utils.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
42 #include <tf2_eigen/tf2_eigen.h>
43 
44 using namespace moveit::core;
45 
46 namespace kinematic_constraints
47 {
48 const std::string LOGNAME = "kinematic_constraint_utils";
49 
50 moveit_msgs::Constraints mergeConstraints(const moveit_msgs::Constraints& first, const moveit_msgs::Constraints& second)
51 {
52  moveit_msgs::Constraints r;
53 
54  // add all joint constraints that are in first but not in second
55  // and merge joint constraints that are for the same joint
56  for (const moveit_msgs::JointConstraint& jc_first : first.joint_constraints)
57  {
58  bool add = true;
59  for (const moveit_msgs::JointConstraint& jc_second : second.joint_constraints)
60  if (jc_second.joint_name == jc_first.joint_name)
61  {
62  add = false;
63  // now we merge
64  moveit_msgs::JointConstraint m;
65  const moveit_msgs::JointConstraint& a = jc_first;
66  const moveit_msgs::JointConstraint& b = jc_second;
67  double low = std::max(a.position - a.tolerance_below, b.position - b.tolerance_below);
68  double high = std::min(a.position + a.tolerance_above, b.position + b.tolerance_above);
69  if (low > high)
70  ROS_ERROR_NAMED("kinematic_constraints",
71  "Attempted to merge incompatible constraints for joint '%s'. Discarding constraint.",
72  a.joint_name.c_str());
73  else
74  {
75  m.joint_name = a.joint_name;
76  m.position =
77  std::max(low, std::min((a.position * a.weight + b.position * b.weight) / (a.weight + b.weight), high));
78  m.weight = (a.weight + b.weight) / 2.0;
79  m.tolerance_above = std::max(0.0, high - m.position);
80  m.tolerance_below = std::max(0.0, m.position - low);
81  r.joint_constraints.push_back(m);
82  }
83  break;
84  }
85  if (add)
86  r.joint_constraints.push_back(jc_first);
87  }
88 
89  // add all joint constraints that are in second but not in first
90  for (const moveit_msgs::JointConstraint& jc_second : second.joint_constraints)
91  {
92  bool add = true;
93  for (const moveit_msgs::JointConstraint& jc_first : first.joint_constraints)
94  if (jc_second.joint_name == jc_first.joint_name)
95  {
96  add = false;
97  break;
98  }
99  if (add)
100  r.joint_constraints.push_back(jc_second);
101  }
102 
103  // merge rest of constraints
104  r.position_constraints = first.position_constraints;
105  for (const moveit_msgs::PositionConstraint& position_constraint : second.position_constraints)
106  r.position_constraints.push_back(position_constraint);
107 
108  r.orientation_constraints = first.orientation_constraints;
109  for (const moveit_msgs::OrientationConstraint& orientation_constraint : second.orientation_constraints)
110  r.orientation_constraints.push_back(orientation_constraint);
111 
112  r.visibility_constraints = first.visibility_constraints;
113  for (const moveit_msgs::VisibilityConstraint& visibility_constraint : second.visibility_constraints)
114  r.visibility_constraints.push_back(visibility_constraint);
115 
116  return r;
117 }
118 
119 bool isEmpty(const moveit_msgs::Constraints& constr)
120 {
121  return moveit::core::isEmpty(constr);
122 }
123 
124 std::size_t countIndividualConstraints(const moveit_msgs::Constraints& constr)
125 {
126  return constr.position_constraints.size() + constr.orientation_constraints.size() +
127  constr.visibility_constraints.size() + constr.joint_constraints.size();
128 }
129 
130 moveit_msgs::Constraints constructGoalConstraints(const moveit::core::RobotState& state,
131  const moveit::core::JointModelGroup* jmg, double tolerance)
132 {
133  return constructGoalConstraints(state, jmg, tolerance, tolerance);
134 }
135 
136 moveit_msgs::Constraints constructGoalConstraints(const moveit::core::RobotState& state,
137  const moveit::core::JointModelGroup* jmg, double tolerance_below,
138  double tolerance_above)
139 {
140  moveit_msgs::Constraints goal;
141  std::vector<double> vals;
142  state.copyJointGroupPositions(jmg, vals);
143  goal.joint_constraints.resize(vals.size());
144  for (std::size_t i = 0; i < vals.size(); ++i)
145  {
146  goal.joint_constraints[i].joint_name = jmg->getVariableNames()[i];
147  goal.joint_constraints[i].position = vals[i];
148  goal.joint_constraints[i].tolerance_above = tolerance_above;
149  goal.joint_constraints[i].tolerance_below = tolerance_below;
150  goal.joint_constraints[i].weight = 1.0;
151  }
152 
153  return goal;
154 }
155 
156 moveit_msgs::Constraints constructGoalConstraints(const std::string& link_name, const geometry_msgs::PoseStamped& pose,
157  double tolerance_pos, double tolerance_angle)
158 {
159  moveit_msgs::Constraints goal;
160 
161  goal.position_constraints.resize(1);
162  moveit_msgs::PositionConstraint& pcm = goal.position_constraints[0];
163  pcm.link_name = link_name;
164  pcm.target_point_offset.x = 0;
165  pcm.target_point_offset.y = 0;
166  pcm.target_point_offset.z = 0;
167  pcm.constraint_region.primitives.resize(1);
168  shape_msgs::SolidPrimitive& bv = pcm.constraint_region.primitives[0];
169  bv.type = shape_msgs::SolidPrimitive::SPHERE;
170  bv.dimensions.resize(geometric_shapes::solidPrimitiveDimCount<shape_msgs::SolidPrimitive::SPHERE>());
171  bv.dimensions[shape_msgs::SolidPrimitive::SPHERE_RADIUS] = tolerance_pos;
172 
173  pcm.header = pose.header;
174  pcm.constraint_region.primitive_poses.resize(1);
175  pcm.constraint_region.primitive_poses[0].position = pose.pose.position;
176 
177  // orientation of constraint region does not affect anything, since it is a sphere
178  pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
179  pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
180  pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
181  pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
182  pcm.weight = 1.0;
183 
184  goal.orientation_constraints.resize(1);
185  moveit_msgs::OrientationConstraint& ocm = goal.orientation_constraints[0];
186  ocm.parameterization = moveit_msgs::OrientationConstraint::ROTATION_VECTOR;
187  ocm.link_name = link_name;
188  ocm.header = pose.header;
189  ocm.orientation = pose.pose.orientation;
190  ocm.absolute_x_axis_tolerance = tolerance_angle;
191  ocm.absolute_y_axis_tolerance = tolerance_angle;
192  ocm.absolute_z_axis_tolerance = tolerance_angle;
193  ocm.weight = 1.0;
194 
195  return goal;
196 }
197 
198 moveit_msgs::Constraints constructGoalConstraints(const std::string& link_name, const geometry_msgs::PoseStamped& pose,
199  const std::vector<double>& tolerance_pos,
200  const std::vector<double>& tolerance_angle)
201 {
202  moveit_msgs::Constraints goal = constructGoalConstraints(link_name, pose);
203  if (tolerance_pos.size() == 3)
204  {
205  shape_msgs::SolidPrimitive& bv = goal.position_constraints[0].constraint_region.primitives[0];
206  bv.type = shape_msgs::SolidPrimitive::BOX;
207  bv.dimensions.resize(geometric_shapes::solidPrimitiveDimCount<shape_msgs::SolidPrimitive::BOX>());
208  bv.dimensions[shape_msgs::SolidPrimitive::BOX_X] = tolerance_pos[0];
209  bv.dimensions[shape_msgs::SolidPrimitive::BOX_Y] = tolerance_pos[1];
210  bv.dimensions[shape_msgs::SolidPrimitive::BOX_Z] = tolerance_pos[2];
211  }
212  if (tolerance_angle.size() == 3)
213  {
214  moveit_msgs::OrientationConstraint& ocm = goal.orientation_constraints[0];
215  ocm.absolute_x_axis_tolerance = tolerance_angle[0];
216  ocm.absolute_y_axis_tolerance = tolerance_angle[1];
217  ocm.absolute_z_axis_tolerance = tolerance_angle[2];
218  }
219  return goal;
220 }
221 
222 moveit_msgs::Constraints constructGoalConstraints(const std::string& link_name,
223  const geometry_msgs::QuaternionStamped& quat, double tolerance)
224 {
225  moveit_msgs::Constraints goal;
226  goal.orientation_constraints.resize(1);
227  moveit_msgs::OrientationConstraint& ocm = goal.orientation_constraints[0];
228  ocm.link_name = link_name;
229  ocm.header = quat.header;
230  ocm.orientation = quat.quaternion;
231  ocm.absolute_x_axis_tolerance = tolerance;
232  ocm.absolute_y_axis_tolerance = tolerance;
233  ocm.absolute_z_axis_tolerance = tolerance;
234  ocm.weight = 1.0;
235  return goal;
236 }
237 
238 moveit_msgs::Constraints constructGoalConstraints(const std::string& link_name,
239  const geometry_msgs::PointStamped& goal_point, double tolerance)
240 {
241  geometry_msgs::Point p;
242  p.x = 0;
243  p.y = 0;
244  p.z = 0;
245  return constructGoalConstraints(link_name, p, goal_point, tolerance);
246 }
247 
248 moveit_msgs::Constraints constructGoalConstraints(const std::string& link_name,
249  const geometry_msgs::Point& reference_point,
250  const geometry_msgs::PointStamped& goal_point, double tolerance)
251 {
252  moveit_msgs::Constraints goal;
253  goal.position_constraints.resize(1);
254  moveit_msgs::PositionConstraint& pcm = goal.position_constraints[0];
255  pcm.link_name = link_name;
256  pcm.target_point_offset.x = reference_point.x;
257  pcm.target_point_offset.y = reference_point.y;
258  pcm.target_point_offset.z = reference_point.z;
259  pcm.constraint_region.primitives.resize(1);
260  pcm.constraint_region.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
261  pcm.constraint_region.primitives[0].dimensions.resize(
262  geometric_shapes::solidPrimitiveDimCount<shape_msgs::SolidPrimitive::SPHERE>());
263  pcm.constraint_region.primitives[0].dimensions[shape_msgs::SolidPrimitive::SPHERE_RADIUS] = tolerance;
264 
265  pcm.header = goal_point.header;
266  pcm.constraint_region.primitive_poses.resize(1);
267  pcm.constraint_region.primitive_poses[0].position = goal_point.point;
268 
269  // orientation of constraint region does not affect anything, since it is a sphere
270  pcm.constraint_region.primitive_poses[0].orientation.x = 0.0;
271  pcm.constraint_region.primitive_poses[0].orientation.y = 0.0;
272  pcm.constraint_region.primitive_poses[0].orientation.z = 0.0;
273  pcm.constraint_region.primitive_poses[0].orientation.w = 1.0;
274  pcm.weight = 1.0;
275 
276  return goal;
277 }
278 
279 static bool constructPoseStamped(XmlRpc::XmlRpcValue::iterator& it, geometry_msgs::PoseStamped& pose)
280 {
281  if (!isStruct(it->second, { "frame_id", "position", "orientation" }, it->first))
282  return false;
283  pose.header.frame_id = static_cast<std::string>(it->second["frame_id"]);
284 
285  if (!isArray(it->second["orientation"], 3, "orientation", "RPY values"))
286  return false;
287  auto& rpy = it->second["orientation"];
288  tf2::Quaternion q;
289  q.setRPY(parseDouble(rpy[0]), parseDouble(rpy[1]), parseDouble(rpy[2]));
290  pose.pose.orientation = toMsg(q);
291 
292  if (!isArray(it->second["position"], 3, "position", "xyz position"))
293  return false;
294  pose.pose.position.x = parseDouble(it->second["position"][0]);
295  pose.pose.position.y = parseDouble(it->second["position"][1]);
296  pose.pose.position.z = parseDouble(it->second["position"][2]);
297 
298  return true;
299 }
300 
301 static bool constructConstraint(XmlRpc::XmlRpcValue& params, moveit_msgs::JointConstraint& constraint)
302 {
303  for (XmlRpc::XmlRpcValue::iterator it = params.begin(); it != params.end(); ++it)
304  {
305  if (it->first == "type")
306  continue;
307  else if (it->first == "joint_name")
308  constraint.joint_name = static_cast<std::string>(it->second);
309  else if (it->first == "weight")
310  constraint.weight = parseDouble(it->second);
311  else if (it->first == "position")
312  {
313  constraint.position = parseDouble(it->second);
314  }
315  else if (it->first == "tolerance")
316  {
317  constraint.tolerance_below = parseDouble(it->second);
318  constraint.tolerance_above = parseDouble(it->second);
319  }
320  else if (it->first == "tolerances")
321  {
322  if (!isArray(it->second, 2, it->first, "lower/upper tolerances"))
323  return false;
324 
325  constraint.tolerance_below = parseDouble(it->second[0]);
326  constraint.tolerance_above = parseDouble(it->second[1]);
327  }
328  else if (it->first == "bounds")
329  {
330  if (!isArray(it->second, 2, it->first, "lower/upper bound"))
331  return false;
332 
333  const double lower_bound = parseDouble(it->second[0]);
334  const double upper_bound = parseDouble(it->second[1]);
335 
336  constraint.position = (lower_bound + upper_bound) / 2;
337  constraint.tolerance_below = constraint.position - lower_bound;
338  constraint.tolerance_above = upper_bound - constraint.position;
339  }
340  else
341  {
342  ROS_WARN_STREAM_NAMED(LOGNAME, "joint constraint contains unknown entity '" << it->first << "'");
343  }
344  }
345  return true;
346 }
347 
348 static bool constructConstraint(XmlRpc::XmlRpcValue& params, moveit_msgs::PositionConstraint& constraint)
349 {
350  for (XmlRpc::XmlRpcValue::iterator it = params.begin(); it != params.end(); ++it)
351  {
352  if (it->first == "type")
353  continue;
354  else if (it->first == "frame_id")
355  constraint.header.frame_id = static_cast<std::string>(it->second);
356  else if (it->first == "weight")
357  constraint.weight = parseDouble(it->second);
358  else if (it->first == "link_name")
359  constraint.link_name = static_cast<std::string>(it->second);
360  else if (it->first == "target_offset")
361  {
362  if (!isArray(it->second, 3, it->first, "x/y/z position"))
363  return false;
364 
365  constraint.target_point_offset.x = parseDouble(it->second[0]);
366  constraint.target_point_offset.y = parseDouble(it->second[1]);
367  constraint.target_point_offset.z = parseDouble(it->second[2]);
368  }
369  else if (it->first == "region")
370  {
371  if (!isStruct(it->second, { "x", "y", "z" }, "region"))
372  return false;
373 
374  constraint.constraint_region.primitive_poses.emplace_back();
375  constraint.constraint_region.primitives.emplace_back();
376 
377  geometry_msgs::Pose& region_pose = constraint.constraint_region.primitive_poses.back();
378  shape_msgs::SolidPrimitive& region_primitive = constraint.constraint_region.primitives.back();
379 
380  region_primitive.type = shape_msgs::SolidPrimitive::BOX;
381  region_primitive.dimensions.resize(3);
382 
383  std::function<void(XmlRpc::XmlRpcValue&, double&, double&)> parse_dimension =
384  [](XmlRpc::XmlRpcValue& it, double& center, double& dimension) {
385  center = (parseDouble(it[0]) + parseDouble(it[1])) / 2;
386  dimension = parseDouble(it[1]) - parseDouble(it[0]);
387  };
388 
389  parse_dimension(it->second["x"], region_pose.position.x,
390  region_primitive.dimensions[shape_msgs::SolidPrimitive::BOX_X]);
391  parse_dimension(it->second["y"], region_pose.position.y,
392  region_primitive.dimensions[shape_msgs::SolidPrimitive::BOX_Y]);
393  parse_dimension(it->second["z"], region_pose.position.z,
394  region_primitive.dimensions[shape_msgs::SolidPrimitive::BOX_Z]);
395 
396  region_pose.orientation.w = 1.0;
397  }
398  else
399  {
400  ROS_WARN_STREAM_NAMED(LOGNAME, "position constraint contains unknown entity '" << it->first << "'");
401  }
402  }
403  return true;
404 }
405 
406 static bool constructConstraint(XmlRpc::XmlRpcValue& params, moveit_msgs::OrientationConstraint& constraint)
407 {
408  for (XmlRpc::XmlRpcValue::iterator it = params.begin(); it != params.end(); ++it)
409  {
410  if (it->first == "type")
411  continue;
412  else if (it->first == "frame_id")
413  constraint.header.frame_id = static_cast<std::string>(it->second);
414  else if (it->first == "weight")
415  constraint.weight = parseDouble(it->second);
416  else if (it->first == "link_name")
417  constraint.link_name = static_cast<std::string>(it->second);
418  else if (it->first == "orientation")
419  {
420  if (!isArray(it->second, 3, it->first, "RPY values"))
421  return false;
422 
423  tf2::Quaternion q;
424  q.setRPY(parseDouble(it->second[0]), parseDouble(it->second[1]), parseDouble(it->second[2]));
425  constraint.orientation = toMsg(q);
426  }
427  else if (it->first == "tolerances")
428  {
429  if (!isArray(it->second, 3, it->first, "xyz tolerances"))
430  return false;
431 
432  constraint.absolute_x_axis_tolerance = parseDouble(it->second[0]);
433  constraint.absolute_y_axis_tolerance = parseDouble(it->second[1]);
434  constraint.absolute_z_axis_tolerance = parseDouble(it->second[2]);
435  }
436  else
437  {
438  ROS_WARN_STREAM_NAMED(LOGNAME, "orientation constraint contains unknown entity '" << it->first << "'");
439  }
440  }
441  return true;
442 }
443 
444 static bool constructConstraint(XmlRpc::XmlRpcValue& params, moveit_msgs::VisibilityConstraint& constraint)
445 {
446  for (XmlRpc::XmlRpcValue::iterator it = params.begin(); it != params.end(); ++it)
447  {
448  if (it->first == "type")
449  continue;
450  else if (it->first == "weight")
451  constraint.weight = parseDouble(it->second);
452  else if (it->first == "target_radius")
453  constraint.target_radius = parseDouble(it->second);
454  else if (it->first == "target_pose")
455  {
456  if (!constructPoseStamped(it, constraint.target_pose))
457  return false;
458  }
459  else if (it->first == "cone_sides")
460  constraint.cone_sides = static_cast<int>(it->second);
461  else if (it->first == "sensor_pose")
462  {
463  if (!constructPoseStamped(it, constraint.sensor_pose))
464  return false;
465  }
466  else if (it->first == "max_view_angle")
467  constraint.max_view_angle = parseDouble(it->second);
468  else if (it->first == "max_range_angle")
469  constraint.max_range_angle = parseDouble(it->second);
470  else
471  {
472  ROS_WARN_STREAM_NAMED(LOGNAME, "orientation constraint contains unknown entity '" << it->first << "'");
473  }
474  }
475 
476  constraint.sensor_view_direction = moveit_msgs::VisibilityConstraint::SENSOR_X;
477 
478  return true;
479 }
480 
481 static bool collectConstraints(XmlRpc::XmlRpcValue& params, moveit_msgs::Constraints& constraints)
482 {
483  if (params.getType() != XmlRpc::XmlRpcValue::TypeArray)
484  {
485  ROS_ERROR_NAMED(LOGNAME, "expected constraints as array");
486  return false;
487  }
488 
489  for (int i = 0; i < params.size(); ++i) // NOLINT(modernize-loop-convert)
490  {
491  if (!params[i].hasMember("type"))
492  {
493  ROS_ERROR_NAMED(LOGNAME, "constraint parameter does not specify its type");
494  }
495  else if (params[i]["type"] == "joint")
496  {
497  constraints.joint_constraints.emplace_back();
498  if (!constructConstraint(params[i], constraints.joint_constraints.back()))
499  return false;
500  }
501  else if (params[i]["type"] == "position")
502  {
503  constraints.position_constraints.emplace_back();
504  if (!constructConstraint(params[i], constraints.position_constraints.back()))
505  return false;
506  }
507  else if (params[i]["type"] == "orientation")
508  {
509  constraints.orientation_constraints.emplace_back();
510  if (!constructConstraint(params[i], constraints.orientation_constraints.back()))
511  return false;
512  }
513  else if (params[i]["type"] == "visibility")
514  {
515  constraints.visibility_constraints.emplace_back();
516  if (!constructConstraint(params[i], constraints.visibility_constraints.back()))
517  return false;
518  }
519  }
520 
521  return true;
522 }
523 
524 bool constructConstraints(XmlRpc::XmlRpcValue& params, moveit_msgs::Constraints& constraints)
525 {
526  if (!isStruct(params, { "name", "constraints" }, "Parameter"))
527  return false;
528 
529  constraints.name = static_cast<std::string>(params["name"]);
530  return collectConstraints(params["constraints"], constraints);
531 }
532 
533 bool resolveConstraintFrames(const moveit::core::RobotState& state, moveit_msgs::Constraints& constraints)
534 {
535  for (auto& c : constraints.position_constraints)
536  {
537  bool frame_found;
538  const moveit::core::LinkModel* robot_link;
539  const Eigen::Isometry3d& transform = state.getFrameInfo(c.link_name, robot_link, frame_found);
540  if (!frame_found)
541  return false;
542 
543  // If the frame of the constraint is not part of the robot link model (but an attached body or subframe),
544  // the constraint needs to be expressed in the frame of a robot link.
545  if (c.link_name != robot_link->getName())
546  {
547  Eigen::Isometry3d robot_link_to_link_name = state.getGlobalLinkTransform(robot_link).inverse() * transform;
548  Eigen::Vector3d offset_link_name(c.target_point_offset.x, c.target_point_offset.y, c.target_point_offset.z);
549  Eigen::Vector3d offset_robot_link = robot_link_to_link_name * offset_link_name;
550 
551  c.link_name = robot_link->getName();
552  tf2::toMsg(offset_robot_link, c.target_point_offset);
553  }
554  }
555 
556  for (auto& c : constraints.orientation_constraints)
557  {
558  bool frame_found;
559  const moveit::core::LinkModel* robot_link;
560  // getFrameInfo() returns a valid isometry by contract
561  const Eigen::Isometry3d& transform = state.getFrameInfo(c.link_name, robot_link, frame_found);
562  if (!frame_found)
563  return false;
564 
565  // If the frame of the constraint is not part of the robot link model (but an attached body or subframe),
566  // the constraint needs to be expressed in the frame of a robot link.
567  if (c.link_name != robot_link->getName())
568  {
569  if (c.parameterization == moveit_msgs::OrientationConstraint::XYZ_EULER_ANGLES)
570  {
572  LOGNAME, "Euler angles parameterization is not supported for non-link frames in orientation constraints. \n"
573  "Switch to rotation vector parameterization.");
574  return false;
575  }
576  c.link_name = robot_link->getName();
577  Eigen::Quaterniond link_name_to_robot_link(transform.linear().transpose() *
578  state.getGlobalLinkTransform(robot_link).linear());
579  // adapt goal orientation
580  Eigen::Quaterniond quat_target;
581  tf2::fromMsg(c.orientation, quat_target);
582  c.orientation = tf2::toMsg(quat_target * link_name_to_robot_link);
583  }
584  }
585  return true;
586 }
587 } // namespace kinematic_constraints
XmlRpc::XmlRpcValue::size
int size() const
moveit::core::LinkModel
A link from the robot. Contains the constant transform applied to the link and its geometry.
Definition: link_model.h:71
moveit::core
Core components of MoveIt.
Definition: kinematics_base.h:83
xmlrpc_casts.h
moveit::core::isStruct
bool isStruct(const XmlRpc::XmlRpcValue &v, const std::vector< std::string > &keys={}, const std::string &name="")
Definition: xmlrpc_casts.cpp:131
moveit::core::JointModelGroup
Definition: joint_model_group.h:134
tf2_eigen.h
tf2::fromMsg
void fromMsg(const A &, B &b)
moveit::core::RobotState::getFrameInfo
const Eigen::Isometry3d & getFrameInfo(const std::string &frame_id, const LinkModel *&robot_link, bool &frame_found) const
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
Definition: robot_state.cpp:1211
kinematic_constraints::resolveConstraintFrames
bool resolveConstraintFrames(const moveit::core::RobotState &state, moveit_msgs::Constraints &constraints)
Resolves frames used in constraints to links in the robot model.
Definition: utils.cpp:533
kinematic_constraints
Representation and evaluation of kinematic constraints.
Definition: kinematic_constraint.h:52
tf2::Quaternion::setRPY
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
kinematic_constraints::constructConstraints
bool constructConstraints(XmlRpc::XmlRpcValue &params, moveit_msgs::Constraints &constraints)
extract constraint message from XmlRpc node.
Definition: utils.cpp:524
ROS_ERROR_NAMED
#define ROS_ERROR_NAMED(name,...)
moveit::core::RobotState
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:155
moveit::core::RobotState::copyJointGroupPositions
void copyJointGroupPositions(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the position values of the variables that make up the group into another loca...
Definition: robot_state.h:757
moveit::core::RobotState::getGlobalLinkTransform
const Eigen::Isometry3d & getGlobalLinkTransform(const std::string &link_name)
Get the link transform w.r.t. the root link (model frame) of the RobotModel. This is typically the ro...
Definition: robot_state.h:1394
transform
template Halfspace< double > transform(const Halfspace< double > &a, const Transform3< double > &tf)
kinematic_constraints::collectConstraints
static bool collectConstraints(XmlRpc::XmlRpcValue &params, moveit_msgs::Constraints &constraints)
Definition: utils.cpp:481
moveit::core::JointModelGroup::getVariableNames
const std::vector< std::string > & getVariableNames() const
Get the names of the variables that make up the joints included in this group. The number of returned...
Definition: joint_model_group.h:254
utils.h
kinematic_constraints::constructPoseStamped
static bool constructPoseStamped(XmlRpc::XmlRpcValue::iterator &it, geometry_msgs::PoseStamped &pose)
Definition: utils.cpp:279
kinematic_constraints::mergeConstraints
moveit_msgs::Constraints mergeConstraints(const moveit_msgs::Constraints &first, const moveit_msgs::Constraints &second)
Merge two sets of constraints into one.
Definition: utils.cpp:50
moveit::core::parseDouble
double parseDouble(const XmlRpc::XmlRpcValue &v)
parse a double value from a scalar XmlRpc
Definition: xmlrpc_casts.cpp:109
kinematic_constraints::constructConstraint
static bool constructConstraint(XmlRpc::XmlRpcValue &params, moveit_msgs::VisibilityConstraint &constraint)
Definition: utils.cpp:444
moveit::core::LOGNAME
const std::string LOGNAME
Definition: joint_model_group.cpp:165
XmlRpc::XmlRpcValue::iterator
ValueStruct::iterator iterator
XmlRpc::XmlRpcValue::end
iterator end()
r
S r
XmlRpc::XmlRpcValue::getType
const Type & getType() const
kinematic_constraints::countIndividualConstraints
std::size_t countIndividualConstraints(const moveit_msgs::Constraints &constr)
Definition: utils.cpp:124
kinematic_constraints::constructGoalConstraints
moveit_msgs::Constraints constructGoalConstraints(const moveit::core::RobotState &state, const moveit::core::JointModelGroup *jmg, double tolerance_below, double tolerance_above)
Generates a constraint message intended to be used as a goal constraint for a joint group....
Definition: utils.cpp:136
ROS_WARN_STREAM_NAMED
#define ROS_WARN_STREAM_NAMED(name, args)
XmlRpc::XmlRpcValue::TypeArray
TypeArray
solid_primitive_dims.h
add
bool add(const actionlib::TwoIntsGoal &req, actionlib::TwoIntsResult &res)
moveit::core::isArray
bool isArray(const XmlRpc::XmlRpcValue &v, size_t size=0, const std::string &name="", const std::string &description="")
Definition: xmlrpc_casts.cpp:119
tf2::Quaternion
tolerance
S tolerance()
tf2_geometry_msgs.h
toMsg
B toMsg(const A &a)
XmlRpc::XmlRpcValue::begin
iterator begin()
moveit::core::LinkModel::getName
const std::string & getName() const
The name of this link.
Definition: link_model.h:80
message_checks.h
XmlRpc::XmlRpcValue
fcl::Vector3d
Vec3fX< details::Vec3Data< double > > Vector3d
Definition: fcl_compat.h:89
moveit::core::isEmpty
bool isEmpty(const moveit_msgs::PlanningScene &msg)
Check if a message includes any information about a planning scene, or whether it is empty.
Definition: message_checks.cpp:107


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Nov 3 2024 03:26:15