42 #include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
53 #include <moveit_msgs/action/execute_trajectory.hpp>
54 #include <moveit_msgs/srv/query_planner_interfaces.hpp>
55 #include <moveit_msgs/srv/get_cartesian_path.hpp>
56 #include <moveit_msgs/srv/grasp_planning.hpp>
57 #include <moveit_msgs/srv/get_planner_params.hpp>
58 #include <moveit_msgs/srv/set_planner_params.hpp>
61 #include <std_msgs/msg/string.hpp>
62 #include <geometry_msgs/msg/transform_stamped.hpp>
63 #include <tf2/utils.h>
64 #include <tf2_eigen/tf2_eigen.hpp>
65 #include <tf2_ros/transform_listener.h>
75 const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"move_group_interface");
94 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer,
const rclcpp::Duration& wait_for_servers)
95 : opt_(
opt), node_(node), tf_buffer_(tf_buffer)
99 callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive,
101 callback_executor_.add_callback_group(callback_group_, node->get_node_base_interface());
102 callback_thread_ = std::thread([
this]() { callback_executor_.spin(); });
107 std::string error =
"Unable to construct robot model. Please make sure all needed information is on the "
109 RCLCPP_FATAL_STREAM(
LOGGER, error);
110 throw std::runtime_error(error);
115 std::string error =
"Group '" +
opt.group_name_ +
"' was not found.";
116 RCLCPP_FATAL_STREAM(
LOGGER, error);
117 throw std::runtime_error(error);
122 joint_state_target_ = std::make_shared<moveit::core::RobotState>(
getRobotModel());
123 joint_state_target_->setToDefaultValues();
124 active_target_ =
JOINT;
126 look_around_attempts_ = 0;
129 replan_attempts_ = 1;
130 goal_joint_tolerance_ = 1e-4;
131 goal_position_tolerance_ = 1e-4;
132 goal_orientation_tolerance_ = 1e-3;
133 allowed_planning_time_ = 5.0;
134 num_planning_attempts_ = 1;
135 node_->get_parameter_or<
double>(
"robot_description_planning.default_velocity_scaling_factor",
136 max_velocity_scaling_factor_, 0.1);
137 node_->get_parameter_or<
double>(
"robot_description_planning.default_acceleration_scaling_factor",
138 max_acceleration_scaling_factor_, 0.1);
139 initializing_constraints_ =
false;
141 if (joint_model_group_->
isChain())
145 trajectory_event_publisher_ = node_->create_publisher<std_msgs::msg::String>(
149 attached_object_publisher_ = node_->create_publisher<moveit_msgs::msg::AttachedCollisionObject>(
156 move_action_client_ = rclcpp_action::create_client<moveit_msgs::action::MoveGroup>(
158 move_action_client_->wait_for_action_server(wait_for_servers.to_chrono<std::chrono::duration<double>>());
159 execute_action_client_ = rclcpp_action::create_client<moveit_msgs::action::ExecuteTrajectory>(
161 execute_action_client_->wait_for_action_server(wait_for_servers.to_chrono<std::chrono::duration<double>>());
163 query_service_ = node_->create_client<moveit_msgs::srv::QueryPlannerInterfaces>(
165 rmw_qos_profile_services_default, callback_group_);
166 get_params_service_ = node_->create_client<moveit_msgs::srv::GetPlannerParams>(
168 rmw_qos_profile_services_default, callback_group_);
169 set_params_service_ = node_->create_client<moveit_msgs::srv::SetPlannerParams>(
171 rmw_qos_profile_services_default, callback_group_);
173 cartesian_path_service_ = node_->create_client<moveit_msgs::srv::GetCartesianPath>(
175 rmw_qos_profile_services_default, callback_group_);
179 RCLCPP_INFO_STREAM(
LOGGER,
"Ready to take commands for planning group " <<
opt.group_name_ <<
".");
184 if (constraints_init_thread_)
185 constraints_init_thread_->join();
187 if (callback_executor_.is_spinning())
188 callback_executor_.cancel();
190 if (callback_thread_.joinable())
191 callback_thread_.join();
194 const std::shared_ptr<tf2_ros::Buffer>&
getTF()
const
211 return joint_model_group_;
216 return *move_action_client_;
221 auto req = std::make_shared<moveit_msgs::srv::QueryPlannerInterfaces::Request>();
222 auto future_response = query_service_->async_send_request(req);
224 if (future_response.valid())
226 const auto& response = future_response.get();
227 if (!response->planner_interfaces.empty())
229 desc = response->planner_interfaces.front();
238 auto req = std::make_shared<moveit_msgs::srv::QueryPlannerInterfaces::Request>();
239 auto future_response = query_service_->async_send_request(req);
240 if (future_response.valid())
242 const auto& response = future_response.get();
243 if (!response->planner_interfaces.empty())
245 desc = response->planner_interfaces;
254 auto req = std::make_shared<moveit_msgs::srv::GetPlannerParams::Request>();
255 moveit_msgs::srv::GetPlannerParams::Response::SharedPtr response;
256 req->planner_config = planner_id;
258 std::map<std::string, std::string> result;
260 auto future_response = get_params_service_->async_send_request(req);
261 if (future_response.valid())
263 response = future_response.get();
264 for (
unsigned int i = 0, end = response->params.keys.size(); i < end; ++i)
265 result[response->params.keys[i]] = response->params.values[i];
271 const std::map<std::string, std::string>& params,
bool replace =
false)
273 auto req = std::make_shared<moveit_msgs::srv::SetPlannerParams::Request>();
274 req->planner_config = planner_id;
276 req->replace = replace;
277 for (
const std::pair<const std::string, std::string>& param : params)
279 req->params.keys.push_back(param.first);
280 req->params.values.push_back(param.second);
282 set_params_service_->async_send_request(req);
287 std::string default_planning_pipeline;
288 node_->get_parameter(
"move_group.default_planning_pipeline", default_planning_pipeline);
289 return default_planning_pipeline;
294 if (pipeline_id != planning_pipeline_id_)
296 planning_pipeline_id_ = pipeline_id;
305 return planning_pipeline_id_;
312 if (!planning_pipeline_id_.empty())
313 pipeline_id = planning_pipeline_id_;
315 std::stringstream param_name;
316 param_name <<
"move_group";
317 if (!pipeline_id.empty())
318 param_name <<
"/planning_pipelines/" << pipeline_id;
320 param_name <<
"." <<
group;
321 param_name <<
".default_planner_config";
323 std::string default_planner_config;
324 node_->get_parameter(param_name.str(), default_planner_config);
325 return default_planner_config;
330 planner_id_ = planner_id;
340 num_planning_attempts_ = num_planning_attempts;
350 setMaxScalingFactor(max_acceleration_scaling_factor_, value,
"acceleration_scaling_factor", 0.1);
353 void setMaxScalingFactor(
double& variable,
const double target_value,
const char* factor_name,
double fallback_value)
355 if (target_value > 1.0)
357 RCLCPP_WARN(rclcpp::get_logger(
"move_group_interface"),
"Limiting max_%s (%.2f) to 1.0.", factor_name,
361 else if (target_value <= 0.0)
363 node_->get_parameter_or<
double>(std::string(
"robot_description_planning.default_") + factor_name, variable,
365 if (target_value < 0.0)
367 RCLCPP_WARN(rclcpp::get_logger(
"move_group_interface"),
"max_%s < 0.0! Setting to default: %.2f.", factor_name,
373 variable = target_value;
379 return *joint_state_target_;
384 return *joint_state_target_;
389 considered_start_state_ = std::make_shared<moveit::core::RobotState>(start_state);
394 considered_start_state_.reset();
399 if (considered_start_state_)
400 return considered_start_state_;
403 moveit::core::RobotStatePtr s;
410 const std::string& frame,
bool approx)
412 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
445 tf2::fromMsg(eef_pose,
p);
451 RCLCPP_ERROR(
LOGGER,
"Unable to transform from frame '%s' to frame '%s'", frame.c_str(),
463 end_effector_link_ = end_effector;
468 pose_targets_.erase(end_effector_link);
473 pose_targets_.clear();
478 return end_effector_link_;
483 if (!end_effector_link_.empty())
485 const std::vector<std::string>& possible_eefs =
487 for (
const std::string& possible_eef : possible_eefs)
491 static std::string empty;
495 bool setPoseTargets(
const std::vector<geometry_msgs::msg::PoseStamped>& poses,
const std::string& end_effector_link)
497 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
500 RCLCPP_ERROR(
LOGGER,
"No end-effector to set the pose for");
505 pose_targets_[eef] = poses;
507 std::vector<geometry_msgs::msg::PoseStamped>& stored_poses = pose_targets_[eef];
508 for (geometry_msgs::msg::PoseStamped& stored_pose : stored_poses)
509 stored_pose.header.stamp = rclcpp::Time(0);
516 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
517 return pose_targets_.find(eef) != pose_targets_.end();
520 const geometry_msgs::msg::PoseStamped&
getPoseTarget(
const std::string& end_effector_link)
const
522 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
525 std::map<std::string, std::vector<geometry_msgs::msg::PoseStamped>>::const_iterator jt = pose_targets_.find(eef);
526 if (jt != pose_targets_.end())
527 if (!jt->second.empty())
528 return jt->second.at(0);
531 static const geometry_msgs::msg::PoseStamped UNKNOWN;
532 RCLCPP_ERROR(
LOGGER,
"Pose for end-effector '%s' not known.", eef.c_str());
536 const std::vector<geometry_msgs::msg::PoseStamped>&
getPoseTargets(
const std::string& end_effector_link)
const
538 const std::string& eef = end_effector_link.empty() ? end_effector_link_ : end_effector_link;
540 std::map<std::string, std::vector<geometry_msgs::msg::PoseStamped>>::const_iterator jt = pose_targets_.find(eef);
541 if (jt != pose_targets_.end())
542 if (!jt->second.empty())
546 static const std::vector<geometry_msgs::msg::PoseStamped> EMPTY;
547 RCLCPP_ERROR(
LOGGER,
"Poses for end-effector '%s' are not known.", eef.c_str());
553 pose_reference_frame_ = pose_reference_frame;
558 support_surface_ = support_surface;
563 return pose_reference_frame_;
568 active_target_ =
type;
573 return active_target_;
578 if (!current_state_monitor_)
580 RCLCPP_ERROR(
LOGGER,
"Unable to monitor current robot state");
585 if (!current_state_monitor_->isActive())
586 current_state_monitor_->startStateMonitor();
588 current_state_monitor_->waitForCompleteState(opt_.
group_name_, wait);
592 bool getCurrentState(moveit::core::RobotStatePtr& current_state,
double wait_seconds = 1.0)
594 if (!current_state_monitor_)
596 RCLCPP_ERROR(
LOGGER,
"Unable to get current robot state");
601 if (!current_state_monitor_->isActive())
602 current_state_monitor_->startStateMonitor();
604 if (!current_state_monitor_->waitForCurrentState(node_->now(), wait_seconds))
606 RCLCPP_ERROR(
LOGGER,
"Failed to fetch current robot state");
610 current_state = current_state_monitor_->getCurrentState();
738 if (!move_action_client_ || !move_action_client_->action_server_is_ready())
740 RCLCPP_INFO_STREAM(
LOGGER,
"MoveGroup action client/server not ready");
741 return moveit::core::MoveItErrorCode::FAILURE;
743 RCLCPP_INFO_STREAM(
LOGGER,
"MoveGroup action client/server ready");
745 moveit_msgs::action::MoveGroup::Goal goal;
747 goal.planning_options.plan_only =
true;
748 goal.planning_options.look_around =
false;
749 goal.planning_options.replan =
false;
750 goal.planning_options.planning_scene_diff.is_diff =
true;
751 goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
754 rclcpp_action::ResultCode code = rclcpp_action::ResultCode::UNKNOWN;
755 std::shared_ptr<moveit_msgs::action::MoveGroup::Result> res;
756 auto send_goal_opts = rclcpp_action::Client<moveit_msgs::action::MoveGroup>::SendGoalOptions();
758 send_goal_opts.goal_response_callback =
759 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::SharedPtr& goal_handle) {
763 RCLCPP_INFO(
LOGGER,
"Planning request rejected");
766 RCLCPP_INFO(
LOGGER,
"Planning request accepted");
768 send_goal_opts.result_callback =
769 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::WrappedResult& result) {
776 case rclcpp_action::ResultCode::SUCCEEDED:
777 RCLCPP_INFO(
LOGGER,
"Planning request complete!");
779 case rclcpp_action::ResultCode::ABORTED:
780 RCLCPP_INFO(
LOGGER,
"Planning request aborted");
782 case rclcpp_action::ResultCode::CANCELED:
783 RCLCPP_INFO(
LOGGER,
"Planning request canceled");
786 RCLCPP_INFO(
LOGGER,
"Planning request unknown result code");
791 auto goal_handle_future = move_action_client_->async_send_goal(goal, send_goal_opts);
796 std::this_thread::sleep_for(std::chrono::milliseconds(1));
799 if (code != rclcpp_action::ResultCode::SUCCEEDED)
801 RCLCPP_ERROR_STREAM(
LOGGER,
"MoveGroupInterface::plan() failed or timeout reached");
802 return res->error_code;
805 plan.trajectory_ = res->planned_trajectory;
806 plan.start_state_ = res->trajectory_start;
807 plan.planning_time_ = res->planning_time;
808 RCLCPP_INFO(
LOGGER,
"time taken to generate plan: %g seconds",
plan.planning_time_);
810 return res->error_code;
815 if (!move_action_client_ || !move_action_client_->action_server_is_ready())
817 RCLCPP_INFO_STREAM(
LOGGER,
"MoveGroup action client/server not ready");
818 return moveit::core::MoveItErrorCode::FAILURE;
821 moveit_msgs::action::MoveGroup::Goal goal;
823 goal.planning_options.plan_only =
false;
824 goal.planning_options.look_around = can_look_;
825 goal.planning_options.replan = can_replan_;
826 goal.planning_options.replan_delay = replan_delay_;
827 goal.planning_options.planning_scene_diff.is_diff =
true;
828 goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
831 rclcpp_action::ResultCode code = rclcpp_action::ResultCode::UNKNOWN;
832 std::shared_ptr<moveit_msgs::action::MoveGroup_Result> res;
833 auto send_goal_opts = rclcpp_action::Client<moveit_msgs::action::MoveGroup>::SendGoalOptions();
835 send_goal_opts.goal_response_callback =
836 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::SharedPtr& goal_handle) {
840 RCLCPP_INFO(
LOGGER,
"Plan and Execute request rejected");
843 RCLCPP_INFO(
LOGGER,
"Plan and Execute request accepted");
845 send_goal_opts.result_callback =
846 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::MoveGroup>::WrappedResult& result) {
853 case rclcpp_action::ResultCode::SUCCEEDED:
854 RCLCPP_INFO(
LOGGER,
"Plan and Execute request complete!");
856 case rclcpp_action::ResultCode::ABORTED:
857 RCLCPP_INFO(
LOGGER,
"Plan and Execute request aborted");
859 case rclcpp_action::ResultCode::CANCELED:
860 RCLCPP_INFO(
LOGGER,
"Plan and Execute request canceled");
863 RCLCPP_INFO(
LOGGER,
"Plan and Execute request unknown result code");
867 auto goal_handle_future = move_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::move() failed or timeout reached");
881 return res->error_code;
886 if (!execute_action_client_ || !execute_action_client_->action_server_is_ready())
888 RCLCPP_INFO_STREAM(
LOGGER,
"execute_action_client_ client/server not ready");
889 return moveit::core::MoveItErrorCode::FAILURE;
893 rclcpp_action::ResultCode code = rclcpp_action::ResultCode::UNKNOWN;
894 std::shared_ptr<moveit_msgs::action::ExecuteTrajectory_Result> res;
895 auto send_goal_opts = rclcpp_action::Client<moveit_msgs::action::ExecuteTrajectory>::SendGoalOptions();
897 send_goal_opts.goal_response_callback =
898 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::ExecuteTrajectory>::SharedPtr& goal_handle) {
902 RCLCPP_INFO(
LOGGER,
"Execute request rejected");
905 RCLCPP_INFO(
LOGGER,
"Execute request accepted");
907 send_goal_opts.result_callback =
908 [&](
const rclcpp_action::ClientGoalHandle<moveit_msgs::action::ExecuteTrajectory>::WrappedResult& result) {
915 case rclcpp_action::ResultCode::SUCCEEDED:
916 RCLCPP_INFO(
LOGGER,
"Execute request success!");
918 case rclcpp_action::ResultCode::ABORTED:
919 RCLCPP_INFO(
LOGGER,
"Execute request aborted");
921 case rclcpp_action::ResultCode::CANCELED:
922 RCLCPP_INFO(
LOGGER,
"Execute request canceled");
925 RCLCPP_INFO(
LOGGER,
"Execute request unknown result code");
930 moveit_msgs::action::ExecuteTrajectory::Goal goal;
931 goal.trajectory = trajectory;
933 auto goal_handle_future = execute_action_client_->async_send_goal(goal, send_goal_opts);
935 return moveit::core::MoveItErrorCode::SUCCESS;
940 std::this_thread::sleep_for(std::chrono::milliseconds(1));
943 if (code != rclcpp_action::ResultCode::SUCCEEDED)
945 RCLCPP_ERROR_STREAM(
LOGGER,
"MoveGroupInterface::execute() failed or timeout reached");
947 return res->error_code;
951 double jump_threshold, moveit_msgs::msg::RobotTrajectory& msg,
952 const moveit_msgs::msg::Constraints&
path_constraints,
bool avoid_collisions,
953 moveit_msgs::msg::MoveItErrorCodes& error_code)
955 auto req = std::make_shared<moveit_msgs::srv::GetCartesianPath::Request>();
956 moveit_msgs::srv::GetCartesianPath::Response::SharedPtr response;
958 if (considered_start_state_)
961 req->start_state.is_diff =
true;
965 req->header.stamp =
getClock()->now();
967 req->max_step = step;
968 req->jump_threshold = jump_threshold;
970 req->avoid_collisions = avoid_collisions;
973 auto future_response = cartesian_path_service_->async_send_request(req);
974 if (future_response.valid())
976 response = future_response.get();
977 error_code = response->error_code;
978 if (response->error_code.val == moveit_msgs::msg::MoveItErrorCodes::SUCCESS)
980 msg = response->solution;
981 return response->fraction;
988 error_code.val = error_code.FAILURE;
995 if (trajectory_event_publisher_)
997 std_msgs::msg::String event;
999 trajectory_event_publisher_->publish(event);
1003 bool attachObject(
const std::string&
object,
const std::string& link,
const std::vector<std::string>& touch_links)
1008 const std::vector<std::string>& links = joint_model_group_->
getLinkModelNames();
1014 RCLCPP_ERROR(
LOGGER,
"No known link to attach object '%s' to",
object.c_str());
1017 moveit_msgs::msg::AttachedCollisionObject aco;
1018 aco.object.id = object;
1019 aco.link_name.swap(l);
1020 if (touch_links.empty())
1021 aco.touch_links.push_back(aco.link_name);
1023 aco.touch_links = touch_links;
1024 aco.object.operation = moveit_msgs::msg::CollisionObject::ADD;
1025 attached_object_publisher_->publish(aco);
1031 moveit_msgs::msg::AttachedCollisionObject aco;
1034 aco.link_name =
name;
1036 aco.object.id =
name;
1037 aco.object.operation = moveit_msgs::msg::CollisionObject::REMOVE;
1038 if (aco.link_name.empty() && aco.object.id.empty())
1041 const std::vector<std::string>& lnames = joint_model_group_->
getLinkModelNames();
1042 for (
const std::string& lname : lnames)
1044 aco.link_name = lname;
1045 attached_object_publisher_->publish(aco);
1050 attached_object_publisher_->publish(aco);
1057 return goal_position_tolerance_;
1062 return goal_orientation_tolerance_;
1067 return goal_joint_tolerance_;
1072 goal_joint_tolerance_ = tolerance;
1077 goal_position_tolerance_ = tolerance;
1082 goal_orientation_tolerance_ = tolerance;
1088 allowed_planning_time_ = seconds;
1093 return allowed_planning_time_;
1099 request.num_planning_attempts = num_planning_attempts_;
1100 request.max_velocity_scaling_factor = max_velocity_scaling_factor_;
1101 request.max_acceleration_scaling_factor = max_acceleration_scaling_factor_;
1102 request.allowed_planning_time = allowed_planning_time_;
1103 request.pipeline_id = planning_pipeline_id_;
1104 request.planner_id = planner_id_;
1105 request.workspace_parameters = workspace_parameters_;
1107 if (considered_start_state_)
1110 request.start_state.is_diff =
true;
1112 if (active_target_ ==
JOINT)
1114 request.goal_constraints.resize(1);
1118 else if (active_target_ == POSE || active_target_ ==
POSITION || active_target_ ==
ORIENTATION)
1121 std::size_t goal_count = 0;
1122 for (
const auto& pose_target : pose_targets_)
1123 goal_count = std::max(goal_count, pose_target.second.size());
1129 request.goal_constraints.resize(goal_count);
1131 for (
const auto& pose_target : pose_targets_)
1133 for (std::size_t i = 0; i < pose_target.second.size(); ++i)
1136 pose_target.first, pose_target.second[i], goal_position_tolerance_, goal_orientation_tolerance_);
1138 c.position_constraints.clear();
1140 c.orientation_constraints.clear();
1146 RCLCPP_ERROR(
LOGGER,
"Unable to construct MotionPlanRequest representation");
1148 if (path_constraints_)
1149 request.path_constraints = *path_constraints_;
1150 if (trajectory_constraints_)
1151 request.trajectory_constraints = *trajectory_constraints_;
1216 path_constraints_ = std::make_unique<moveit_msgs::msg::Constraints>(constraint);
1221 if (constraints_storage_)
1224 if (constraints_storage_->getConstraints(msg_m, constraint, robot_model_->getName(), opt_.
group_name_))
1227 std::make_unique<moveit_msgs::msg::Constraints>(
static_cast<moveit_msgs::msg::Constraints
>(*msg_m));
1239 path_constraints_.reset();
1244 trajectory_constraints_ = std::make_unique<moveit_msgs::msg::TrajectoryConstraints>(constraint);
1249 trajectory_constraints_.reset();
1254 while (initializing_constraints_)
1256 std::chrono::duration<double>
d(0.01);
1257 rclcpp::sleep_for(std::chrono::duration_cast<std::chrono::nanoseconds>(
d), rclcpp::Context::SharedPtr(
nullptr));
1260 std::vector<std::string>
c;
1261 if (constraints_storage_)
1262 constraints_storage_->getKnownConstraints(
c, robot_model_->getName(), opt_.
group_name_);
1269 if (path_constraints_)
1270 return *path_constraints_;
1272 return moveit_msgs::msg::Constraints();
1277 if (trajectory_constraints_)
1278 return *trajectory_constraints_;
1280 return moveit_msgs::msg::TrajectoryConstraints();
1285 initializing_constraints_ =
true;
1286 if (constraints_init_thread_)
1287 constraints_init_thread_->join();
1288 constraints_init_thread_ =
1289 std::make_unique<std::thread>([
this, host, port] { initializeConstraintsStorageThread(host, port); });
1292 void setWorkspace(
double minx,
double miny,
double minz,
double maxx,
double maxy,
double maxz)
1294 workspace_parameters_.header.frame_id =
getRobotModel()->getModelFrame();
1295 workspace_parameters_.header.stamp =
getClock()->now();
1296 workspace_parameters_.min_corner.x = minx;
1297 workspace_parameters_.min_corner.y = miny;
1298 workspace_parameters_.min_corner.z = minz;
1299 workspace_parameters_.max_corner.x = maxx;
1300 workspace_parameters_.max_corner.y = maxy;
1301 workspace_parameters_.max_corner.z = maxz;
1306 return node_->get_clock();
1310 void initializeConstraintsStorageThread(
const std::string& host,
unsigned int port)
1316 conn->setParams(host, port);
1317 if (conn->connect())
1319 constraints_storage_ = std::make_unique<moveit_warehouse::ConstraintsStorage>(conn);
1322 catch (std::exception& ex)
1324 RCLCPP_ERROR(
LOGGER,
"%s", ex.what());
1326 initializing_constraints_ =
false;
1330 rclcpp::Node::SharedPtr node_;
1331 rclcpp::CallbackGroup::SharedPtr callback_group_;
1332 rclcpp::executors::SingleThreadedExecutor callback_executor_;
1333 std::thread callback_thread_;
1334 std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
1335 moveit::core::RobotModelConstPtr robot_model_;
1336 planning_scene_monitor::CurrentStateMonitorPtr current_state_monitor_;
1338 std::shared_ptr<rclcpp_action::Client<moveit_msgs::action::MoveGroup>> move_action_client_;
1341 std::shared_ptr<rclcpp_action::Client<moveit_msgs::action::ExecuteTrajectory>> execute_action_client_;
1344 moveit::core::RobotStatePtr considered_start_state_;
1345 moveit_msgs::msg::WorkspaceParameters workspace_parameters_;
1346 double allowed_planning_time_;
1347 std::string planning_pipeline_id_;
1348 std::string planner_id_;
1349 unsigned int num_planning_attempts_;
1350 double max_velocity_scaling_factor_;
1351 double max_acceleration_scaling_factor_;
1352 double goal_joint_tolerance_;
1353 double goal_position_tolerance_;
1354 double goal_orientation_tolerance_;
1356 int32_t look_around_attempts_;
1358 int32_t replan_attempts_;
1359 double replan_delay_;
1362 moveit::core::RobotStatePtr joint_state_target_;
1367 std::map<std::string, std::vector<geometry_msgs::msg::PoseStamped>> pose_targets_;
1370 ActiveTargetType active_target_;
1371 std::unique_ptr<moveit_msgs::msg::Constraints> path_constraints_;
1372 std::unique_ptr<moveit_msgs::msg::TrajectoryConstraints> trajectory_constraints_;
1373 std::string end_effector_link_;
1374 std::string pose_reference_frame_;
1375 std::string support_surface_;
1378 rclcpp::Publisher<std_msgs::msg::String>::SharedPtr trajectory_event_publisher_;
1379 rclcpp::Publisher<moveit_msgs::msg::AttachedCollisionObject>::SharedPtr attached_object_publisher_;
1380 rclcpp::Client<moveit_msgs::srv::QueryPlannerInterfaces>::SharedPtr query_service_;
1381 rclcpp::Client<moveit_msgs::srv::GetPlannerParams>::SharedPtr get_params_service_;
1382 rclcpp::Client<moveit_msgs::srv::SetPlannerParams>::SharedPtr set_params_service_;
1383 rclcpp::Client<moveit_msgs::srv::GetCartesianPath>::SharedPtr cartesian_path_service_;
1385 std::unique_ptr<moveit_warehouse::ConstraintsStorage> constraints_storage_;
1386 std::unique_ptr<std::thread> constraints_init_thread_;
1387 bool initializing_constraints_;
1391 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer,
1392 const rclcpp::Duration& wait_for_servers)
1395 throw std::runtime_error(
"ROS does not seem to be running");
1401 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer,
1402 const rclcpp::Duration& wait_for_servers)
1413 : remembered_joint_values_(std::move(other.remembered_joint_values_)), impl_(other.impl_)
1415 other.impl_ =
nullptr;
1423 impl_ = other.impl_;
1424 remembered_joint_values_ = std::move(other.remembered_joint_values_);
1425 other.impl_ =
nullptr;
1459 const std::string&
group)
const
1465 const std::map<std::string, std::string>& params,
bool replace)
1517 return impl_->
move(
false);
1527 return impl_->
move(
true);
1537 return impl_->
execute(trajectory,
false);
1547 return impl_->
execute(trajectory,
true);
1596 double jump_threshold, moveit_msgs::msg::RobotTrajectory& trajectory,
1597 bool avoid_collisions, moveit_msgs::msg::MoveItErrorCodes* error_code)
1599 moveit_msgs::msg::Constraints path_constraints_tmp;
1605 double jump_threshold, moveit_msgs::msg::RobotTrajectory& trajectory,
1607 bool avoid_collisions, moveit_msgs::msg::MoveItErrorCodes* error_code)
1612 avoid_collisions, *error_code);
1616 moveit_msgs::msg::MoveItErrorCodes error_code_tmp;
1618 avoid_collisions, error_code_tmp);
1629 moveit::core::RobotStatePtr rs;
1630 if (start_state.is_diff)
1634 rs = std::make_shared<moveit::core::RobotState>(
getRobotModel());
1635 rs->setToDefaultValues();
1669 std::map<std::string, std::vector<double>>::const_iterator it = remembered_joint_values_.find(
name);
1670 std::map<std::string, double> positions;
1672 if (it != remembered_joint_values_.cend())
1675 for (
size_t x = 0;
x < names.size(); ++
x)
1677 positions[names[
x]] = it->second[
x];
1689 std::map<std::string, std::vector<double>>::const_iterator it = remembered_joint_values_.find(
name);
1690 if (it != remembered_joint_values_.end())
1701 RCLCPP_ERROR(
LOGGER,
"The requested named target '%s' does not exist",
name.c_str());
1714 if (joint_values.size() != n_group_joints)
1716 RCLCPP_DEBUG_STREAM(
LOGGER,
"Provided joint value list has length " << joint_values.size() <<
" but group "
1718 <<
" has " << n_group_joints <<
" joints");
1729 for (
const auto& pair : variable_values)
1731 if (std::find(allowed.begin(), allowed.end(), pair.first) == allowed.end())
1733 RCLCPP_ERROR_STREAM(
LOGGER,
"joint variable " << pair.first <<
" is not part of group "
1745 const std::vector<double>& variable_values)
1748 for (
const auto& variable_name : variable_names)
1750 if (std::find(allowed.begin(), allowed.end(), variable_name) == allowed.end())
1752 RCLCPP_ERROR_STREAM(
LOGGER,
"joint variable " << variable_name <<
" is not part of group "
1772 std::vector<double> values(1, value);
1786 RCLCPP_ERROR_STREAM(
LOGGER,
1797 const std::string& end_effector_link)
1803 const std::string& end_effector_link)
1805 return impl_->
setJointValueTarget(eef_pose.pose, end_effector_link, eef_pose.header.frame_id,
false);
1810 geometry_msgs::msg::Pose msg = tf2::toMsg(eef_pose);
1815 const std::string& end_effector_link)
1821 const std::string& end_effector_link)
1823 return impl_->
setJointValueTarget(eef_pose.pose, end_effector_link, eef_pose.header.frame_id,
true);
1827 const std::string& end_effector_link)
1829 geometry_msgs::msg::Pose msg = tf2::toMsg(eef_pose);
1882 std::vector<geometry_msgs::msg::PoseStamped> pose_msg(1);
1883 pose_msg[0].pose = tf2::toMsg(pose);
1885 pose_msg[0].header.stamp = impl_->
getClock()->now();
1891 std::vector<geometry_msgs::msg::PoseStamped> pose_msg(1);
1892 pose_msg[0].pose = target;
1894 pose_msg[0].header.stamp = impl_->
getClock()->now();
1899 const std::string& end_effector_link)
1901 std::vector<geometry_msgs::msg::PoseStamped> targets(1, target);
1907 std::vector<geometry_msgs::msg::PoseStamped> pose_out(target.size());
1908 rclcpp::Time tm = impl_->
getClock()->now();
1910 for (std::size_t i = 0; i < target.size(); ++i)
1912 pose_out[i].pose = tf2::toMsg(target[i]);
1913 pose_out[i].header.stamp = tm;
1914 pose_out[i].header.frame_id =
frame_id;
1920 const std::string& end_effector_link)
1922 std::vector<geometry_msgs::msg::PoseStamped> target_stamped(target.size());
1923 rclcpp::Time tm = impl_->
getClock()->now();
1925 for (std::size_t i = 0; i < target.size(); ++i)
1927 target_stamped[i].pose = target[i];
1928 target_stamped[i].header.stamp = tm;
1929 target_stamped[i].header.frame_id =
frame_id;
1935 const std::string& end_effector_link)
1939 RCLCPP_ERROR(
LOGGER,
"No pose specified as goal target");
1954 const std::vector<geometry_msgs::msg::PoseStamped>&
1962 inline void transformPose(
const tf2_ros::Buffer& tf_buffer,
const std::string& desired_frame,
1963 geometry_msgs::msg::PoseStamped& target)
1965 if (desired_frame != target.header.frame_id)
1967 geometry_msgs::msg::PoseStamped target_in(target);
1968 tf_buffer.transform(target_in, target, desired_frame);
1970 target.header.stamp = rclcpp::Time(0);
1977 geometry_msgs::msg::PoseStamped target;
1985 target.pose.orientation.x = 0.0;
1986 target.pose.orientation.y = 0.0;
1987 target.pose.orientation.z = 0.0;
1988 target.pose.orientation.w = 1.0;
1992 target.pose.position.x =
x;
1993 target.pose.position.y =
y;
1994 target.pose.position.z =
z;
2002 geometry_msgs::msg::PoseStamped target;
2010 target.pose.position.x = 0.0;
2011 target.pose.position.y = 0.0;
2012 target.pose.position.z = 0.0;
2017 target.pose.orientation = tf2::toMsg(q);
2024 const std::string& end_effector_link)
2026 geometry_msgs::msg::PoseStamped target;
2034 target.pose.position.x = 0.0;
2035 target.pose.position.y = 0.0;
2036 target.pose.position.z = 0.0;
2040 target.pose.orientation.x =
x;
2041 target.pose.orientation.y =
y;
2042 target.pose.orientation.z =
z;
2043 target.pose.orientation.w =
w;
2108 moveit::core::RobotStatePtr current_state;
2109 std::vector<double> values;
2111 current_state->copyJointGroupPositions(
getName(), values);
2117 std::vector<double>
r;
2124 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
2125 Eigen::Isometry3d pose;
2128 RCLCPP_ERROR(
LOGGER,
"No end-effector specified");
2131 moveit::core::RobotStatePtr current_state;
2137 pose = current_state->getGlobalLinkTransform(lm);
2140 geometry_msgs::msg::PoseStamped pose_msg;
2141 pose_msg.header.stamp = impl_->
getClock()->now();
2142 pose_msg.header.frame_id = impl_->
getRobotModel()->getModelFrame();
2143 pose_msg.pose = tf2::toMsg(pose);
2149 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
2150 Eigen::Isometry3d pose;
2153 RCLCPP_ERROR(
LOGGER,
"No end-effector specified");
2156 moveit::core::RobotStatePtr current_state;
2161 pose = current_state->getGlobalLinkTransform(lm);
2164 geometry_msgs::msg::PoseStamped pose_msg;
2165 pose_msg.header.stamp = impl_->
getClock()->now();
2166 pose_msg.header.frame_id = impl_->
getRobotModel()->getModelFrame();
2167 pose_msg.pose = tf2::toMsg(pose);
2173 std::vector<double> result;
2174 const std::string& eef = end_effector_link.empty() ?
getEndEffectorLink() : end_effector_link;
2176 RCLCPP_ERROR(
LOGGER,
"No end-effector specified");
2179 moveit::core::RobotStatePtr current_state;
2186 geometry_msgs::msg::TransformStamped tfs = tf2::eigenToTransform(current_state->getGlobalLinkTransform(lm));
2187 double pitch, roll, yaw;
2188 tf2::getEulerYPR<geometry_msgs::msg::Quaternion>(tfs.transform.rotation, yaw, pitch, roll);
2215 moveit::core::RobotStatePtr current_state;
2217 return current_state;
2222 remembered_joint_values_[
name] = values;
2227 remembered_joint_values_.erase(
name);
2232 impl_->can_look_ = flag;
2233 RCLCPP_DEBUG(
LOGGER,
"Looking around: %s", flag ?
"yes" :
"no");
2240 RCLCPP_ERROR(
LOGGER,
"Tried to set negative number of look-around attempts");
2244 RCLCPP_DEBUG_STREAM(
LOGGER,
"Look around attempts: " << attempts);
2245 impl_->look_around_attempts_ = attempts;
2251 impl_->can_replan_ = flag;
2252 RCLCPP_DEBUG(
LOGGER,
"Replanning: %s", flag ?
"yes" :
"no");
2259 RCLCPP_ERROR(
LOGGER,
"Tried to set negative number of replan attempts");
2263 RCLCPP_DEBUG_STREAM(
LOGGER,
"Replan Attempts: " << attempts);
2264 impl_->replan_attempts_ = attempts;
2272 RCLCPP_ERROR(
LOGGER,
"Tried to set negative replan delay");
2276 RCLCPP_DEBUG_STREAM(
LOGGER,
"Replan Delay: " << delay);
2277 impl_->replan_delay_ = delay;
2328 impl_->
setWorkspace(minx, miny, minz, maxx, maxy, maxz);
2360 return attachObject(
object, link, std::vector<std::string>());
2364 const std::vector<std::string>& touch_links)
const std::vector< std::string > & getLinkModelNames() const
Get the names of the links that are part of this joint group.
bool isChain() const
Check if this group is a linear chain.
const std::string & getName() const
Get the name of the joint group.
void getVariableRandomPositions(random_numbers::RandomNumberGenerator &rng, double *values) const
Compute random values for the state of the joint group.
const std::vector< std::string > & getJointModelNames() const
Get the names of the joints in this group. These are the names of the joints returned by getJointMode...
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...
const JointModel * getJointModel(const std::string &joint) const
Get a joint by its name. Throw an exception if the joint is not part of this group.
bool hasLinkModel(const std::string &link) const
Check if a link is part of this group.
unsigned int getVariableCount() const
Get the number of variables that describe this joint group. This includes variables necessary for mim...
const std::vector< std::string > & getVariableNames() const
Get the names of the variables that make up the joints included in this group. The number of returned...
bool getVariableDefaultPositions(const std::string &name, std::map< std::string, double > &values) const
Get the values that correspond to a named state as read from the URDF. Return false on failure.
const std::vector< std::string > & getDefaultStateNames() const
Get the names of the known default states (as specified in the SRDF)
const std::vector< std::string > & getActiveJointModelNames() const
Get the names of the active joints in this group. These are the names of the joints returned by getJo...
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.
void setVariablePositions(const double *position)
It is assumed positions is an array containing the new positions for all variables in this state....
void setJointGroupPositions(const std::string &joint_group_name, const double *gstate)
Given positions for the variables that make up a group, in the order found in the group (including va...
void copyJointGroupPositions(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the position values of the variables that make up the group into another loca...
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...
void setToRandomPositions()
Set all joints to random values. Values will be within default bounds.
bool satisfiesBounds(double margin=0.0) const
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
random_numbers::RandomNumberGenerator & getRandomNumberGenerator()
Return the instance of a random number generator.
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...
void setJointPositions(const std::string &joint_name, const double *position)
std::vector< std::string > getKnownConstraints() const
const std::string & getEndEffectorLink() const
bool startStateMonitor(double wait)
void setPlanningPipelineId(const std::string &pipeline_id)
const std::string & getEndEffector() const
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)
const Options & getOptions() const
void constructGoal(moveit_msgs::action::MoveGroup::Goal &goal) const
double getPlanningTime() const
double computeCartesianPath(const std::vector< geometry_msgs::msg::Pose > &waypoints, double step, double jump_threshold, moveit_msgs::msg::RobotTrajectory &msg, const moveit_msgs::msg::Constraints &path_constraints, bool avoid_collisions, moveit_msgs::msg::MoveItErrorCodes &error_code)
std::string getDefaultPlannerId(const std::string &group) const
bool setPathConstraints(const std::string &constraint)
const std::string & getPlannerId() const
void setStartState(const moveit::core::RobotState &start_state)
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)
void setSupportSurfaceName(const std::string &support_surface)
const moveit::core::RobotState & getTargetRobotState() const
bool getCurrentState(moveit::core::RobotStatePtr ¤t_state, double wait_seconds=1.0)
rclcpp_action::Client< moveit_msgs::action::MoveGroup > & getMoveGroupClient() const
moveit::core::MoveItErrorCode execute(const moveit_msgs::msg::RobotTrajectory &trajectory, bool wait)
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)
void initializeConstraintsStorage(const std::string &host, unsigned int port)
void setPlannerId(const std::string &planner_id)
const std::shared_ptr< tf2_ros::Buffer > & getTF() const
double getGoalOrientationTolerance() const
moveit_msgs::msg::Constraints getPathConstraints() const
void setTargetType(ActiveTargetType type)
void setPathConstraints(const moveit_msgs::msg::Constraints &constraint)
std::map< std::string, std::string > getPlannerParams(const std::string &planner_id, const std::string &group="")
const moveit::core::JointModelGroup * getJointModelGroup() const
ActiveTargetType getTargetType() const
void setMaxVelocityScalingFactor(double value)
void setNumPlanningAttempts(unsigned int num_planning_attempts)
const moveit::core::RobotModelConstPtr & getRobotModel() const
void setGoalJointTolerance(double tolerance)
const geometry_msgs::msg::PoseStamped & getPoseTarget(const std::string &end_effector_link) const
void setTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &constraint)
moveit::core::MoveItErrorCode move(bool wait)
void constructMotionPlanRequest(moveit_msgs::msg::MotionPlanRequest &request) const
void setPlanningTime(double seconds)
moveit_msgs::msg::TrajectoryConstraints getTrajectoryConstraints() 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)
moveit::core::RobotState & getTargetRobotState()
void clearTrajectoryConstraints()
bool getInterfaceDescription(moveit_msgs::msg::PlannerInterfaceDescription &desc)
const std::string & getPlanningPipelineId() 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()
const std::vector< geometry_msgs::msg::PoseStamped > & getPoseTargets(const std::string &end_effector_link) const
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::MoveItErrorCode plan(Plan &plan)
Convert a vector of PoseStamped to a vector of PlaceLocation.
const std::string & getPoseReferenceFrame() const
void setWorkspace(double minx, double miny, double minz, double maxx, double maxy, double maxz)
Client class to conveniently use the ROS interfaces provided by the move_group node.
double computeCartesianPath(const std::vector< geometry_msgs::msg::Pose > &waypoints, double eef_step, double jump_threshold, 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...
std::vector< double > getRandomJointValues() const
Get random joint values for the joints planned for by this instance (see getJoints())
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)
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).
void setSupportSurfaceName(const std::string &name)
For pick/place operations, the name of the support surface is used to specify the fact that attached ...
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="")
Pick up an object.
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 ...
MoveGroupInterface & operator=(const MoveGroupInterface &)=delete
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.
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()
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.
moveit::core::MoveItErrorCode execute(const Plan &plan)
Given a plan, execute it while waiting for completion.
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.
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.
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::vector< geometry_msgs::msg::PoseStamped > & getPoseTargets(const std::string &end_effector_link="") const
moveit_msgs::msg::TrajectoryConstraints getTrajectoryConstraints() const
const std::vector< std::string > & getLinkNames() const
Get vector of names of links available in move group.
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.
const moveit::core::RobotState & getJointValueTarget() const
Get the currently set joint state goal, replaced by private getTargetRobotState()
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 ...
moveit::core::MoveItErrorCode asyncExecute(const Plan &plan)
Given a plan, execute it without waiting for completion.
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 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.
moveit::core::RobotModelConstPtr getSharedRobotModel(const rclcpp::Node::SharedPtr &node, const std::string &robot_description)
std::shared_ptr< tf2_ros::Buffer > getSharedTF()
const rclcpp::Logger LOGGER
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
const std::string GRASP_PLANNING_SERVICE_NAME
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.
This namespace includes the base class for MoveIt planners.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
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 group_name_
The group to construct the class instance for.
std::string move_group_namespace_
The namespace for the move group node.
The representation of a motion plan (as ROS messasges)