moveit2
The MoveIt Motion Planning Framework for ROS 2.
wrap_python_move_group.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, 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 
47 #include <tf2_eigen/tf2_eigen.hpp>
48 #include <tf2/LinearMath/Quaternion.h>
49 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
50 #include <tf2_ros/buffer.h>
51 
52 #include <boost/python.hpp>
53 #include <boost/noncopyable.hpp>
54 #include <eigenpy/eigenpy.hpp>
55 #include <memory>
56 #include <Python.h>
57 
60 namespace bp = boost::python;
61 
63 
64 namespace moveit
65 {
66 namespace planning_interface
67 {
68 class MoveGroupInterfaceWrapper : protected py_bindings_tools::ROScppInitializer, public MoveGroupInterface
69 {
70 public:
71  // ROSInitializer is constructed first, and ensures ros::init() was called, if
72  // needed
73  MoveGroupInterfaceWrapper(const std::string& group_name, const std::string& robot_description,
74  const std::string& ns = "", double wait_for_servers = 5.0)
75  : py_bindings_tools::ROScppInitializer()
76  , MoveGroupInterface(Options(group_name, robot_description, ros::NodeHandle(ns)),
77  std::shared_ptr<tf2_ros::Buffer>(), ros::WallDuration(wait_for_servers))
78  {
79  }
80 
81  bool setJointValueTargetPerJointPythonList(const std::string& joint, bp::list& values)
82  {
83  return setJointValueTarget(joint, py_bindings_tools::doubleFromList(values));
84  }
85 
86  bool setJointValueTargetPythonIterable(bp::object& values)
87  {
88  return setJointValueTarget(py_bindings_tools::doubleFromList(values));
89  }
90 
91  bool setJointValueTargetPythonDict(bp::dict& values)
92  {
93  bp::list k = values.keys();
94  int l = bp::len(k);
95  std::map<std::string, double> v;
96  for (int i = 0; i < l; ++i)
97  v[bp::extract<std::string>(k[i])] = bp::extract<double>(values[k[i]]);
98  return setJointValueTarget(v);
99  }
100 
101  bool setJointValueTargetFromPosePython(const py_bindings_tools::ByteString& pose_str, const std::string& eef,
102  bool approx)
103  {
104  geometry_msgs::Pose pose_msg;
105  py_bindings_tools::deserializeMsg(pose_str, pose_msg);
106  return approx ? setApproximateJointValueTarget(pose_msg, eef) : setJointValueTarget(pose_msg, eef);
107  }
108 
109  bool setJointValueTargetFromPoseStampedPython(const py_bindings_tools::ByteString& pose_str, const std::string& eef,
110  bool approx)
111  {
112  geometry_msgs::PoseStamped pose_msg;
113  py_bindings_tools::deserializeMsg(pose_str, pose_msg);
114  return approx ? setApproximateJointValueTarget(pose_msg, eef) : setJointValueTarget(pose_msg, eef);
115  }
116 
117  bool setJointValueTargetFromJointStatePython(const py_bindings_tools::ByteString& js_str)
118  {
119  sensor_msgs::JointState js_msg;
120  py_bindings_tools::deserializeMsg(js_str, js_msg);
121  return setJointValueTarget(js_msg);
122  }
123 
124  bp::list getJointValueTargetPythonList()
125  {
126  std::vector<double> values;
128  bp::list l;
129  for (const double value : values)
130  l.append(value);
131  return l;
132  }
133 
134  py_bindings_tools::ByteString getJointValueTarget()
135  {
136  moveit_msgs::msg::RobotState msg;
140  }
141 
142  void rememberJointValuesFromPythonList(const std::string& string, bp::list& values)
143  {
144  rememberJointValues(string, py_bindings_tools::doubleFromList(values));
145  }
146 
147  const char* getPlanningFrameCStr() const
148  {
149  return getPlanningFrame().c_str();
150  }
151 
152  py_bindings_tools::ByteString getInterfaceDescriptionPython()
153  {
154  moveit_msgs::msg::PlannerInterfaceDescription msg;
155  getInterfaceDescription(msg);
157  }
158 
159  bp::list getActiveJointsList() const
160  {
161  return py_bindings_tools::listFromString(getActiveJoints());
162  }
163 
164  bp::list getJointsList() const
165  {
166  return py_bindings_tools::listFromString(getJoints());
167  }
168 
169  bp::list getCurrentJointValuesList()
170  {
171  return py_bindings_tools::listFromDouble(getCurrentJointValues());
172  }
173 
174  bp::list getRandomJointValuesList()
175  {
176  return py_bindings_tools::listFromDouble(getRandomJointValues());
177  }
178 
179  bp::dict getRememberedJointValuesPython() const
180  {
181  const std::map<std::string, std::vector<double>>& rv = getRememberedJointValues();
182  bp::dict d;
183  for (const std::pair<const std::string, std::vector<double>>& it : rv)
184  d[it.first] = py_bindings_tools::listFromDouble(it.second);
185  return d;
186  }
187 
188  bp::list convertPoseToList(const geometry_msgs::Pose& pose) const
189  {
190  std::vector<double> v(7);
191  v[0] = pose.position.x;
192  v[1] = pose.position.y;
193  v[2] = pose.position.z;
194  v[3] = pose.orientation.x;
195  v[4] = pose.orientation.y;
196  v[5] = pose.orientation.z;
197  v[6] = pose.orientation.w;
199  }
200 
201  bp::list convertTransformToList(const geometry_msgs::Transform& tr) const
202  {
203  std::vector<double> v(7);
204  v[0] = tr.translation.x;
205  v[1] = tr.translation.y;
206  v[2] = tr.translation.z;
207  v[3] = tr.rotation.x;
208  v[4] = tr.rotation.y;
209  v[5] = tr.rotation.z;
210  v[6] = tr.rotation.w;
212  }
213 
214  void convertListToTransform(const bp::list& l, geometry_msgs::Transform& tr) const
215  {
216  std::vector<double> v = py_bindings_tools::doubleFromList(l);
217  tr.translation.x = v[0];
218  tr.translation.y = v[1];
219  tr.translation.z = v[2];
220  tr.rotation.x = v[3];
221  tr.rotation.y = v[4];
222  tr.rotation.z = v[5];
223  tr.rotation.w = v[6];
224  }
225 
226  void convertListToPose(const bp::list& l, geometry_msgs::Pose& p) const
227  {
228  std::vector<double> v = py_bindings_tools::doubleFromList(l);
229  p.position.x = v[0];
230  p.position.y = v[1];
231  p.position.z = v[2];
232  p.orientation.x = v[3];
233  p.orientation.y = v[4];
234  p.orientation.z = v[5];
235  p.orientation.w = v[6];
236  }
237 
238  bp::list getCurrentRPYPython(const std::string& end_effector_link = "")
239  {
240  return py_bindings_tools::listFromDouble(getCurrentRPY(end_effector_link));
241  }
242 
243  bp::list getCurrentPosePython(const std::string& end_effector_link = "")
244  {
245  geometry_msgs::PoseStamped pose = getCurrentPose(end_effector_link);
246  return convertPoseToList(pose.pose);
247  }
248 
249  bp::list getRandomPosePython(const std::string& end_effector_link = "")
250  {
251  geometry_msgs::PoseStamped pose = getRandomPose(end_effector_link);
252  return convertPoseToList(pose.pose);
253  }
254 
255  bp::list getKnownConstraintsList() const
256  {
257  return py_bindings_tools::listFromString(getKnownConstraints());
258  }
259 
260  bool placePose(const std::string& object_name, const bp::list& pose, bool plan_only = false)
261  {
262  geometry_msgs::PoseStamped msg;
263  convertListToPose(pose, msg.pose);
264  msg.header.frame_id = getPoseReferenceFrame();
265  msg.header.stamp = ros::Time::now();
266  GILReleaser gr;
267  return place(object_name, msg, plan_only) == moveit::core::MoveItErrorCode::SUCCESS;
268  }
269 
270  bool placePoses(const std::string& object_name, const bp::list& poses_list, bool plan_only = false)
271  {
272  int l = bp::len(poses_list);
273  std::vector<geometry_msgs::PoseStamped> poses(l);
274  for (int i = 0; i < l; ++i)
275  py_bindings_tools::deserializeMsg(py_bindings_tools::ByteString(poses_list[i]), poses[i]);
276  GILReleaser gr;
277  return place(object_name, poses, plan_only) == moveit::core::MoveItErrorCode::SUCCESS;
278  }
279 
280  bool placeLocation(const std::string& object_name, const py_bindings_tools::ByteString& location_str,
281  bool plan_only = false)
282  {
283  std::vector<moveit_msgs::action::PlaceLocation> locations(1);
284  py_bindings_tools::deserializeMsg(location_str, locations[0]);
285  GILReleaser gr;
286  return place(object_name, std::move(locations), plan_only) == moveit::core::MoveItErrorCode::SUCCESS;
287  }
288 
289  bool placeLocations(const std::string& object_name, const bp::list& location_list, bool plan_only = false)
290  {
291  int l = bp::len(location_list);
292  std::vector<moveit_msgs::PlaceLocation> locations(l);
293  for (int i = 0; i < l; ++i)
294  py_bindings_tools::deserializeMsg(py_bindings_tools::ByteString(location_list[i]), locations[i]);
295  GILReleaser gr;
296  return place(object_name, std::move(locations), plan_only) == moveit::core::MoveItErrorCode::SUCCESS;
297  }
298 
299  bool placeAnywhere(const std::string& object_name, bool plan_only = false)
300  {
301  GILReleaser gr;
302  return place(object_name, plan_only) == moveit::core::MoveItErrorCode::SUCCESS;
303  }
304 
305  void convertListToArrayOfPoses(const bp::list& poses, std::vector<geometry_msgs::Pose>& msg)
306  {
307  int l = bp::len(poses);
308  for (int i = 0; i < l; ++i)
309  {
310  const bp::list& pose = bp::extract<bp::list>(poses[i]);
311  std::vector<double> v = py_bindings_tools::doubleFromList(pose);
312  if (v.size() == 6 || v.size() == 7)
313  {
314  Eigen::Isometry3d p;
315  if (v.size() == 6)
316  {
317  tf2::Quaternion tq;
318  tq.setRPY(v[3], v[4], v[5]);
319  Eigen::Quaterniond eq;
320  tf2::convert(tq, eq);
321  p = Eigen::Isometry3d(eq);
322  }
323  else
324  p = Eigen::Isometry3d(Eigen::Quaterniond(v[6], v[3], v[4], v[5]));
325  p.translation() = Eigen::Vector3d(v[0], v[1], v[2]);
326  geometry_msgs::Pose pm = tf2::toMsg(p);
327  msg.push_back(pm);
328  }
329  else
330  ROS_WARN("Incorrect number of values for a pose: %u", (unsigned int)v.size());
331  }
332  }
333 
334  bp::dict getCurrentStateBoundedPython()
335  {
336  moveit::core::RobotStatePtr current = getCurrentState();
337  current->enforceBounds();
338  moveit_msgs::msg::RobotState rsmv;
340  bp::dict output;
341  for (size_t x = 0; x < rsmv.joint_state.name.size(); ++x)
342  output[rsmv.joint_state.name[x]] = rsmv.joint_state.position[x];
343  return output;
344  }
345 
346  py_bindings_tools::ByteString getCurrentStatePython()
347  {
348  moveit::core::RobotStatePtr current_state = getCurrentState();
349  moveit_msgs::RobotState state_message;
350  moveit::core::robotStateToRobotStateMsg(*current_state, state_message);
351  return py_bindings_tools::serializeMsg(state_message);
352  }
353 
354  void setStartStatePython(const py_bindings_tools::ByteString& msg_str)
355  {
356  moveit_msgs::msg::RobotState msg;
357  py_bindings_tools::deserializeMsg(msg_str, msg);
358  setStartState(msg);
359  }
360 
361  bool setPoseTargetsPython(bp::list& poses, const std::string& end_effector_link = "")
362  {
363  std::vector<geometry_msgs::Pose> msg;
364  convertListToArrayOfPoses(poses, msg);
365  return setPoseTargets(msg, end_effector_link);
366  }
367  py_bindings_tools::ByteString getPoseTargetPython(const std::string& end_effector_link)
368  {
369  geometry_msgs::PoseStamped pose = moveit::planning_interface::MoveGroupInterface::getPoseTarget(end_effector_link);
370  return py_bindings_tools::serializeMsg(pose);
371  }
372 
373  bool setPoseTargetPython(bp::list& pose, const std::string& end_effector_link = "")
374  {
375  std::vector<double> v = py_bindings_tools::doubleFromList(pose);
376  geometry_msgs::Pose msg;
377  if (v.size() == 6)
378  {
379  tf2::Quaternion q;
380  q.setRPY(v[3], v[4], v[5]);
381  tf2::convert(q, msg.orientation);
382  }
383  else if (v.size() == 7)
384  {
385  msg.orientation.x = v[3];
386  msg.orientation.y = v[4];
387  msg.orientation.z = v[5];
388  msg.orientation.w = v[6];
389  }
390  else
391  {
392  ROS_ERROR("Pose description expected to consist of either 6 or 7 values");
393  return false;
394  }
395  msg.position.x = v[0];
396  msg.position.y = v[1];
397  msg.position.z = v[2];
398  return setPoseTarget(msg, end_effector_link);
399  }
400 
401  const char* getEndEffectorLinkCStr() const
402  {
403  return getEndEffectorLink().c_str();
404  }
405 
406  const char* getPoseReferenceFrameCStr() const
407  {
408  return getPoseReferenceFrame().c_str();
409  }
410 
411  const char* getNameCStr() const
412  {
413  return getName().c_str();
414  }
415 
416  const char* getPlannerIdCStr() const
417  {
418  return getPlannerId().c_str();
419  }
420 
421  const char* getPlanningPipelineIdCStr() const
422  {
423  return getPlanningPipelineId().c_str();
424  }
425 
426  bp::dict getNamedTargetValuesPython(const std::string& name)
427  {
428  bp::dict output;
429  std::map<std::string, double> positions = getNamedTargetValues(name);
430  std::map<std::string, double>::iterator iterator;
431 
432  for (iterator = positions.begin(); iterator != positions.end(); ++iterator)
433  output[iterator->first] = iterator->second;
434  return output;
435  }
436 
437  bp::list getNamedTargetsPython()
438  {
439  return py_bindings_tools::listFromString(getNamedTargets());
440  }
441 
442  bool movePython()
443  {
444  GILReleaser gr;
445  return move() == moveit::core::MoveItErrorCode::SUCCESS;
446  }
447 
448  bool asyncMovePython()
449  {
450  return asyncMove() == moveit::core::MoveItErrorCode::SUCCESS;
451  }
452 
453  bool attachObjectPython(const std::string& object_name, const std::string& link_name, const bp::list& touch_links)
454  {
455  return attachObject(object_name, link_name, py_bindings_tools::stringFromList(touch_links));
456  }
457 
458  bool executePython(const py_bindings_tools::ByteString& plan_str)
459  {
460  MoveGroupInterface::Plan plan;
461  py_bindings_tools::deserializeMsg(plan_str, plan.trajectory_);
462  GILReleaser gr;
463  return execute(plan) == moveit::core::MoveItErrorCode::SUCCESS;
464  }
465 
466  bool asyncExecutePython(const py_bindings_tools::ByteString& plan_str)
467  {
468  MoveGroupInterface::Plan plan;
469  py_bindings_tools::deserializeMsg(plan_str, plan.trajectory_);
470  return asyncExecute(plan) == moveit::core::MoveItErrorCode::SUCCESS;
471  }
472 
473  bp::tuple planPython()
474  {
475  MoveGroupInterface::Plan plan;
476  moveit_msgs::MoveItErrorCodes res;
477  {
478  GILReleaser gr;
480  }
481  return bp::make_tuple(py_bindings_tools::serializeMsg(res), py_bindings_tools::serializeMsg(plan.trajectory_),
482  plan.planning_time_);
483  }
484 
485  py_bindings_tools::ByteString constructMotionPlanRequestPython()
486  {
488  constructMotionPlanRequest(request);
489  return py_bindings_tools::serializeMsg(request);
490  }
491 
492  bp::tuple computeCartesianPathPython(const bp::list& waypoints, double eef_step, double jump_threshold,
493  bool avoid_collisions)
494  {
495  moveit_msgs::msg::Constraints path_constraints_tmp;
496  return doComputeCartesianPathPython(waypoints, eef_step, jump_threshold, avoid_collisions, path_constraints_tmp);
497  }
498 
499  bp::tuple computeCartesianPathConstrainedPython(const bp::list& waypoints, double eef_step, double jump_threshold,
500  bool avoid_collisions,
501  const py_bindings_tools::ByteString& path_constraints_str)
502  {
503  moveit_msgs::msg::Constraints path_constraints;
505  return doComputeCartesianPathPython(waypoints, eef_step, jump_threshold, avoid_collisions, path_constraints);
506  }
507 
508  bp::tuple doComputeCartesianPathPython(const bp::list& waypoints, double eef_step, double jump_threshold,
509  bool avoid_collisions, const moveit_msgs::msg::Constraints& path_constraints)
510  {
511  std::vector<geometry_msgs::Pose> poses;
512  convertListToArrayOfPoses(waypoints, poses);
513  moveit_msgs::msg::RobotTrajectory trajectory;
514  double fraction;
515  {
516  GILReleaser gr;
517  fraction = computeCartesianPath(poses, eef_step, jump_threshold, trajectory, path_constraints, avoid_collisions);
518  }
519  return bp::make_tuple(py_bindings_tools::serializeMsg(trajectory), fraction);
520  }
521 
522  int pickGrasp(const std::string& object, const py_bindings_tools::ByteString& grasp_str, bool plan_only = false)
523  {
524  moveit_msgs::msg::Grasp grasp;
525  py_bindings_tools::deserializeMsg(grasp_str, grasp);
526  GILReleaser gr;
527  return pick(object, grasp, plan_only).val;
528  }
529 
530  int pickGrasps(const std::string& object, const bp::list& grasp_list, bool plan_only = false)
531  {
532  int l = bp::len(grasp_list);
533  std::vector<moveit_msgs::msg::Grasp> grasps(l);
534  for (int i = 0; i < l; ++i)
535  py_bindings_tools::deserializeMsg(py_bindings_tools::ByteString(grasp_list[i]), grasps[i]);
536  GILReleaser gr;
537  return pick(object, std::move(grasps), plan_only).val;
538  }
539 
540  void setPathConstraintsFromMsg(const py_bindings_tools::ByteString& constraints_str)
541  {
542  moveit_msgs::msg::Constraints constraints_msg;
543  py_bindings_tools::deserializeMsg(constraints_str, constraints_msg);
544  setPathConstraints(constraints_msg);
545  }
546 
547  py_bindings_tools::ByteString getPathConstraintsPython()
548  {
549  moveit_msgs::msg::Constraints constraints_msg(getPathConstraints());
550  return py_bindings_tools::serializeMsg(constraints_msg);
551  }
552 
553  void setTrajectoryConstraintsFromMsg(const py_bindings_tools::ByteString& constraints_str)
554  {
555  moveit_msgs::TrajectoryConstraints constraints_msg;
556  py_bindings_tools::deserializeMsg(constraints_str, constraints_msg);
557  setTrajectoryConstraints(constraints_msg);
558  }
559 
560  py_bindings_tools::ByteString getTrajectoryConstraintsPython()
561  {
562  moveit_msgs::TrajectoryConstraints constraints_msg(getTrajectoryConstraints());
563  return py_bindings_tools::serializeMsg(constraints_msg);
564  }
565 
566  py_bindings_tools::ByteString retimeTrajectory(const py_bindings_tools::ByteString& ref_state_str,
567  const py_bindings_tools::ByteString& traj_str,
568  double velocity_scaling_factor, double acceleration_scaling_factor,
569  const std::string& algorithm)
570  {
571  // Convert reference state message to object
572  moveit_msgs::msg::RobotState ref_state_msg;
573  py_bindings_tools::deserializeMsg(ref_state_str, ref_state_msg);
574  moveit::core::RobotState ref_state_obj(getRobotModel());
575  if (moveit::core::robotStateMsgToRobotState(ref_state_msg, ref_state_obj, true))
576  {
577  // Convert trajectory message to object
578  moveit_msgs::msg::RobotTrajectory traj_msg;
579  py_bindings_tools::deserializeMsg(traj_str, traj_msg);
580  bool algorithm_found = true;
581  {
582  GILReleaser gr;
583  robot_trajectory::RobotTrajectory traj_obj(getRobotModel(), getName());
584  traj_obj.setRobotTrajectoryMsg(ref_state_obj, traj_msg);
585 
586  // Do the actual retiming
587  if (algorithm == "iterative_time_parameterization")
588  {
590  time_param.computeTimeStamps(traj_obj, velocity_scaling_factor, acceleration_scaling_factor);
591  }
592  else if (algorithm == "iterative_spline_parameterization")
593  {
595  time_param.computeTimeStamps(traj_obj, velocity_scaling_factor, acceleration_scaling_factor);
596  }
597  else if (algorithm == "time_optimal_trajectory_generation")
598  {
600  time_param.computeTimeStamps(traj_obj, velocity_scaling_factor, acceleration_scaling_factor);
601  }
602  else
603  {
604  ROS_ERROR_STREAM_NAMED("move_group_py", "Unknown time parameterization algorithm: " << algorithm);
605  algorithm_found = false;
606  traj_msg = moveit_msgs::RobotTrajectory();
607  }
608 
609  if (algorithm_found)
610  // Convert the retimed trajectory back into a message
611  traj_obj.getRobotTrajectoryMsg(traj_msg);
612  }
613  return py_bindings_tools::serializeMsg(traj_msg);
614  }
615  else
616  {
617  ROS_ERROR("Unable to convert RobotState message to RobotState instance.");
618  return py_bindings_tools::ByteString("");
619  }
620  }
621 
622  Eigen::MatrixXd getJacobianMatrixPython(const bp::list& joint_values, const bp::object& reference_point = bp::object())
623  {
624  const std::vector<double> v = py_bindings_tools::doubleFromList(joint_values);
625  std::vector<double> ref;
626  if (reference_point.is_none())
627  ref = { 0.0, 0.0, 0.0 };
628  else
629  ref = py_bindings_tools::doubleFromList(reference_point);
630  if (ref.size() != 3)
631  throw std::invalid_argument("reference point needs to have 3 elements, got " + std::to_string(ref.size()));
632 
633  moveit::core::RobotState state(getRobotModel());
634  state.setToDefaultValues();
635  auto group = state.getJointModelGroup(getName());
636  state.setJointGroupPositions(group, v);
637  return state.getJacobian(group, Eigen::Map<Eigen::Vector3d>(&ref[0]));
638  }
639 
640  py_bindings_tools::ByteString enforceBoundsPython(const py_bindings_tools::ByteString& msg_str)
641  {
642  moveit_msgs::RobotState state_msg;
643  py_bindings_tools::deserializeMsg(msg_str, state_msg);
644  moveit::core::RobotState state(getRobotModel());
645  if (moveit::core::robotStateMsgToRobotState(state_msg, state, true))
646  {
647  state.enforceBounds();
648  moveit::core::robotStateToRobotStateMsg(state, state_msg);
649  return py_bindings_tools::serializeMsg(state_msg);
650  }
651  else
652  {
653  ROS_ERROR("Unable to convert RobotState message to RobotState instance.");
654  return py_bindings_tools::ByteString("");
655  }
656  }
657 };
658 
659 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getJacobianMatrixOverloads, getJacobianMatrixPython, 1, 2)
660 
661 static void wrap_move_group_interface()
662 {
663  eigenpy::enableEigenPy();
664 
665  bp::class_<MoveGroupInterfaceWrapper, boost::noncopyable> move_group_interface_class(
666  "MoveGroupInterface", bp::init<std::string, std::string, bp::optional<std::string, double>>());
667 
668  move_group_interface_class.def("async_move", &MoveGroupInterfaceWrapper::asyncMovePython);
669  move_group_interface_class.def("move", &MoveGroupInterfaceWrapper::movePython);
670  move_group_interface_class.def("execute", &MoveGroupInterfaceWrapper::executePython);
671  move_group_interface_class.def("async_execute", &MoveGroupInterfaceWrapper::asyncExecutePython);
672  moveit::core::MoveItErrorCode (MoveGroupInterfaceWrapper::*pick_1)(const std::string&, bool) =
673  &MoveGroupInterfaceWrapper::pick;
674  move_group_interface_class.def("pick", pick_1);
675  move_group_interface_class.def("pick", &MoveGroupInterfaceWrapper::pickGrasp);
676  move_group_interface_class.def("pick", &MoveGroupInterfaceWrapper::pickGrasps);
677  move_group_interface_class.def("place", &MoveGroupInterfaceWrapper::placePose);
678  move_group_interface_class.def("place_poses_list", &MoveGroupInterfaceWrapper::placePoses);
679  move_group_interface_class.def("place", &MoveGroupInterfaceWrapper::placeLocation);
680  move_group_interface_class.def("place_locations_list", &MoveGroupInterfaceWrapper::placeLocations);
681  move_group_interface_class.def("place", &MoveGroupInterfaceWrapper::placeAnywhere);
682  move_group_interface_class.def("stop", &MoveGroupInterfaceWrapper::stop);
683 
684  move_group_interface_class.def("get_name", &MoveGroupInterfaceWrapper::getNameCStr);
685  move_group_interface_class.def("get_planning_frame", &MoveGroupInterfaceWrapper::getPlanningFrameCStr);
686  move_group_interface_class.def("get_interface_description", &MoveGroupInterfaceWrapper::getInterfaceDescriptionPython);
687 
688  move_group_interface_class.def("get_active_joints", &MoveGroupInterfaceWrapper::getActiveJointsList);
689  move_group_interface_class.def("get_joints", &MoveGroupInterfaceWrapper::getJointsList);
690  move_group_interface_class.def("get_variable_count", &MoveGroupInterfaceWrapper::getVariableCount);
691  move_group_interface_class.def("allow_looking", &MoveGroupInterfaceWrapper::allowLooking);
692  move_group_interface_class.def("allow_replanning", &MoveGroupInterfaceWrapper::allowReplanning);
693 
694  move_group_interface_class.def("set_pose_reference_frame", &MoveGroupInterfaceWrapper::setPoseReferenceFrame);
695 
696  move_group_interface_class.def("set_pose_reference_frame", &MoveGroupInterfaceWrapper::setPoseReferenceFrame);
697  move_group_interface_class.def("set_end_effector_link", &MoveGroupInterfaceWrapper::setEndEffectorLink);
698  move_group_interface_class.def("get_end_effector_link", &MoveGroupInterfaceWrapper::getEndEffectorLinkCStr);
699  move_group_interface_class.def("get_pose_reference_frame", &MoveGroupInterfaceWrapper::getPoseReferenceFrameCStr);
700 
701  move_group_interface_class.def("set_pose_target", &MoveGroupInterfaceWrapper::setPoseTargetPython);
702 
703  move_group_interface_class.def("set_pose_targets", &MoveGroupInterfaceWrapper::setPoseTargetsPython);
704 
705  move_group_interface_class.def("set_position_target", &MoveGroupInterfaceWrapper::setPositionTarget);
706  move_group_interface_class.def("set_rpy_target", &MoveGroupInterfaceWrapper::setRPYTarget);
707  move_group_interface_class.def("set_orientation_target", &MoveGroupInterfaceWrapper::setOrientationTarget);
708 
709  move_group_interface_class.def("get_current_pose", &MoveGroupInterfaceWrapper::getCurrentPosePython);
710  move_group_interface_class.def("get_current_rpy", &MoveGroupInterfaceWrapper::getCurrentRPYPython);
711 
712  move_group_interface_class.def("get_random_pose", &MoveGroupInterfaceWrapper::getRandomPosePython);
713 
714  move_group_interface_class.def("clear_pose_target", &MoveGroupInterfaceWrapper::clearPoseTarget);
715  move_group_interface_class.def("clear_pose_targets", &MoveGroupInterfaceWrapper::clearPoseTargets);
716 
717  move_group_interface_class.def("set_joint_value_target",
718  &MoveGroupInterfaceWrapper::setJointValueTargetPythonIterable);
719  move_group_interface_class.def("set_joint_value_target", &MoveGroupInterfaceWrapper::setJointValueTargetPythonDict);
720 
721  move_group_interface_class.def("set_joint_value_target",
722  &MoveGroupInterfaceWrapper::setJointValueTargetPerJointPythonList);
723  bool (MoveGroupInterfaceWrapper::*set_joint_value_target_4)(const std::string&, double) =
724  &MoveGroupInterfaceWrapper::setJointValueTarget;
725  move_group_interface_class.def("set_joint_value_target", set_joint_value_target_4);
726 
727  move_group_interface_class.def("set_joint_value_target_from_pose",
728  &MoveGroupInterfaceWrapper::setJointValueTargetFromPosePython);
729  move_group_interface_class.def("set_joint_value_target_from_pose_stamped",
730  &MoveGroupInterfaceWrapper::setJointValueTargetFromPoseStampedPython);
731  move_group_interface_class.def("set_joint_value_target_from_joint_state_message",
732  &MoveGroupInterfaceWrapper::setJointValueTargetFromJointStatePython);
733 
734  move_group_interface_class.def("get_joint_value_target", &MoveGroupInterfaceWrapper::getJointValueTargetPythonList);
735 
736  move_group_interface_class.def("set_named_target", &MoveGroupInterfaceWrapper::setNamedTarget);
737  move_group_interface_class.def("set_random_target", &MoveGroupInterfaceWrapper::setRandomTarget);
738 
739  void (MoveGroupInterfaceWrapper::*remember_joint_values_2)(const std::string&) =
740  &MoveGroupInterfaceWrapper::rememberJointValues;
741  move_group_interface_class.def("remember_joint_values", remember_joint_values_2);
742 
743  move_group_interface_class.def("remember_joint_values", &MoveGroupInterfaceWrapper::rememberJointValuesFromPythonList);
744 
745  move_group_interface_class.def("start_state_monitor", &MoveGroupInterfaceWrapper::startStateMonitor);
746  move_group_interface_class.def("get_current_joint_values", &MoveGroupInterfaceWrapper::getCurrentJointValuesList);
747  move_group_interface_class.def("get_random_joint_values", &MoveGroupInterfaceWrapper::getRandomJointValuesList);
748  move_group_interface_class.def("get_remembered_joint_values",
749  &MoveGroupInterfaceWrapper::getRememberedJointValuesPython);
750 
751  move_group_interface_class.def("forget_joint_values", &MoveGroupInterfaceWrapper::forgetJointValues);
752 
753  move_group_interface_class.def("get_goal_joint_tolerance", &MoveGroupInterfaceWrapper::getGoalJointTolerance);
754  move_group_interface_class.def("get_goal_position_tolerance", &MoveGroupInterfaceWrapper::getGoalPositionTolerance);
755  move_group_interface_class.def("get_goal_orientation_tolerance",
756  &MoveGroupInterfaceWrapper::getGoalOrientationTolerance);
757 
758  move_group_interface_class.def("set_goal_joint_tolerance", &MoveGroupInterfaceWrapper::setGoalJointTolerance);
759  move_group_interface_class.def("set_goal_position_tolerance", &MoveGroupInterfaceWrapper::setGoalPositionTolerance);
760  move_group_interface_class.def("set_goal_orientation_tolerance",
761  &MoveGroupInterfaceWrapper::setGoalOrientationTolerance);
762  move_group_interface_class.def("set_goal_tolerance", &MoveGroupInterfaceWrapper::setGoalTolerance);
763 
764  move_group_interface_class.def("set_start_state_to_current_state",
765  &MoveGroupInterfaceWrapper::setStartStateToCurrentState);
766  move_group_interface_class.def("set_start_state", &MoveGroupInterfaceWrapper::setStartStatePython);
767 
768  bool (MoveGroupInterfaceWrapper::*set_path_constraints_1)(const std::string&) =
769  &MoveGroupInterfaceWrapper::setPathConstraints;
770  move_group_interface_class.def("set_path_constraints", set_path_constraints_1);
771  move_group_interface_class.def("set_path_constraints_from_msg", &MoveGroupInterfaceWrapper::setPathConstraintsFromMsg);
772  move_group_interface_class.def("get_path_constraints", &MoveGroupInterfaceWrapper::getPathConstraintsPython);
773  move_group_interface_class.def("clear_path_constraints", &MoveGroupInterfaceWrapper::clearPathConstraints);
774 
775  move_group_interface_class.def("set_trajectory_constraints_from_msg",
776  &MoveGroupInterfaceWrapper::setTrajectoryConstraintsFromMsg);
777  move_group_interface_class.def("get_trajectory_constraints",
778  &MoveGroupInterfaceWrapper::getTrajectoryConstraintsPython);
779  move_group_interface_class.def("clear_trajectory_constraints", &MoveGroupInterfaceWrapper::clearTrajectoryConstraints);
780  move_group_interface_class.def("get_known_constraints", &MoveGroupInterfaceWrapper::getKnownConstraintsList);
781  move_group_interface_class.def("set_constraints_database", &MoveGroupInterfaceWrapper::setConstraintsDatabase);
782  move_group_interface_class.def("set_workspace", &MoveGroupInterfaceWrapper::setWorkspace);
783  move_group_interface_class.def("set_planning_time", &MoveGroupInterfaceWrapper::setPlanningTime);
784  move_group_interface_class.def("get_planning_time", &MoveGroupInterfaceWrapper::getPlanningTime);
785  move_group_interface_class.def("set_max_velocity_scaling_factor",
786  &MoveGroupInterfaceWrapper::setMaxVelocityScalingFactor);
787  move_group_interface_class.def("set_max_acceleration_scaling_factor",
788  &MoveGroupInterfaceWrapper::setMaxAccelerationScalingFactor);
789  move_group_interface_class.def("set_planner_id", &MoveGroupInterfaceWrapper::setPlannerId);
790  move_group_interface_class.def("get_planner_id", &MoveGroupInterfaceWrapper::getPlannerIdCStr);
791  move_group_interface_class.def("set_planning_pipeline_id", &MoveGroupInterfaceWrapper::setPlanningPipelineId);
792  move_group_interface_class.def("get_planning_pipeline_id", &MoveGroupInterfaceWrapper::getPlanningPipelineIdCStr);
793  move_group_interface_class.def("set_num_planning_attempts", &MoveGroupInterfaceWrapper::setNumPlanningAttempts);
794  move_group_interface_class.def("plan", &MoveGroupInterfaceWrapper::planPython);
795  move_group_interface_class.def("construct_motion_plan_request",
796  &MoveGroupInterfaceWrapper::constructMotionPlanRequestPython);
797  move_group_interface_class.def("compute_cartesian_path", &MoveGroupInterfaceWrapper::computeCartesianPathPython);
798  move_group_interface_class.def("compute_cartesian_path",
799  &MoveGroupInterfaceWrapper::computeCartesianPathConstrainedPython);
800  move_group_interface_class.def("set_support_surface_name", &MoveGroupInterfaceWrapper::setSupportSurfaceName);
801  move_group_interface_class.def("attach_object", &MoveGroupInterfaceWrapper::attachObjectPython);
802  move_group_interface_class.def("detach_object", &MoveGroupInterfaceWrapper::detachObject);
803  move_group_interface_class.def("retime_trajectory", &MoveGroupInterfaceWrapper::retimeTrajectory);
804  move_group_interface_class.def("get_named_targets", &MoveGroupInterfaceWrapper::getNamedTargetsPython);
805  move_group_interface_class.def("get_named_target_values", &MoveGroupInterfaceWrapper::getNamedTargetValuesPython);
806  move_group_interface_class.def("get_current_state_bounded", &MoveGroupInterfaceWrapper::getCurrentStateBoundedPython);
807  move_group_interface_class.def("get_current_state", &MoveGroupInterfaceWrapper::getCurrentStatePython);
808  move_group_interface_class.def("get_jacobian_matrix", &MoveGroupInterfaceWrapper::getJacobianMatrixPython,
809  getJacobianMatrixOverloads());
810  move_group_interface_class.def("enforce_bounds", &MoveGroupInterfaceWrapper::enforceBoundsPython);
811 }
812 } // namespace planning_interface
813 } // namespace moveit
814 
815 BOOST_PYTHON_MODULE(_moveit_move_group_interface)
816 {
817  using namespace moveit::planning_interface;
818  wrap_move_group_interface();
819 }
820 
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:90
moveit::core::MoveItErrorCode plan(Plan &plan)
Compute a motion plan that takes the group declared in the constructor from the current state to the ...
const geometry_msgs::msg::PoseStamped & getPoseTarget(const std::string &end_effector_link="") const
const moveit::core::RobotState & getJointValueTarget() const
Get the currently set joint state goal, replaced by private getTargetRobotState()
const moveit::core::RobotState & getTargetRobotState() const
RAII Helper to release the Global Interpreter Lock (GIL)
Definition: gil_releaser.h:55
Maintain a sequence of waypoints and the time durations between these waypoints.
bool computeTimeStamps(robot_trajectory::RobotTrajectory &trajectory, const double max_velocity_scaling_factor=1.0, const double max_acceleration_scaling_factor=1.0) const override
This class sets the timestamps of a trajectory to enforce velocity, acceleration constraints....
bool computeTimeStamps(robot_trajectory::RobotTrajectory &trajectory, const double max_velocity_scaling_factor=1.0, const double max_acceleration_scaling_factor=1.0) const override
bool computeTimeStamps(robot_trajectory::RobotTrajectory &trajectory, const double max_velocity_scaling_factor=1.0, const double max_acceleration_scaling_factor=1.0) const override
void attachObject()
Definition: demo.cpp:104
Vec3fX< details::Vec3Data< double > > Vector3d
Definition: fcl_compat.h:89
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::msg::RobotState &robot_state, bool copy_attached_bodies=true)
Convert a MoveIt robot state to a robot state message.
bool robotStateMsgToRobotState(const Transforms &tf, const moveit_msgs::msg::RobotState &robot_state, RobotState &state, bool copy_attached_bodies=true)
Convert a robot state msg (with accompanying extra transforms) to a MoveIt robot state.
Simple interface to MoveIt components.
Definition: moveit_cpp.h:203
moveit::core::MoveItErrorCode MoveItErrorCode
boost::python::list listFromString(const std::vector< std::string > &v)
boost::python::list listFromDouble(const std::vector< double > &v)
ByteString serializeMsg(const T &msg)
Convert a ROS message to a Python Bytestring.
std::vector< std::string > stringFromList(const boost::python::object &values)
void deserializeMsg(const ByteString &data, T &msg)
Convert a Python Bytestring to a ROS message.
std::vector< double > doubleFromList(const boost::python::object &values)
Main namespace for MoveIt.
Definition: exceptions.h:43
Definition: pick.py:1
p
Definition: pick.py:62
x
Definition: pick.py:64
Definition: plan.py:1
This namespace includes the base class for MoveIt planners.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
d
Definition: setup.py:4
name
Definition: setup.py:7
BOOST_PYTHON_MODULE(_moveit_roscpp_initializer)