44#include <rclcpp/rclcpp.hpp>
45#include <rclcpp/version.h>
47#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
58#include <moveit_msgs/action/execute_trajectory.hpp>
59#include <moveit_msgs/srv/query_planner_interfaces.hpp>
60#include <moveit_msgs/srv/get_cartesian_path.hpp>
61#include <moveit_msgs/srv/grasp_planning.hpp>
62#include <moveit_msgs/srv/get_planner_params.hpp>
63#include <moveit_msgs/srv/set_planner_params.hpp>
67#include <std_msgs/msg/string.hpp>
68#include <geometry_msgs/msg/transform_stamped.hpp>
70#if __has_include(<tf2/utils.hpp>)
71#include <tf2/utils.hpp>
75#include <tf2_eigen/tf2_eigen.hpp>
77#if RCLCPP_VERSION_GTE(29, 6, 0)
78#include <tf2_ros/transform_listener.hpp>
81#include <tf2_ros/transform_listener.h>
104#if RCLCPP_VERSION_GTE(17, 0, 0)
107 return rclcpp::SystemDefaultsQoS();
112 return rmw_qos_profile_services_default;
120 friend MoveGroupInterface;
124 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer,
const rclcpp::Duration& wait_for_servers)
125 : opt_(opt), node_(node), logger_(
moveit::
getLogger(
"moveit.ros.move_group_interface")), tf_buffer_(tf_buffer)
129 callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive,
131 callback_executor_.add_callback_group(callback_group_, node->get_node_base_interface());
132 callback_thread_ = std::thread([
this]() { callback_executor_.spin(); });
137 std::string error =
"Unable to construct robot model. Please make sure all needed information is on the "
139 RCLCPP_FATAL_STREAM(logger_, error);
140 throw std::runtime_error(error);
145 std::string error =
"Group '" + opt.group_name +
"' was not found.";
146 RCLCPP_FATAL_STREAM(logger_, error);
147 throw std::runtime_error(error);
153 joint_state_target_ = std::make_shared<moveit::core::RobotState>(
getRobotModel());
154 joint_state_target_->setToDefaultValues();
155 active_target_ = JOINT;
157 look_around_attempts_ = 0;
160 replan_attempts_ = 1;
161 goal_joint_tolerance_ = 1e-4;
162 goal_position_tolerance_ = 1e-4;
163 goal_orientation_tolerance_ = 1e-3;
164 allowed_planning_time_ = 5.0;
165 num_planning_attempts_ = 1;
166 node_->get_parameter_or<
double>(
"robot_description_planning.default_velocity_scaling_factor",
167 max_velocity_scaling_factor_, 0.1);
168 node_->get_parameter_or<
double>(
"robot_description_planning.default_acceleration_scaling_factor",
169 max_acceleration_scaling_factor_, 0.1);
170 initializing_constraints_ =
false;
172 if (joint_model_group_->isChain())
173 end_effector_link_ = joint_model_group_->getLinkModelNames().back();
176 trajectory_event_publisher_ = node_->create_publisher<std_msgs::msg::String>(
180 attached_object_publisher_ = node_->create_publisher<moveit_msgs::msg::AttachedCollisionObject>(
187 move_action_client_ = rclcpp_action::create_client<moveit_msgs::action::MoveGroup>(
189 move_action_client_->wait_for_action_server(wait_for_servers.to_chrono<std::chrono::duration<double>>());
190 execute_action_client_ = rclcpp_action::create_client<moveit_msgs::action::ExecuteTrajectory>(
191 node_,
rclcpp::names::append(opt_.move_group_namespace, move_group::EXECUTE_ACTION_NAME), callback_group_);
192 execute_action_client_->wait_for_action_server(wait_for_servers.to_chrono<std::chrono::duration<double>>());
194 query_service_ = node_->create_client<moveit_msgs::srv::QueryPlannerInterfaces>(
195 rclcpp::names::append(opt_.move_group_namespace, move_group::QUERY_PLANNERS_SERVICE_NAME), qosDefault(),
197 get_params_service_ = node_->create_client<moveit_msgs::srv::GetPlannerParams>(
198 rclcpp::names::append(opt_.move_group_namespace, move_group::GET_PLANNER_PARAMS_SERVICE_NAME), qosDefault(),
200 set_params_service_ = node_->create_client<moveit_msgs::srv::SetPlannerParams>(
201 rclcpp::names::append(opt_.move_group_namespace, move_group::SET_PLANNER_PARAMS_SERVICE_NAME), qosDefault(),
203 cartesian_path_service_ = node_->create_client<moveit_msgs::srv::GetCartesianPath>(
204 rclcpp::names::append(opt_.move_group_namespace, move_group::CARTESIAN_PATH_SERVICE_NAME), qosDefault(),
207 RCLCPP_INFO_STREAM(logger_,
"Ready to take commands for planning group " << opt.
group_name <<
'.');
212 if (constraints_init_thread_)
213 constraints_init_thread_->join();
215 callback_executor_.cancel();
217 if (callback_thread_.joinable())
218 callback_thread_.join();
221 const std::shared_ptr<tf2_ros::Buffer>&
getTF()
const
238 return joint_model_group_;
243 return *move_action_client_;
248 auto req = std::make_shared<moveit_msgs::srv::QueryPlannerInterfaces::Request>();
249 auto future_response = query_service_->async_send_request(req);
251 if (future_response.valid())
253 const auto& response = future_response.get();
254 if (!response->planner_interfaces.empty())
256 desc = response->planner_interfaces.front();
265 auto req = std::make_shared<moveit_msgs::srv::QueryPlannerInterfaces::Request>();
266 auto future_response = query_service_->async_send_request(req);
267 if (future_response.valid())
269 const auto& response = future_response.get();
270 if (!response->planner_interfaces.empty())
272 desc = response->planner_interfaces;
279 std::map<std::string, std::string>
getPlannerParams(
const std::string& planner_id,
const std::string& group =
"")
281 auto req = std::make_shared<moveit_msgs::srv::GetPlannerParams::Request>();
282 moveit_msgs::srv::GetPlannerParams::Response::SharedPtr response;
283 req->planner_config = planner_id;
285 std::map<std::string, std::string> result;
287 auto future_response = get_params_service_->async_send_request(req);
288 if (future_response.valid())
290 response = future_response.get();
291 for (
unsigned int i = 0, end = response->params.keys.size(); i < end; ++i)
292 result[response->params.keys[i]] = response->params.values[i];
298 const std::map<std::string, std::string>& params,
bool replace =
false)
300 auto req = std::make_shared<moveit_msgs::srv::SetPlannerParams::Request>();
301 req->planner_config = planner_id;
303 req->replace = replace;
304 for (
const std::pair<const std::string, std::string>& param : params)
306 req->params.keys.push_back(param.first);
307 req->params.values.push_back(param.second);
309 set_params_service_->async_send_request(req);
314 std::string default_planning_pipeline;
315 node_->get_parameter(
"move_group.default_planning_pipeline", default_planning_pipeline);
316 return default_planning_pipeline;
321 if (pipeline_id != planning_pipeline_id_)
323 planning_pipeline_id_ = pipeline_id;
332 return planning_pipeline_id_;
339 if (!planning_pipeline_id_.empty())
340 pipeline_id = planning_pipeline_id_;
342 std::stringstream param_name;
343 param_name <<
"move_group";
344 if (!pipeline_id.empty())
345 param_name <<
"/planning_pipelines/" << pipeline_id;
347 param_name <<
'.' << group;
348 param_name <<
".default_planner_config";
350 std::string default_planner_config;
351 node_->get_parameter(param_name.str(), default_planner_config);
352 return default_planner_config;
357 planner_id_ = planner_id;
367 num_planning_attempts_ = num_planning_attempts;
377 return max_velocity_scaling_factor_;
382 setMaxScalingFactor(max_acceleration_scaling_factor_, value,
"acceleration_scaling_factor", 0.1);
387 return max_acceleration_scaling_factor_;
390 void setMaxScalingFactor(
double& variable,
const double target_value,
const char* factor_name,
double fallback_value)
392 if (target_value > 1.0)
394 RCLCPP_WARN(logger_,
"Limiting max_%s (%.2f) to 1.0.", factor_name, target_value);
397 else if (target_value <= 0.0)
399 node_->get_parameter_or<
double>(std::string(
"robot_description_planning.default_") + factor_name, variable,
401 if (target_value < 0.0)
403 RCLCPP_WARN(logger_,
"max_%s < 0.0! Setting to default: %.2f.", factor_name, variable);
408 variable = target_value;
414 return *joint_state_target_;
419 return *joint_state_target_;
424 considered_start_state_ = start_state;
429 considered_start_state_ = moveit_msgs::msg::RobotState();
436 considered_start_state_ = moveit_msgs::msg::RobotState();
437 considered_start_state_.is_diff =
true;
442 moveit::core::RobotStatePtr s;
449 const std::string& frame,
bool approx)
451 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
490 tf2::fromMsg(eef_pose, p);
496 RCLCPP_ERROR(logger_,
"Unable to transform from frame '%s' to frame '%s'", frame.c_str(),
510 end_effector_link_ = end_effector;
515 pose_targets_.erase(end_effector_link);
520 pose_targets_.clear();
525 return end_effector_link_;
530 if (!end_effector_link_.empty())
532 const std::vector<std::string>& possible_eefs =
533 getRobotModel()->getJointModelGroup(opt_.group_name)->getAttachedEndEffectorNames();
534 for (
const std::string& possible_eef : possible_eefs)
540 static std::string empty;
544 bool setPoseTargets(
const std::vector<geometry_msgs::msg::PoseStamped>& poses,
const std::string& end_effector_link)
546 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
549 RCLCPP_ERROR(logger_,
"No end-effector to set the pose for");
554 pose_targets_[eef] = poses;
556 std::vector<geometry_msgs::msg::PoseStamped>& stored_poses = pose_targets_[eef];
557 for (geometry_msgs::msg::PoseStamped& stored_pose : stored_poses)
558 stored_pose.header.stamp = rclcpp::Time(0);
565 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
566 return pose_targets_.find(eef) != pose_targets_.end();
569 const geometry_msgs::msg::PoseStamped&
getPoseTarget(
const std::string& end_effector_link)
const
571 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
574 std::map<std::string, std::vector<geometry_msgs::msg::PoseStamped>>::const_iterator jt = pose_targets_.find(eef);
575 if (jt != pose_targets_.end())
577 if (!jt->second.empty())
578 return jt->second.at(0);
582 static const geometry_msgs::msg::PoseStamped UNKNOWN;
583 RCLCPP_ERROR(logger_,
"Pose for end-effector '%s' not known.", eef.c_str());
587 const std::vector<geometry_msgs::msg::PoseStamped>&
getPoseTargets(
const std::string& end_effector_link)
const
589 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
591 std::map<std::string, std::vector<geometry_msgs::msg::PoseStamped>>::const_iterator jt = pose_targets_.find(eef);
592 if (jt != pose_targets_.end())
594 if (!jt->second.empty())
599 static const std::vector<geometry_msgs::msg::PoseStamped> EMPTY;
600 RCLCPP_ERROR(logger_,
"Poses for end-effector '%s' are not known.", eef.c_str());
606 pose_reference_frame_ = pose_reference_frame;
611 return pose_reference_frame_;
616 active_target_ = type;
621 return active_target_;
626 if (!current_state_monitor_)
628 RCLCPP_ERROR(logger_,
"Unable to monitor current robot state");
633 if (!current_state_monitor_->isActive())
634 current_state_monitor_->startStateMonitor();
636 current_state_monitor_->waitForCompleteState(opt_.group_name, wait);
640 bool getCurrentState(moveit::core::RobotStatePtr& current_state,
double wait_seconds = 1.0)
642 if (!current_state_monitor_)
644 RCLCPP_ERROR(logger_,
"Unable to get current robot state");
649 if (!current_state_monitor_->isActive())
650 current_state_monitor_->startStateMonitor();
652 if (!current_state_monitor_->waitForCurrentState(node_->now(), wait_seconds))
654 RCLCPP_ERROR(logger_,
"Failed to fetch current robot state");
658 current_state = current_state_monitor_->getCurrentState();
664 if (!move_action_client_ || !move_action_client_->action_server_is_ready())
666 RCLCPP_INFO_STREAM(logger_,
"MoveGroup action client/server not ready");
667 return moveit::core::MoveItErrorCode::FAILURE;
669 RCLCPP_INFO_STREAM(logger_,
"MoveGroup action client/server ready");
671 moveit_msgs::action::MoveGroup::Goal goal;
673 goal.planning_options.plan_only =
true;
674 goal.planning_options.look_around =
false;
675 goal.planning_options.replan =
false;
676 goal.planning_options.planning_scene_diff.is_diff =
true;
677 goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
680 rclcpp_action::ResultCode code = rclcpp_action::ResultCode::UNKNOWN;
681 std::shared_ptr<moveit_msgs::action::MoveGroup::Result> res;
682 auto send_goal_opts = rclcpp_action::Client<moveit_msgs::action::MoveGroup>::SendGoalOptions();
684 send_goal_opts.goal_response_callback =
685 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::SharedPtr& goal_handle) {
689 RCLCPP_INFO(logger_,
"Planning request rejected");
693 RCLCPP_INFO(logger_,
"Planning request accepted");
696 send_goal_opts.result_callback =
697 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::WrappedResult& result) {
704 case rclcpp_action::ResultCode::SUCCEEDED:
705 RCLCPP_INFO(logger_,
"Planning request complete!");
707 case rclcpp_action::ResultCode::ABORTED:
708 RCLCPP_INFO(logger_,
"Planning request aborted");
710 case rclcpp_action::ResultCode::CANCELED:
711 RCLCPP_INFO(logger_,
"Planning request canceled");
714 RCLCPP_INFO(logger_,
"Planning request unknown result code");
719 auto goal_handle_future = move_action_client_->async_send_goal(goal, send_goal_opts);
724 std::this_thread::sleep_for(std::chrono::milliseconds(1));
727 if (code != rclcpp_action::ResultCode::SUCCEEDED)
729 RCLCPP_ERROR_STREAM(logger_,
"MoveGroupInterface::plan() failed or timeout reached");
730 return res->error_code;
733 plan.trajectory = res->planned_trajectory;
734 plan.start_state = res->trajectory_start;
735 plan.planning_time = res->planning_time;
736 RCLCPP_INFO(logger_,
"time taken to generate plan: %g seconds",
plan.planning_time);
738 return res->error_code;
743 if (!move_action_client_ || !move_action_client_->action_server_is_ready())
745 RCLCPP_INFO_STREAM(logger_,
"MoveGroup action client/server not ready");
746 return moveit::core::MoveItErrorCode::FAILURE;
749 moveit_msgs::action::MoveGroup::Goal goal;
751 goal.planning_options.plan_only =
false;
752 goal.planning_options.look_around = can_look_;
753 goal.planning_options.replan = can_replan_;
754 goal.planning_options.replan_delay = replan_delay_;
755 goal.planning_options.planning_scene_diff.is_diff =
true;
756 goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
759 rclcpp_action::ResultCode code = rclcpp_action::ResultCode::UNKNOWN;
760 std::shared_ptr<moveit_msgs::action::MoveGroup_Result> res;
761 auto send_goal_opts = rclcpp_action::Client<moveit_msgs::action::MoveGroup>::SendGoalOptions();
763 send_goal_opts.goal_response_callback =
764 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::SharedPtr& goal_handle) {
768 RCLCPP_INFO(logger_,
"Plan and Execute request rejected");
772 RCLCPP_INFO(logger_,
"Plan and Execute request accepted");
775 send_goal_opts.result_callback =
776 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::WrappedResult& result) {
783 case rclcpp_action::ResultCode::SUCCEEDED:
784 RCLCPP_INFO(logger_,
"Plan and Execute request complete!");
786 case rclcpp_action::ResultCode::ABORTED:
787 RCLCPP_INFO(logger_,
"Plan and Execute request aborted");
789 case rclcpp_action::ResultCode::CANCELED:
790 RCLCPP_INFO(logger_,
"Plan and Execute request canceled");
793 RCLCPP_INFO(logger_,
"Plan and Execute request unknown result code");
797 auto goal_handle_future = move_action_client_->async_send_goal(goal, send_goal_opts);
799 return moveit::core::MoveItErrorCode::SUCCESS;
804 std::this_thread::sleep_for(std::chrono::milliseconds(1));
807 if (code != rclcpp_action::ResultCode::SUCCEEDED)
809 RCLCPP_ERROR_STREAM(logger_,
"MoveGroupInterface::move() failed or timeout reached");
811 return res->error_code;
815 const std::vector<std::string>& controllers = std::vector<std::string>())
817 if (!execute_action_client_ || !execute_action_client_->action_server_is_ready())
819 RCLCPP_INFO_STREAM(logger_,
"execute_action_client_ client/server not ready");
820 return moveit::core::MoveItErrorCode::FAILURE;
824 rclcpp_action::ResultCode code = rclcpp_action::ResultCode::UNKNOWN;
825 std::shared_ptr<moveit_msgs::action::ExecuteTrajectory_Result> res;
826 auto send_goal_opts = rclcpp_action::Client<moveit_msgs::action::ExecuteTrajectory>::SendGoalOptions();
828 send_goal_opts.goal_response_callback =
829 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::ExecuteTrajectory>::SharedPtr& goal_handle) {
833 RCLCPP_INFO(logger_,
"Execute request rejected");
837 RCLCPP_INFO(logger_,
"Execute request accepted");
840 send_goal_opts.result_callback =
841 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::ExecuteTrajectory>::WrappedResult& result) {
848 case rclcpp_action::ResultCode::SUCCEEDED:
849 RCLCPP_INFO(logger_,
"Execute request success!");
851 case rclcpp_action::ResultCode::ABORTED:
852 RCLCPP_INFO(logger_,
"Execute request aborted");
854 case rclcpp_action::ResultCode::CANCELED:
855 RCLCPP_INFO(logger_,
"Execute request canceled");
858 RCLCPP_INFO(logger_,
"Execute request unknown result code");
863 moveit_msgs::action::ExecuteTrajectory::Goal goal;
864 goal.trajectory = trajectory;
865 goal.controller_names = controllers;
867 auto goal_handle_future = execute_action_client_->async_send_goal(goal, send_goal_opts);
869 return moveit::core::MoveItErrorCode::SUCCESS;
874 std::this_thread::sleep_for(std::chrono::milliseconds(1));
877 if (code != rclcpp_action::ResultCode::SUCCEEDED)
879 RCLCPP_ERROR_STREAM(logger_,
"MoveGroupInterface::execute() failed or timeout reached");
881 return res->error_code;
885 moveit_msgs::msg::RobotTrajectory& msg,
886 const moveit_msgs::msg::Constraints& path_constraints,
bool avoid_collisions,
887 moveit_msgs::msg::MoveItErrorCodes& error_code)
889 auto req = std::make_shared<moveit_msgs::srv::GetCartesianPath::Request>();
890 moveit_msgs::srv::GetCartesianPath::Response::SharedPtr response;
892 req->start_state = considered_start_state_;
893 req->group_name = opt_.group_name;
895 req->header.stamp =
getClock()->now();
896 req->waypoints = waypoints;
897 req->max_step = step;
898 req->path_constraints = path_constraints;
899 req->avoid_collisions = avoid_collisions;
901 req->max_velocity_scaling_factor = max_velocity_scaling_factor_;
902 req->max_acceleration_scaling_factor = max_acceleration_scaling_factor_;
904 auto future_response = cartesian_path_service_->async_send_request(req);
905 if (future_response.valid())
907 response = future_response.get();
908 error_code = response->error_code;
909 if (response->error_code.val == moveit_msgs::msg::MoveItErrorCodes::SUCCESS)
911 msg = response->solution;
912 return response->fraction;
921 error_code.val = error_code.FAILURE;
928 if (trajectory_event_publisher_)
930 std_msgs::msg::String event;
932 trajectory_event_publisher_->publish(event);
936 bool attachObject(
const std::string&
object,
const std::string& link,
const std::vector<std::string>& touch_links)
941 const std::vector<std::string>& links = joint_model_group_->getLinkModelNames();
947 RCLCPP_ERROR(logger_,
"No known link to attach object '%s' to",
object.c_str());
950 moveit_msgs::msg::AttachedCollisionObject aco;
951 aco.object.id = object;
952 aco.link_name.swap(l);
953 if (touch_links.empty())
955 aco.touch_links.push_back(aco.link_name);
959 aco.touch_links = touch_links;
961 aco.object.operation = moveit_msgs::msg::CollisionObject::ADD;
962 attached_object_publisher_->publish(aco);
968 moveit_msgs::msg::AttachedCollisionObject aco;
970 if (!name.empty() && joint_model_group_->hasLinkModel(name))
972 aco.link_name = name;
976 aco.object.id = name;
978 aco.object.operation = moveit_msgs::msg::CollisionObject::REMOVE;
979 if (aco.link_name.empty() && aco.object.id.empty())
982 const std::vector<std::string>& lnames = joint_model_group_->getLinkModelNames();
983 for (
const std::string& lname : lnames)
985 aco.link_name = lname;
986 attached_object_publisher_->publish(aco);
991 attached_object_publisher_->publish(aco);
998 return goal_position_tolerance_;
1003 return goal_orientation_tolerance_;
1008 return goal_joint_tolerance_;
1013 goal_joint_tolerance_ = tolerance;
1018 goal_position_tolerance_ = tolerance;
1023 goal_orientation_tolerance_ = tolerance;
1029 allowed_planning_time_ = seconds;
1034 return allowed_planning_time_;
1039 state = considered_start_state_;
1044 request.group_name = opt_.group_name;
1045 request.num_planning_attempts = num_planning_attempts_;
1046 request.max_velocity_scaling_factor = max_velocity_scaling_factor_;
1047 request.max_acceleration_scaling_factor = max_acceleration_scaling_factor_;
1048 request.allowed_planning_time = allowed_planning_time_;
1049 request.pipeline_id = planning_pipeline_id_;
1050 request.planner_id = planner_id_;
1051 request.workspace_parameters = workspace_parameters_;
1052 request.start_state = considered_start_state_;
1054 if (active_target_ == JOINT)
1056 request.goal_constraints.resize(1);
1060 else if (active_target_ == POSE || active_target_ == POSITION || active_target_ == ORIENTATION)
1063 std::size_t goal_count = 0;
1064 for (
const auto& pose_target : pose_targets_)
1065 goal_count = std::max(goal_count, pose_target.second.size());
1071 request.goal_constraints.resize(goal_count);
1073 for (
const auto& pose_target : pose_targets_)
1075 for (std::size_t i = 0; i < pose_target.second.size(); ++i)
1078 pose_target.first, pose_target.second[i], goal_position_tolerance_, goal_orientation_tolerance_);
1079 if (active_target_ == ORIENTATION)
1080 c.position_constraints.clear();
1081 if (active_target_ == POSITION)
1082 c.orientation_constraints.clear();
1089 RCLCPP_ERROR(logger_,
"Unable to construct MotionPlanRequest representation");
1092 if (path_constraints_)
1094 request.path_constraints = *path_constraints_;
1096 if (trajectory_constraints_)
1097 request.trajectory_constraints = *trajectory_constraints_;
1107 path_constraints_ = std::make_unique<moveit_msgs::msg::Constraints>(constraint);
1112 if (constraints_storage_)
1115 if (constraints_storage_->getConstraints(msg_m, constraint, robot_model_->getName(), opt_.group_name))
1118 std::make_unique<moveit_msgs::msg::Constraints>(
static_cast<moveit_msgs::msg::Constraints
>(*msg_m));
1134 path_constraints_.reset();
1139 trajectory_constraints_ = std::make_unique<moveit_msgs::msg::TrajectoryConstraints>(constraint);
1144 trajectory_constraints_.reset();
1149 while (initializing_constraints_)
1151 std::chrono::duration<double> d(0.01);
1152 rclcpp::sleep_for(std::chrono::duration_cast<std::chrono::nanoseconds>(d), rclcpp::Context::SharedPtr(
nullptr));
1155 std::vector<std::string> c;
1156 if (constraints_storage_)
1157 constraints_storage_->getKnownConstraints(c, robot_model_->getName(), opt_.group_name);
1164 if (path_constraints_)
1166 return *path_constraints_;
1170 return moveit_msgs::msg::Constraints();
1176 if (trajectory_constraints_)
1178 return *trajectory_constraints_;
1182 return moveit_msgs::msg::TrajectoryConstraints();
1188 initializing_constraints_ =
true;
1189 if (constraints_init_thread_)
1190 constraints_init_thread_->join();
1191 constraints_init_thread_ =
1192 std::make_unique<std::thread>([
this, host, port] { initializeConstraintsStorageThread(host, port); });
1195 void setWorkspace(
double minx,
double miny,
double minz,
double maxx,
double maxy,
double maxz)
1197 workspace_parameters_.header.frame_id =
getRobotModel()->getModelFrame();
1198 workspace_parameters_.header.stamp =
getClock()->now();
1199 workspace_parameters_.min_corner.x = minx;
1200 workspace_parameters_.min_corner.y = miny;
1201 workspace_parameters_.min_corner.z = minz;
1202 workspace_parameters_.max_corner.x = maxx;
1203 workspace_parameters_.max_corner.y = maxy;
1204 workspace_parameters_.max_corner.z = maxz;
1209 return node_->get_clock();
1213 void initializeConstraintsStorageThread(
const std::string& host,
unsigned int port)
1219 conn->setParams(host, port);
1220 if (conn->connect())
1222 constraints_storage_ = std::make_unique<moveit_warehouse::ConstraintsStorage>(conn);
1225 catch (std::exception& ex)
1227 RCLCPP_ERROR(logger_,
"%s", ex.what());
1229 initializing_constraints_ =
false;
1233 rclcpp::Node::SharedPtr node_;
1234 rclcpp::Logger logger_;
1235 rclcpp::CallbackGroup::SharedPtr callback_group_;
1236 rclcpp::executors::SingleThreadedExecutor callback_executor_;
1237 std::thread callback_thread_;
1238 std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
1239 moveit::core::RobotModelConstPtr robot_model_;
1240 planning_scene_monitor::CurrentStateMonitorPtr current_state_monitor_;
1242 std::shared_ptr<rclcpp_action::Client<moveit_msgs::action::MoveGroup>> move_action_client_;
1245 std::shared_ptr<rclcpp_action::Client<moveit_msgs::action::ExecuteTrajectory>> execute_action_client_;
1248 moveit_msgs::msg::RobotState considered_start_state_;
1249 moveit_msgs::msg::WorkspaceParameters workspace_parameters_;
1250 double allowed_planning_time_;
1251 std::string planning_pipeline_id_;
1252 std::string planner_id_;
1253 unsigned int num_planning_attempts_;
1254 double max_velocity_scaling_factor_;
1255 double max_acceleration_scaling_factor_;
1256 double goal_joint_tolerance_;
1257 double goal_position_tolerance_;
1258 double goal_orientation_tolerance_;
1260 int32_t look_around_attempts_;
1262 int32_t replan_attempts_;
1263 double replan_delay_;
1266 moveit::core::RobotStatePtr joint_state_target_;
1267 const moveit::core::JointModelGroup* joint_model_group_;
1271 std::map<std::string, std::vector<geometry_msgs::msg::PoseStamped>> pose_targets_;
1274 ActiveTargetType active_target_;
1275 std::unique_ptr<moveit_msgs::msg::Constraints> path_constraints_;
1276 std::unique_ptr<moveit_msgs::msg::TrajectoryConstraints> trajectory_constraints_;
1277 std::string end_effector_link_;
1278 std::string pose_reference_frame_;
1281 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr trajectory_event_publisher_;
1282 rclcpp::Publisher<moveit_msgs::msg::AttachedCollisionObject>::SharedPtr attached_object_publisher_;
1283 rclcpp::Client<moveit_msgs::srv::QueryPlannerInterfaces>::SharedPtr query_service_;
1284 rclcpp::Client<moveit_msgs::srv::GetPlannerParams>::SharedPtr get_params_service_;
1285 rclcpp::Client<moveit_msgs::srv::SetPlannerParams>::SharedPtr set_params_service_;
1286 rclcpp::Client<moveit_msgs::srv::GetCartesianPath>::SharedPtr cartesian_path_service_;
1288 std::unique_ptr<moveit_warehouse::ConstraintsStorage> constraints_storage_;
1289 std::unique_ptr<std::thread> constraints_init_thread_;
1290 bool initializing_constraints_;
1294 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer,
1295 const rclcpp::Duration& wait_for_servers)
1299 throw std::runtime_error(
"ROS does not seem to be running");
1305 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer,
1306 const rclcpp::Duration& wait_for_servers)
1318 : remembered_joint_values_(std::move(other.remembered_joint_values_))
1319 , impl_(other.impl_)
1320 , logger_(std::move(other.logger_))
1322 other.impl_ =
nullptr;
1330 impl_ = other.impl_;
1331 logger_ = other.logger_;
1332 remembered_joint_values_ = std::move(other.remembered_joint_values_);
1333 other.impl_ =
nullptr;
1341 return impl_->getOptions().group_name;
1348 return impl_->getJointModelGroup()->getDefaultStateNames();
1353 return impl_->
getTF();
1358 return impl_->getRobotModel();
1363 return impl_->getInterfaceDescription(desc);
1368 return impl_->getInterfaceDescriptions(desc);
1372 const std::string& group)
const
1374 return impl_->getPlannerParams(planner_id, group);
1378 const std::map<std::string, std::string>& params,
bool replace)
1380 impl_->setPlannerParams(planner_id, group, params, replace);
1385 return impl_->getDefaultPlanningPipelineId();
1390 impl_->setPlanningPipelineId(pipeline_id);
1395 return impl_->getPlanningPipelineId();
1400 return impl_->getDefaultPlannerId(group);
1405 impl_->setPlannerId(planner_id);
1410 return impl_->getPlannerId();
1415 impl_->setNumPlanningAttempts(num_planning_attempts);
1420 impl_->setMaxVelocityScalingFactor(max_velocity_scaling_factor);
1425 return impl_->getMaxVelocityScalingFactor();
1430 impl_->setMaxAccelerationScalingFactor(max_acceleration_scaling_factor);
1435 return impl_->getMaxAccelerationScalingFactor();
1440 return impl_->move(
false);
1445 return impl_->getMoveGroupClient();
1450 return impl_->move(
true);
1454 const std::vector<std::string>& controllers)
1456 return impl_->execute(
plan.trajectory,
false, controllers);
1460 const std::vector<std::string>& controllers)
1462 return impl_->execute(trajectory,
false, controllers);
1467 return impl_->execute(
plan.trajectory,
true, controllers);
1471 const std::vector<std::string>& controllers)
1473 return impl_->execute(trajectory,
true, controllers);
1478 return impl_->plan(
plan);
1482 moveit_msgs::msg::RobotTrajectory& trajectory,
bool avoid_collisions,
1483 moveit_msgs::msg::MoveItErrorCodes* error_code)
1485 moveit_msgs::msg::Constraints path_constraints_tmp;
1486 return computeCartesianPath(waypoints, eef_step, trajectory, moveit_msgs::msg::Constraints(), avoid_collisions,
1491 moveit_msgs::msg::RobotTrajectory& trajectory,
1492 const moveit_msgs::msg::Constraints& path_constraints,
1493 bool avoid_collisions, moveit_msgs::msg::MoveItErrorCodes* error_code)
1497 return impl_->computeCartesianPath(waypoints, eef_step, trajectory, path_constraints, avoid_collisions, *error_code);
1501 moveit_msgs::msg::MoveItErrorCodes err_tmp;
1502 err_tmp.val = moveit_msgs::msg::MoveItErrorCodes::SUCCESS;
1503 moveit_msgs::msg::MoveItErrorCodes& err = error_code ? *error_code : err_tmp;
1504 return impl_->computeCartesianPath(waypoints, eef_step, trajectory, path_constraints, avoid_collisions, err);
1515 impl_->setStartState(start_state);
1520 impl_->setStartState(start_state);
1525 impl_->setStartStateToCurrentState();
1530 impl_->getTargetRobotState().setToRandomPositions();
1531 impl_->setTargetType(JOINT);
1536 return impl_->getJointModelGroup()->getVariableNames();
1541 return impl_->getJointModelGroup()->getLinkModelNames();
1546 std::map<std::string, std::vector<double>>::const_iterator it = remembered_joint_values_.find(name);
1547 std::map<std::string, double> positions;
1549 if (it != remembered_joint_values_.cend())
1551 std::vector<std::string> names = impl_->getJointModelGroup()->getVariableNames();
1552 for (
size_t x = 0; x < names.size(); ++x)
1554 positions[names[x]] = it->second[x];
1559 if (!impl_->getJointModelGroup()->getVariableDefaultPositions(name, positions))
1561 RCLCPP_ERROR(logger_,
"The requested named target '%s' does not exist, returning empty positions.", name.c_str());
1569 std::map<std::string, std::vector<double>>::const_iterator it = remembered_joint_values_.find(name);
1570 if (it != remembered_joint_values_.end())
1576 if (impl_->getTargetRobotState().setToDefaultValues(impl_->getJointModelGroup(), name))
1578 impl_->setTargetType(JOINT);
1581 RCLCPP_ERROR(logger_,
"The requested named target '%s' does not exist", name.c_str());
1588 impl_->getTargetRobotState().copyJointGroupPositions(impl_->getJointModelGroup(), group_variable_values);
1593 const auto n_group_joints = impl_->getJointModelGroup()->getVariableCount();
1594 if (joint_values.size() != n_group_joints)
1596 RCLCPP_DEBUG_STREAM(logger_,
"Provided joint value list has length " << joint_values.size() <<
" but group "
1597 << impl_->getJointModelGroup()->getName()
1598 <<
" has " << n_group_joints <<
" joints");
1601 impl_->setTargetType(JOINT);
1602 impl_->getTargetRobotState().setJointGroupPositions(impl_->getJointModelGroup(), joint_values);
1603 return impl_->getTargetRobotState().satisfiesBounds(impl_->getJointModelGroup(), impl_->getGoalJointTolerance());
1608 const auto& allowed = impl_->getJointModelGroup()->getVariableNames();
1609 for (
const auto& pair : variable_values)
1611 if (std::find(allowed.begin(), allowed.end(), pair.first) == allowed.end())
1613 RCLCPP_ERROR_STREAM(logger_,
"joint variable " << pair.first <<
" is not part of group "
1614 << impl_->getJointModelGroup()->getName());
1619 impl_->setTargetType(JOINT);
1620 impl_->getTargetRobotState().setVariablePositions(variable_values);
1621 return impl_->getTargetRobotState().satisfiesBounds(impl_->getGoalJointTolerance());
1625 const std::vector<double>& variable_values)
1627 if (variable_names.size() != variable_values.size())
1629 RCLCPP_ERROR_STREAM(logger_,
"sizes of name and position arrays do not match");
1632 const auto& allowed = impl_->getJointModelGroup()->getVariableNames();
1633 for (
const auto& variable_name : variable_names)
1635 if (std::find(allowed.begin(), allowed.end(), variable_name) == allowed.end())
1637 RCLCPP_ERROR_STREAM(logger_,
"joint variable " << variable_name <<
" is not part of group "
1638 << impl_->getJointModelGroup()->getName());
1643 impl_->setTargetType(JOINT);
1644 impl_->getTargetRobotState().setVariablePositions(variable_names, variable_values);
1645 return impl_->getTargetRobotState().satisfiesBounds(impl_->getGoalJointTolerance());
1650 impl_->setTargetType(JOINT);
1651 impl_->getTargetRobotState() = rstate;
1652 return impl_->getTargetRobotState().
satisfiesBounds(impl_->getGoalJointTolerance());
1657 std::vector<double> values(1, value);
1663 impl_->setTargetType(JOINT);
1667 impl_->getTargetRobotState().setJointPositions(jm, values);
1668 return impl_->getTargetRobotState().satisfiesBounds(jm, impl_->getGoalJointTolerance());
1671 RCLCPP_ERROR_STREAM(logger_,
1672 "joint " << joint_name <<
" is not part of group " << impl_->getJointModelGroup()->getName());
1682 const std::string& end_effector_link)
1684 return impl_->setJointValueTarget(eef_pose, end_effector_link,
"",
false);
1688 const std::string& end_effector_link)
1690 return impl_->setJointValueTarget(eef_pose.pose, end_effector_link, eef_pose.header.frame_id,
false);
1695 geometry_msgs::msg::Pose msg = tf2::toMsg(eef_pose);
1700 const std::string& end_effector_link)
1702 return impl_->setJointValueTarget(eef_pose, end_effector_link,
"",
true);
1706 const std::string& end_effector_link)
1708 return impl_->setJointValueTarget(eef_pose.pose, end_effector_link, eef_pose.header.frame_id,
true);
1712 const std::string& end_effector_link)
1714 geometry_msgs::msg::Pose msg = tf2::toMsg(eef_pose);
1720 return impl_->getTargetRobotState();
1725 return impl_->getEndEffectorLink();
1730 return impl_->getEndEffector();
1735 if (impl_->getEndEffectorLink().empty() || link_name.empty())
1737 impl_->setEndEffectorLink(link_name);
1738 impl_->setTargetType(POSE);
1752 impl_->clearPoseTarget(end_effector_link);
1757 impl_->clearPoseTargets();
1762 std::vector<geometry_msgs::msg::PoseStamped> pose_msg(1);
1763 pose_msg[0].pose = tf2::toMsg(pose);
1765 pose_msg[0].header.stamp = impl_->getClock()->now();
1771 std::vector<geometry_msgs::msg::PoseStamped> pose_msg(1);
1772 pose_msg[0].pose = target;
1774 pose_msg[0].header.stamp = impl_->getClock()->now();
1779 const std::string& end_effector_link)
1781 std::vector<geometry_msgs::msg::PoseStamped> targets(1, target);
1787 std::vector<geometry_msgs::msg::PoseStamped> pose_out(target.size());
1788 rclcpp::Time tm = impl_->getClock()->now();
1790 for (std::size_t i = 0; i < target.size(); ++i)
1792 pose_out[i].pose = tf2::toMsg(target[i]);
1793 pose_out[i].header.stamp = tm;
1794 pose_out[i].header.frame_id = frame_id;
1800 const std::string& end_effector_link)
1802 std::vector<geometry_msgs::msg::PoseStamped> target_stamped(target.size());
1803 rclcpp::Time tm = impl_->getClock()->now();
1805 for (std::size_t i = 0; i < target.size(); ++i)
1807 target_stamped[i].pose = target[i];
1808 target_stamped[i].header.stamp = tm;
1809 target_stamped[i].header.frame_id = frame_id;
1815 const std::string& end_effector_link)
1819 RCLCPP_ERROR(logger_,
"No pose specified as goal target");
1824 impl_->setTargetType(POSE);
1825 return impl_->setPoseTargets(target, end_effector_link);
1831 return impl_->getPoseTarget(end_effector_link);
1834const std::vector<geometry_msgs::msg::PoseStamped>&
1837 return impl_->getPoseTargets(end_effector_link);
1842inline void transformPose(
const tf2_ros::Buffer& tf_buffer,
const std::string& desired_frame,
1843 geometry_msgs::msg::PoseStamped& target)
1845 if (desired_frame != target.header.frame_id)
1847 geometry_msgs::msg::PoseStamped target_in(target);
1848 tf_buffer.transform(target_in, target, desired_frame);
1850 target.header.stamp = rclcpp::Time(0);
1857 geometry_msgs::msg::PoseStamped target;
1858 if (impl_->hasPoseTarget(end_effector_link))
1861 transformPose(*impl_->getTF(), impl_->getPoseReferenceFrame(), target);
1865 target.pose.orientation.x = 0.0;
1866 target.pose.orientation.y = 0.0;
1867 target.pose.orientation.z = 0.0;
1868 target.pose.orientation.w = 1.0;
1869 target.header.frame_id = impl_->getPoseReferenceFrame();
1872 target.pose.position.x = x;
1873 target.pose.position.y = y;
1874 target.pose.position.z = z;
1876 impl_->setTargetType(POSITION);
1882 geometry_msgs::msg::PoseStamped target;
1883 if (impl_->hasPoseTarget(end_effector_link))
1886 transformPose(*impl_->getTF(), impl_->getPoseReferenceFrame(), target);
1890 target.pose.position.x = 0.0;
1891 target.pose.position.y = 0.0;
1892 target.pose.position.z = 0.0;
1893 target.header.frame_id = impl_->getPoseReferenceFrame();
1897 target.pose.orientation = tf2::toMsg(q);
1899 impl_->setTargetType(ORIENTATION);
1904 const std::string& end_effector_link)
1906 geometry_msgs::msg::PoseStamped target;
1907 if (impl_->hasPoseTarget(end_effector_link))
1910 transformPose(*impl_->getTF(), impl_->getPoseReferenceFrame(), target);
1914 target.pose.position.x = 0.0;
1915 target.pose.position.y = 0.0;
1916 target.pose.position.z = 0.0;
1917 target.header.frame_id = impl_->getPoseReferenceFrame();
1920 target.pose.orientation.x = x;
1921 target.pose.orientation.y = y;
1922 target.pose.orientation.z = z;
1923 target.pose.orientation.w = w;
1925 impl_->setTargetType(ORIENTATION);
1931 impl_->setPoseReferenceFrame(pose_reference_frame);
1936 return impl_->getPoseReferenceFrame();
1941 return impl_->getGoalJointTolerance();
1946 return impl_->getGoalPositionTolerance();
1951 return impl_->getGoalOrientationTolerance();
1963 impl_->setGoalJointTolerance(tolerance);
1968 impl_->setGoalPositionTolerance(tolerance);
1973 impl_->setGoalOrientationTolerance(tolerance);
1983 return impl_->startStateMonitor(wait);
1988 moveit::core::RobotStatePtr current_state;
1989 std::vector<double> values;
1990 if (impl_->getCurrentState(current_state))
1991 current_state->copyJointGroupPositions(
getName(), values);
1997 std::vector<double> r;
1998 impl_->getJointModelGroup()->getVariableRandomPositions(impl_->getTargetRobotState().getRandomNumberGenerator(), r);
2004 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
2005 Eigen::Isometry3d pose;
2009 RCLCPP_ERROR(logger_,
"No end-effector specified");
2013 moveit::core::RobotStatePtr current_state;
2014 if (impl_->getCurrentState(current_state))
2016 current_state->setToRandomPositions(impl_->getJointModelGroup());
2019 pose = current_state->getGlobalLinkTransform(lm);
2022 geometry_msgs::msg::PoseStamped pose_msg;
2023 pose_msg.header.stamp = impl_->getClock()->now();
2024 pose_msg.header.frame_id = impl_->getRobotModel()->getModelFrame();
2025 pose_msg.pose = tf2::toMsg(pose);
2031 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
2032 Eigen::Isometry3d pose;
2036 RCLCPP_ERROR(logger_,
"No end-effector specified");
2040 moveit::core::RobotStatePtr current_state;
2041 if (impl_->getCurrentState(current_state))
2045 pose = current_state->getGlobalLinkTransform(lm);
2048 geometry_msgs::msg::PoseStamped pose_msg;
2049 pose_msg.header.stamp = impl_->getClock()->now();
2050 pose_msg.header.frame_id = impl_->getRobotModel()->getModelFrame();
2051 pose_msg.pose = tf2::toMsg(pose);
2057 std::vector<double> result;
2058 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
2061 RCLCPP_ERROR(logger_,
"No end-effector specified");
2065 moveit::core::RobotStatePtr current_state;
2066 if (impl_->getCurrentState(current_state))
2072 geometry_msgs::msg::TransformStamped tfs = tf2::eigenToTransform(current_state->getGlobalLinkTransform(lm));
2073 double pitch, roll, yaw;
2074 tf2::getEulerYPR<geometry_msgs::msg::Quaternion>(tfs.transform.rotation, yaw, pitch, roll);
2086 return impl_->getJointModelGroup()->getActiveJointModelNames();
2091 return impl_->getJointModelGroup()->getJointModelNames();
2096 return impl_->getJointModelGroup()->getVariableCount();
2101 moveit::core::RobotStatePtr current_state;
2102 impl_->getCurrentState(current_state, wait);
2103 return current_state;
2108 remembered_joint_values_[name] = values;
2113 remembered_joint_values_.erase(name);
2118 impl_->can_look_ = flag;
2119 RCLCPP_DEBUG(logger_,
"Looking around: %s", flag ?
"yes" :
"no");
2126 RCLCPP_ERROR(logger_,
"Tried to set negative number of look-around attempts");
2130 RCLCPP_DEBUG_STREAM(logger_,
"Look around attempts: " << attempts);
2131 impl_->look_around_attempts_ = attempts;
2137 impl_->can_replan_ = flag;
2138 RCLCPP_DEBUG(logger_,
"Replanning: %s", flag ?
"yes" :
"no");
2145 RCLCPP_ERROR(logger_,
"Tried to set negative number of replan attempts");
2149 RCLCPP_DEBUG_STREAM(logger_,
"Replan Attempts: " << attempts);
2150 impl_->replan_attempts_ = attempts;
2158 RCLCPP_ERROR(logger_,
"Tried to set negative replan delay");
2162 RCLCPP_DEBUG_STREAM(logger_,
"Replan Delay: " << delay);
2163 impl_->replan_delay_ = delay;
2169 return impl_->getKnownConstraints();
2174 return impl_->getPathConstraints();
2179 return impl_->setPathConstraints(constraint);
2184 impl_->setPathConstraints(constraint);
2189 impl_->clearPathConstraints();
2194 return impl_->getTrajectoryConstraints();
2199 impl_->setTrajectoryConstraints(constraint);
2204 impl_->clearTrajectoryConstraints();
2209 impl_->initializeConstraintsStorage(host, port);
2214 impl_->setWorkspace(minx, miny, minz, maxx, maxy, maxz);
2220 impl_->setPlanningTime(seconds);
2226 return impl_->getPlanningTime();
2231 return impl_->node_;
2236 return impl_->getRobotModel()->getModelFrame();
2241 return impl_->getRobotModel()->getJointModelGroupNames();
2246 return attachObject(
object, link, std::vector<std::string>());
2250 const std::vector<std::string>& touch_links)
2252 return impl_->attachObject(
object, link, touch_links);
2257 return impl_->detachObject(name);
2262 impl_->constructRobotState(state);
2267 impl_->constructMotionPlanRequest(goal_out);
const std::pair< std::string, std::string > & getEndEffectorParentGroup() const
Get the name of the group this end-effector attaches to (first) and the name of the link in that grou...
A joint from the robot. Models the transform that this joint applies in the kinematic chain....
std::size_t getVariableCount() const
Get the number of variables that describe this joint.
A link from the robot. Contains the constant transform applied to the link and its geometry.
a wrapper around moveit_msgs::MoveItErrorCodes to make it easier to return an error code message from...
Representation of a robot's state. This includes position, velocity, acceleration and effort.
const Eigen::Isometry3d & getFrameTransform(const std::string &frame_id, bool *frame_found=nullptr)
Get the transformation matrix from the model frame (root of model) to the frame identified by frame_i...
bool satisfiesBounds(double margin=0.0) const
bool setFromIK(const JointModelGroup *group, const geometry_msgs::msg::Pose &pose, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions(), const kinematics::KinematicsBase::IKCostFn &cost_function=kinematics::KinematicsBase::IKCostFn())
If the group this state corresponds to is a chain and a solver is available, then the joint values ca...
rclcpp_action::Client< moveit_msgs::action::MoveGroup > & getMoveGroupClient() const
bool startStateMonitor(double wait)
void setPlanningPipelineId(const std::string &pipeline_id)
void setPoseReferenceFrame(const std::string &pose_reference_frame)
double getGoalPositionTolerance() const
std::string getDefaultPlanningPipelineId() const
~MoveGroupInterfaceImpl()
rclcpp::Clock::SharedPtr getClock()
void setEndEffectorLink(const std::string &end_effector)
void constructGoal(moveit_msgs::action::MoveGroup::Goal &goal) const
double getPlanningTime() const
void constructRobotState(moveit_msgs::msg::RobotState &state) const
std::string getDefaultPlannerId(const std::string &group) const
bool setPathConstraints(const std::string &constraint)
void setStartState(const moveit::core::RobotState &start_state)
const std::string & getEndEffector() const
double getGoalJointTolerance() const
void setMaxScalingFactor(double &variable, const double target_value, const char *factor_name, double fallback_value)
void setMaxAccelerationScalingFactor(double value)
void clearPathConstraints()
void setGoalOrientationTolerance(double tolerance)
bool getCurrentState(moveit::core::RobotStatePtr ¤t_state, double wait_seconds=1.0)
const std::string & getPoseReferenceFrame() const
void clearPoseTarget(const std::string &end_effector_link)
bool attachObject(const std::string &object, const std::string &link, const std::vector< std::string > &touch_links)
void setGoalPositionTolerance(double tolerance)
const std::string & getEndEffectorLink() const
std::map< std::string, std::string > getPlannerParams(const std::string &planner_id, const std::string &group="")
void initializeConstraintsStorage(const std::string &host, unsigned int port)
void setPlannerId(const std::string &planner_id)
double getGoalOrientationTolerance() const
moveit_msgs::msg::Constraints getPathConstraints() const
void setTargetType(ActiveTargetType type)
void setPathConstraints(const moveit_msgs::msg::Constraints &constraint)
ActiveTargetType getTargetType() const
double computeCartesianPath(const std::vector< geometry_msgs::msg::Pose > &waypoints, double step, moveit_msgs::msg::RobotTrajectory &msg, const moveit_msgs::msg::Constraints &path_constraints, bool avoid_collisions, moveit_msgs::msg::MoveItErrorCodes &error_code)
void setMaxVelocityScalingFactor(double value)
const moveit::core::RobotState & getTargetRobotState() const
void setNumPlanningAttempts(unsigned int num_planning_attempts)
const std::string & getPlannerId() const
double getMaxVelocityScalingFactor() const
std::vector< std::string > getKnownConstraints() const
void setGoalJointTolerance(double tolerance)
void setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &constraint)
const std::shared_ptr< tf2_ros::Buffer > & getTF() const
moveit::core::MoveItErrorCode move(bool wait)
void constructMotionPlanRequest(moveit_msgs::msg::MotionPlanRequest &request) const
void setPlanningTime(double seconds)
moveit_msgs::msg::TrajectoryConstraints getTrajectoryConstraints() const
const moveit::core::JointModelGroup * getJointModelGroup() const
double getMaxAccelerationScalingFactor() const
MoveGroupInterfaceImpl(const rclcpp::Node::SharedPtr &node, const Options &opt, const std::shared_ptr< tf2_ros::Buffer > &tf_buffer, const rclcpp::Duration &wait_for_servers)
bool setPoseTargets(const std::vector< geometry_msgs::msg::PoseStamped > &poses, const std::string &end_effector_link)
const geometry_msgs::msg::PoseStamped & getPoseTarget(const std::string &end_effector_link) const
void clearTrajectoryConstraints()
moveit::core::MoveItErrorCode execute(const moveit_msgs::msg::RobotTrajectory &trajectory, bool wait, const std::vector< std::string > &controllers=std::vector< std::string >())
bool getInterfaceDescription(moveit_msgs::msg::PlannerInterfaceDescription &desc)
const Options & getOptions() const
void setStartState(const moveit_msgs::msg::RobotState &start_state)
const moveit::core::RobotModelConstPtr & getRobotModel() const
const std::vector< geometry_msgs::msg::PoseStamped > & getPoseTargets(const std::string &end_effector_link) const
bool detachObject(const std::string &name)
bool setJointValueTarget(const geometry_msgs::msg::Pose &eef_pose, const std::string &end_effector_link, const std::string &frame, bool approx)
moveit::core::RobotStatePtr getStartState()
bool hasPoseTarget(const std::string &end_effector_link) const
void setPlannerParams(const std::string &planner_id, const std::string &group, const std::map< std::string, std::string > ¶ms, bool replace=false)
bool getInterfaceDescriptions(std::vector< moveit_msgs::msg::PlannerInterfaceDescription > &desc)
void setStartStateToCurrentState()
moveit::core::RobotState & getTargetRobotState()
moveit::core::MoveItErrorCode plan(Plan &plan)
const std::string & getPlanningPipelineId() const
void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz)
std::vector< double > getRandomJointValues() const
Get random joint values for the joints planned for by this instance (see getJoints()).
double computeCartesianPath(const std::vector< geometry_msgs::msg::Pose > &waypoints, double eef_step, double, moveit_msgs::msg::RobotTrajectory &trajectory, bool avoid_collisions=true, moveit_msgs::msg::MoveItErrorCodes *error_code=nullptr)
Compute a Cartesian path that follows specified waypoints with a step size of at most eef_step meters...
void setMaxVelocityScalingFactor(double max_velocity_scaling_factor)
Set a scaling factor for optionally reducing the maximum joint velocity. Allowed values are in (0,...
const std::string & getEndEffectorLink() const
Get the current end-effector link. This returns the value set by setEndEffectorLink() (or indirectly ...
static const std::string ROBOT_DESCRIPTION
Default ROS parameter name from where to read the robot's URDF. Set to 'robot_description'.
const std::vector< std::string > & getNamedTargets() const
Get the names of the named robot states available as targets, both either remembered states or defaul...
std::map< std::string, std::string > getPlannerParams(const std::string &planner_id, const std::string &group="") const
Get the planner parameters for given group and planner_id.
void stop()
Stop any trajectory execution, if one is active.
MoveGroupInterface(const rclcpp::Node::SharedPtr &node, const Options &opt, const std::shared_ptr< tf2_ros::Buffer > &tf_buffer=std::shared_ptr< tf2_ros::Buffer >(), const rclcpp::Duration &wait_for_servers=rclcpp::Duration::from_seconds(-1))
Construct a MoveGroupInterface instance call using a specified set of options opt.
const std::string & getPlannerId() const
Get the current planner_id.
void setReplanDelay(double delay)
Sleep this duration between replanning attempts (in walltime seconds).
MoveGroupInterface & operator=(const MoveGroupInterface &)=delete
moveit::core::MoveItErrorCode plan(Plan &plan)
Compute a motion plan that takes the group declared in the constructor from the current state to the ...
void setGoalTolerance(double tolerance)
Set the tolerance that is used for reaching the goal. For joint state goals, this will be distance fo...
void setGoalPositionTolerance(double tolerance)
Set the position tolerance that is used for reaching the goal when moving to a pose.
const std::string & getPlanningFrame() const
Get the name of the frame in which the robot is planning.
bool setPoseTargets(const EigenSTL::vector_Isometry3d &end_effector_pose, const std::string &end_effector_link="")
Set goal poses for end_effector_link.
bool setPoseTarget(const Eigen::Isometry3d &end_effector_pose, const std::string &end_effector_link="")
Set the goal pose of the end-effector end_effector_link.
moveit::core::MoveItErrorCode asyncMove()
Plan and execute a trajectory that takes the group of joints declared in the constructor to the speci...
void setPlanningPipelineId(const std::string &pipeline_id)
Specify a planning pipeline to be used for further planning.
double getGoalJointTolerance() const
Get the tolerance that is used for reaching a joint goal. This is distance for each joint in configur...
bool setEndEffectorLink(const std::string &end_effector_link)
Specify the parent link of the end-effector. This end_effector_link will be used in calls to pose tar...
void setStartStateToCurrentState()
Set the starting state for planning to be that reported by the robot's joint state publication.
bool getInterfaceDescriptions(std::vector< moveit_msgs::msg::PlannerInterfaceDescription > &desc) const
Get the descriptions of all planning plugins loaded by the action server.
void setMaxAccelerationScalingFactor(double max_acceleration_scaling_factor)
Set a scaling factor for optionally reducing the maximum joint acceleration. Allowed values are in (0...
bool setPositionTarget(double x, double y, double z, const std::string &end_effector_link="")
Set the goal position of the end-effector end_effector_link to be (x, y, z).
const std::string & getEndEffector() const
Get the current end-effector name. This returns the value set by setEndEffector() (or indirectly by s...
void clearPathConstraints()
Specify that no path constraints are to be used. This removes any path constraints set in previous ca...
bool attachObject(const std::string &object, const std::string &link="")
Given the name of an object in the planning scene, make the object attached to a link of the robot....
std::string getDefaultPlanningPipelineId() const
moveit_msgs::msg::Constraints getPathConstraints() const
Get the actual set of constraints in use with this MoveGroupInterface.
void setNumPlanningAttempts(unsigned int num_planning_attempts)
Set the number of times the motion plan is to be computed from scratch before the shortest solution i...
rclcpp_action::Client< moveit_msgs::action::MoveGroup > & getMoveGroupClient() const
Get the move_group action client used by the MoveGroupInterface. The client can be used for querying ...
std::vector< double > getCurrentJointValues() const
Get the current joint values for the joints planned for by this instance (see getJoints()).
bool setNamedTarget(const std::string &name)
Set the current joint values to be ones previously remembered by rememberJointValues() or,...
const std::vector< std::string > & getJointNames() const
Get vector of names of joints available in move group.
moveit::core::MoveItErrorCode move()
Plan and execute a trajectory that takes the group of joints declared in the constructor to the speci...
void setReplanAttempts(int32_t attempts)
Maximum number of replanning attempts.
void allowReplanning(bool flag)
Specify whether the robot is allowed to replan if it detects changes in the environment.
moveit::core::RobotModelConstPtr getRobotModel() const
Get the RobotModel object.
moveit::core::MoveItErrorCode execute(const Plan &plan, const std::vector< std::string > &controllers=std::vector< std::string >())
Given a plan, execute it while waiting for completion.
void constructMotionPlanRequest(moveit_msgs::msg::MotionPlanRequest &request)
Build the MotionPlanRequest that would be sent to the move_group action with plan() or move() and sto...
bool setOrientationTarget(double x, double y, double z, double w, const std::string &end_effector_link="")
Set the goal orientation of the end-effector end_effector_link to be the quaternion (x,...
bool setJointValueTarget(const std::vector< double > &group_variable_values)
Set the JointValueTarget and use it for future planning requests.
void clearTrajectoryConstraints()
const rclcpp::Node::SharedPtr & getNode() const
Get the ROS node handle of this instance operates on.
bool setRPYTarget(double roll, double pitch, double yaw, const std::string &end_effector_link="")
Set the goal orientation of the end-effector end_effector_link to be (roll,pitch,yaw) radians.
void setGoalOrientationTolerance(double tolerance)
Set the orientation tolerance that is used for reaching the goal when moving to a pose.
void clearPoseTarget(const std::string &end_effector_link="")
Forget pose(s) specified for end_effector_link.
const geometry_msgs::msg::PoseStamped & getPoseTarget(const std::string &end_effector_link="") const
void setGoalJointTolerance(double tolerance)
Set the joint tolerance (for each joint) that is used for reaching the goal when moving to a joint va...
std::string getDefaultPlannerId(const std::string &group="") const
Get the default planner of the current planning pipeline for the given group (or the pipeline's defau...
void setRandomTarget()
Set the joint state goal to a random joint configuration.
moveit::core::RobotStatePtr getCurrentState(double wait=1) const
Get the current state of the robot within the duration specified by wait.
void getJointValueTarget(std::vector< double > &group_variable_values) const
Get the current joint state goal in a form compatible to setJointValueTarget().
const std::vector< std::string > & getActiveJoints() const
Get only the active (actuated) joints this instance operates on.
void rememberJointValues(const std::string &name)
Remember the current joint values (of the robot being monitored) under name. These can be used by set...
void setLookAroundAttempts(int32_t attempts)
How often is the system allowed to move the camera to update environment model when looking.
bool getInterfaceDescription(moveit_msgs::msg::PlannerInterfaceDescription &desc) const
Get the description of the default planning plugin loaded by the action server.
const std::string & getName() const
Get the name of the group this instance operates on.
moveit::core::MoveItErrorCode asyncExecute(const Plan &plan, const std::vector< std::string > &controllers=std::vector< std::string >())
Given a plan, execute it without waiting for completion.
const std::vector< std::string > & getJoints() const
Get all the joints this instance operates on (including fixed joints).
bool detachObject(const std::string &name="")
Detach an object. name specifies the name of the object attached to this group, or the name of the li...
void setPoseReferenceFrame(const std::string &pose_reference_frame)
Specify which reference frame to assume for poses specified without a reference frame.
const std::shared_ptr< tf2_ros::Buffer > & getTF() const
Get the tf2_ros::Buffer.
const std::vector< geometry_msgs::msg::PoseStamped > & getPoseTargets(const std::string &end_effector_link="") const
double getMaxVelocityScalingFactor() const
Get the max velocity scaling factor set by setMaxVelocityScalingFactor().
moveit_msgs::msg::TrajectoryConstraints getTrajectoryConstraints() const
const std::vector< std::string > & getLinkNames() const
Get vector of names of links available in move group.
double getMaxAccelerationScalingFactor() const
Get the max acceleration scaling factor set by setMaxAccelerationScalingFactor().
void setStartState(const moveit_msgs::msg::RobotState &start_state)
If a different start state should be considered instead of the current state of the robot,...
bool setPathConstraints(const std::string &constraint)
Specify a set of path constraints to use. The constraints are looked up by name from the Mongo databa...
void clearPoseTargets()
Forget any poses specified for all end-effectors.
void setPlannerId(const std::string &planner_id)
Specify a planner to be used for further planning.
bool setEndEffector(const std::string &eef_name)
Specify the name of the end-effector to use. This is equivalent to setting the EndEffectorLink to the...
const std::string & getPoseReferenceFrame() const
Get the reference frame set by setPoseReferenceFrame(). By default this is the reference frame of the...
const std::string & getPlanningPipelineId() const
Get the current planning_pipeline_id.
void setConstraintsDatabase(const std::string &host, unsigned int port)
Specify where the database server that holds known constraints resides.
std::vector< double > getCurrentRPY(const std::string &end_effector_link="") const
Get the roll-pitch-yaw (XYZ) for the end-effector end_effector_link. If end_effector_link is empty (t...
void forgetJointValues(const std::string &name)
Forget the joint values remembered under name.
std::vector< std::string > getKnownConstraints() const
Get the names of the known constraints as read from the Mongo database, if a connection was achieved.
void setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &constraint)
const moveit::core::RobotState & getTargetRobotState() const
geometry_msgs::msg::PoseStamped getRandomPose(const std::string &end_effector_link="") const
Get a random reachable pose for the end-effector end_effector_link. If end_effector_link is empty (th...
double getGoalOrientationTolerance() const
Get the tolerance that is used for reaching an orientation goal. This is the tolerance for roll,...
void allowLooking(bool flag)
Specify whether the robot is allowed to look around before moving if it determines it should (default...
std::map< std::string, double > getNamedTargetValues(const std::string &name) const
Get the joint angles for targets specified by name.
geometry_msgs::msg::PoseStamped getCurrentPose(const std::string &end_effector_link="") const
Get the pose for the end-effector end_effector_link. If end_effector_link is empty (the default value...
bool startStateMonitor(double wait=1.0)
When reasoning about the current state of a robot, a CurrentStateMonitor instance is automatically co...
unsigned int getVariableCount() const
Get the number of variables used to describe the state of this group. This is larger or equal to the ...
double getGoalPositionTolerance() const
Get the tolerance that is used for reaching a position goal. This is be the radius of a sphere where ...
double getPlanningTime() const
Get the number of seconds set by setPlanningTime().
void setPlanningTime(double seconds)
Specify the maximum amount of time to use when planning.
bool setApproximateJointValueTarget(const geometry_msgs::msg::Pose &eef_pose, const std::string &end_effector_link="")
Set the joint state goal for a particular joint by computing IK.
void constructRobotState(moveit_msgs::msg::RobotState &state)
Build a RobotState message for use with plan() or computeCartesianPath() If the move_group has a cust...
void setPlannerParams(const std::string &planner_id, const std::string &group, const std::map< std::string, std::string > ¶ms, bool bReplace=false)
Set the planner parameters for given group and planner_id.
void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz)
Specify the workspace bounding box. The box is specified in the planning frame (i....
const std::vector< std::string > & getJointModelGroupNames() const
Get the available planning group names.
static const std::string DEFAULT_ATTACHED_COLLISION_OBJECT_TOPIC
The name of the topic used by default for attached collision objects.
static const std::string EXECUTION_EVENT_TOPIC
moveit_msgs::msg::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....
moveit_msgs::msg::Constraints mergeConstraints(const moveit_msgs::msg::Constraints &first, const moveit_msgs::msg::Constraints &second)
Merge two sets of constraints into one.
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.
std::function< bool(RobotState *robot_state, const JointModelGroup *joint_group, const double *joint_group_variable_values)> GroupStateValidityCallbackFn
Signature for functions that can verify that if the group joint_group in robot_state is set to joint_...
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.
moveit::core::RobotModelConstPtr getSharedRobotModel(const rclcpp::Node::SharedPtr &node, const std::string &robot_description)
std::shared_ptr< tf2_ros::Buffer > getSharedTF()
planning_scene_monitor::CurrentStateMonitorPtr getSharedStateMonitor(const rclcpp::Node::SharedPtr &node, const moveit::core::RobotModelConstPtr &robot_model, const std::shared_ptr< tf2_ros::Buffer > &tf_buffer)
getSharedStateMonitor
warehouse_ros::DatabaseConnection::Ptr loadDatabase(const rclcpp::Node::SharedPtr &node)
Load a database connection.
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::Constraints >::ConstPtr ConstraintsWithMetadata
Main namespace for MoveIt.
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
std::string append(const std::string &left, const std::string &right)
A set of options for the kinematics solver.
bool return_approximate_solution
Specification of options to use when constructing the MoveGroupInterface class.
std::string robot_description
The robot description parameter name (if different from default).
moveit::core::RobotModelConstPtr robot_model
Optionally, an instance of the RobotModel to use can be also specified.
std::string group_name
The group to construct the class instance for.
The representation of a motion plan (as ROS messages).