pose.cpp
Go to the documentation of this file.
2 
3 namespace fanuc_post_processor
4 {
5 
6 FanucPose::FanucPose(const std::vector<FanucAxis> extended_axes,
7  const std::vector<FanucGroup> extra_groups)
8 {
9  // Add first group
16 
17  std::vector<FanucAxis> axis;
18  axis.push_back(x);
19  axis.push_back(y);
20  axis.push_back(z);
21  axis.push_back(w);
22  axis.push_back(p);
23  axis.push_back(r);
24 
25  // Append extended axis
26  axis.insert(std::end(axis), std::begin(extended_axes), std::end(extended_axes));
27 
28  FanucGroup gp1(axis);
29  groups_.push_back(gp1);
30 
31  // Append extra groups
32  groups_.insert(std::end(groups_), std::begin(extra_groups), std::end(extra_groups));
33 }
34 
36 {
37 }
38 
40 {
41  if (move_type_ == JOINT)
42  return "J";
43  else if (move_type_ == LINEAR)
44  return "L";
45  else
46  return "MovementType not recognized!";
47 }
48 
49 std::string FanucPose::speedTypeToString() const
50 {
51  if (speed_type_ == MM_SEC)
52  return "mm/sec";
53  else if (speed_type_ == CM_SEC)
54  return "cm/sec";
55  else if (speed_type_ == M_SEC)
56  return "m/sec";
57  else if (speed_type_ == MM_MIN)
58  return "mm/min";
59  else if (speed_type_ == CM_MIN)
60  return "cm/min";
61  else if (speed_type_ == M_MIN)
62  return "m/min";
63  else if (speed_type_ == PERCENTAGE)
64  return "%";
65  else
66  return "";
67 }
68 
70 {
71  std::string configuration("");
72 
73  if (std::get<0>(configuration_) == FlipNonFlip::Flip)
74  configuration.append("F ");
75  else
76  configuration.append("N "); // Non-flip
77 
78  if (std::get<1>(configuration_) == Elbow::Down)
79  configuration.append("D ");
80  else
81  configuration.append("U "); // Up
82 
83  if (std::get<2>(configuration_) == BackFront::Back)
84  configuration.append("B");
85  else
86  configuration.append("T"); // Front
87 
88  return configuration;
89 }
90 
91 bool FanucPose::hasSameGroupsAxes(const FanucPose &other) const
92  {
93  if (other.groups_.size() != groups_.size())
94  return false;
95 
96  for (unsigned i(0); i < groups_.size(); ++i)
97  {
98  if (other.groups_[i].axis_.size() != groups_[i].axis_.size())
99  return false;
100 
101  for (unsigned j(0); j < groups_[i].axis_.size(); ++j)
102  {
103  if (other.groups_[i].axis_[j].name_ != groups_[i].axis_[j].name_)
104  return false;
105  if (other.groups_[i].axis_[j].type_ != groups_[i].axis_[j].type_)
106  return false;
107  } // axis for loop
108  } // groups for loop
109 
110  return true;
111 }
112 
113 bool FanucPose::isValid() const
114 {
115  if (groups_.empty())
116  {
117  ROS_ERROR_STREAM("Pose has empty groups");
118  return false;
119  }
120 
121  if (groups_[0].axis_.size() < 6)
122  {
123  ROS_ERROR_STREAM("Pose does not have at least 6 axes");
124  return false;
125  }
126 
127  if (groups_[0].axis_[0].name_ != "X" &&
128  groups_[0].axis_[0].type_ != FanucAxis::AxisType::LINEAR)
129  {
130  ROS_ERROR_STREAM("Pose has wrong X axis");
131  return false;
132  }
133 
134  if (groups_[0].axis_[1].name_ != "Y" &&
135  groups_[0].axis_[1].type_ != FanucAxis::AxisType::LINEAR)
136  {
137  ROS_ERROR_STREAM("Pose has wrong Y axis");
138  return false;
139  }
140 
141  if (groups_[0].axis_[2].name_ != "Z" &&
142  groups_[0].axis_[2].type_ != FanucAxis::AxisType::LINEAR)
143 
144  {
145  ROS_ERROR_STREAM("Pose has wrong Z axis");
146  return false;
147  }
148 
149  if (groups_[0].axis_[3].name_ != "W" &&
150  groups_[0].axis_[3].type_ != FanucAxis::AxisType::ROTATIVE)
151  {
152  ROS_ERROR_STREAM("Pose has wrong W axis");
153  return false;
154  }
155 
156  if (groups_[0].axis_[4].name_ != "P" &&
157  groups_[0].axis_[4].type_ != FanucAxis::AxisType::ROTATIVE)
158  {
159  ROS_ERROR_STREAM("Pose has wrong P axis");
160  return false;
161  }
162  if (groups_[0].axis_[5].name_ != "R" &&
163  groups_[0].axis_[5].type_ != FanucAxis::AxisType::ROTATIVE)
164  {
165  ROS_ERROR_STREAM("Pose has wrong R axis");
166  return false;
167  }
168 
169  if (pose_id_ == 0)
170  {
171  ROS_ERROR_STREAM("Pose ID cannot be zero");
172  return false;
173  }
174 
175  if (move_type_ == JOINT)
176  {
177  if (speed_type_ != PERCENTAGE)
178  {
179  ROS_ERROR_STREAM("Speed type in joint mode must be PERCENTAGE");
180  return false;
181  }
182 
183  if (speed_ > 100)
184  {
185  ROS_ERROR_STREAM("Speed percentage cannot be > 100%");
186  return false;
187  }
188  }
189  else if (move_type_ == LINEAR)
190  {
191  if (speed_type_ == PERCENTAGE)
192  {
193  ROS_ERROR_STREAM("Pose is LINEAR, speed cannot be PERCENTAGE");
194  return false;
195  }
196  }
197  else
198  return false;
199 
200  if (cnt_ > 100)
201  {
202  ROS_ERROR_STREAM("CNT cannot be > 100");
203  return false;
204  }
205 
206  // Speed is a register number
207  if (speed_register_ && speed_ < 1)
208  {
209  ROS_ERROR_STREAM("Speed register specified: register ID cannot be zero!");
210  return false;
211  }
212 
213  for (auto group : groups_)
214  {
215  if (group.axis_.empty())
216  {
217  ROS_ERROR_STREAM("Group axes cannot be empty");
218  return false;
219  }
220 
221  if (group.user_frame_ > 9)
222  {
223  ROS_ERROR_STREAM("Group user frame cannot be > 9");
224  return false;
225  }
226 
227  if (group.tool_frame_ == 0)
228  {
229  ROS_ERROR_STREAM("Group tool frame cannot be zero");
230  return false;
231  }
232 
233  if (group.tool_frame_ > 9)
234  {
235  ROS_ERROR_STREAM("Group tool frame cannot be > 9");
236  return false;
237  }
238  }
239  return true;
240 }
241 
242 std::string FanucPose::getMainLineString() const
243 {
244  if (!isValid())
245  return "";
246 
247  std::string line("");
248 
249  const std::string p_id(std::to_string(pose_id_));
250  const std::string movement(movementTypeToString());
251  const std::string speed_unit(speedTypeToString());
252 
253  std::string move_speed;
254  if (speed_register_)
255  move_speed = "R[" + std::to_string((unsigned)speed_) + "]";
256  else
257  move_speed = std::to_string(unsigned(speed_));
258 
259  line = movement + " P[" + p_id + "] " + move_speed + speed_unit;
260 
261  if (cnt_ == 0) // FINE
262  line.append(" FINE " + option_ + ";");
263  else
264  // CNT 1-100
265  line.append(" CNT" + std::to_string(cnt_) + " " + option_ + ";");
266 
267  return line;
268 }
269 
270 std::string FanucPose::getPoseLinesString() const
271 {
272  if (!isValid())
273  return "";
274 
275  std::string pose_block;
276  pose_block.append("P[" + std::to_string(pose_id_) + "]{\n");
277  pose_block.append(" GP1:\n");
278  pose_block.append(
279  "\tUF : " + std::to_string(groups_[0].user_frame_) + ", UT : "
280  + std::to_string(groups_[0].tool_frame_) + ", CONFIG : '");
281 
282  pose_block.append(configurationToString());
283  pose_block.append(", ");
284  pose_block.append(std::to_string(flipnonflip_rotations_) + ", ");
285  pose_block.append(std::to_string(elbow_rotations_) + ", ");
286  pose_block.append(std::to_string(backfront_rotations_) + "',\n");
287 
288  pose_block.append(
289  "\tX = " + std::to_string(groups_[0].axis_[0].value_ * 1000.0) + " mm, Y = "
290  + std::to_string(groups_[0].axis_[1].value_ * 1000.0)
291  + " mm, Z = " + std::to_string(groups_[0].axis_[2].value_ * 1000.0) + " mm,\n");
292  pose_block.append(
293  "\tW = " + std::to_string(groups_[0].axis_[3].value_ * 180.0 / M_PI) + " deg, P = " + std::to_string(groups_[0].axis_[4].value_* 180.0 / M_PI)
294  + " deg, R = " + std::to_string(groups_[0].axis_[5].value_ * 180.0 / M_PI) + " deg");
295 
296  // Append extended axis
297  if (groups_[0].axis_.size() > 6)
298  {
299  pose_block.append(",\n");
300 
301  for (unsigned i(6); i < groups_[0].axis_.size(); ++i)
302  {
303  double value(groups_[0].axis_[i].value_);
304  if (groups_[0].axis_[i].type_ == FanucAxis::AxisType::ROTATIVE)
305  value *= 180.0 / M_PI; // rad2deg
306  else
307  value *= 1000.0; // meters to millimeters
308 
309  pose_block.append("\t");
310  pose_block.append(groups_[0].axis_[i].name_ + " = " + std::to_string(value));
311 
312  if (groups_[0].axis_[i].type_ == FanucAxis::AxisType::LINEAR)
313  pose_block.append(" mm");
314  else
315  pose_block.append(" deg");
316 
317  if (i == groups_[0].axis_.size() - 1)
318  pose_block.append("\n");
319  else
320  pose_block.append(",\n");
321  }
322  }
323  else
324  pose_block.append("\n");
325 
326  // Append other groups
327  if (groups_.size() != 1)
328  {
329  for (unsigned group_number(1); group_number < groups_.size(); ++group_number)
330  {
331  unsigned axis_per_line(0);
332 
333  pose_block.append(" GP" + std::to_string(group_number + 1) + ":\n");
334  pose_block.append(
335  "\tUF : " + std::to_string(groups_[group_number].user_frame_) + ", UT : "
336  + std::to_string(groups_[group_number].tool_frame_) + ",\n");
337 
338  for (auto &axis : groups_[group_number].axis_)
339  {
340  if (axis_per_line == 0)
341  pose_block.append("\t");
342  else
343  pose_block.append(" ");
344  pose_block.append(axis.name_ + "= ");
345 
346  double value(axis.value_);
347  if (axis.type_ == FanucAxis::AxisType::ROTATIVE)
348  value *= 180.0 / M_PI; // rad2deg
349  else
350  value *= 1000.0; // meters to millimeters
351 
352  pose_block.append(std::to_string(value));
353 
354  if (axis.type_ == FanucAxis::AxisType::LINEAR)
355  pose_block.append(" mm");
356  else
357  pose_block.append(" deg");
358 
359  if (&axis != &groups_[group_number].axis_.back())
360  pose_block.append(",");
361 
362  if (axis_per_line == 2)
363  {
364  pose_block.append("\n");
365  axis_per_line = 0;
366  continue;
367  }
368  ++axis_per_line;
369  }
370 
371  if (axis_per_line != 0)
372  pose_block.append("\n");
373  }
374 
375  }
376 
377  pose_block.append("};\n");
378  return pose_block;
379 }
380 
381 void FanucPose::setRobotPose(const Eigen::Isometry3d &pose)
382 {
383  if (!isValid())
384  return;
385 
386  const Eigen::Vector3d euler_angles(pose.linear().eulerAngles(0, 1, 2));
387  groups_[0].axis_[0].value_ = pose.translation().x();
388  groups_[0].axis_[1].value_ = pose.translation().y();
389  groups_[0].axis_[2].value_ = pose.translation().z();
390 
391  // W
392  groups_[0].axis_[3].value_ = euler_angles[0];
393  // P
394  groups_[0].axis_[4].value_ = euler_angles[1];
395  // R
396  groups_[0].axis_[5].value_ = euler_angles[2];
397 }
398 
399 }
Definition: axis.hpp:6
bool speed_register_
Definition: pose.hpp:126
unsigned cnt_
Definition: pose.hpp:125
std::string movementTypeToString() const
Definition: pose.cpp:39
FanucPose(const std::vector< FanucAxis > extended_axes={}, const std::vector< FanucGroup > extra_groups={})
Definition: pose.cpp:6
Definition: pose.hpp:28
Definition: pose.hpp:28
Definition: pose.hpp:12
Definition: group.hpp:10
virtual ~FanucPose()
Definition: pose.cpp:35
Config configuration_
Definition: pose.hpp:127
bool isValid() const
Definition: pose.cpp:113
Definition: pose.hpp:28
Definition: pose.hpp:28
Definition: pose.hpp:28
TFSIMD_FORCE_INLINE const tfScalar & y() const
unsigned pose_id_
Definition: pose.hpp:119
std::vector< FanucGroup > groups_
Definition: pose.hpp:129
Definition: pose.hpp:28
std::string configurationToString() const
Definition: pose.cpp:69
std::string speedTypeToString() const
Definition: pose.cpp:49
double speed_
Definition: pose.hpp:121
std::string getMainLineString() const
Definition: pose.cpp:242
Definition: pose.hpp:20
std::string option_
Definition: pose.hpp:130
unsigned elbow_rotations_
Definition: pose.hpp:128
void setRobotPose(const Eigen::Isometry3d &pose)
Definition: pose.cpp:381
MovementType move_type_
Definition: pose.hpp:120
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
Definition: axis.hpp:9
TFSIMD_FORCE_INLINE const tfScalar & w() const
std::string getPoseLinesString() const
Definition: pose.cpp:270
Flip.
unsigned flipnonflip_rotations_
Definition: pose.hpp:128
Definition: pose.hpp:20
bool hasSameGroupsAxes(const FanucPose &other) const
Definition: pose.cpp:91
#define ROS_ERROR_STREAM(args)
Definition: pose.hpp:28
SpeedType speed_type_
Definition: pose.hpp:122
unsigned backfront_rotations_
Definition: pose.hpp:128


fanuc_post_processor
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 13:16:56