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


fanuc_post_processor
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Feb 28 2022 22:20:38