51 constexpr
char LOGNAME[] =
"moveit_cpp";
60 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer)
68 if (!loadPlanningSceneMonitor(options.planning_scene_monitor_options))
70 const std::string error =
"Unable to configure planning scene monitor";
72 throw std::runtime_error(error);
75 robot_model_ = planning_scene_monitor_->getRobotModel();
78 const std::string error =
"Unable to construct robot model. Please make sure all needed information is on the "
81 throw std::runtime_error(error);
84 bool load_planning_pipelines =
true;
85 if (load_planning_pipelines && !loadPlanningPipelines(options.planning_pipeline_options))
87 const std::string error =
"Failed to load planning pipelines from parameter server";
89 throw std::runtime_error(error);
94 robot_model_, planning_scene_monitor_->getStateMonitor()));
99 MoveItCpp::~MoveItCpp()
105 bool MoveItCpp::loadPlanningSceneMonitor(
const PlanningSceneMonitorOptions& options)
107 planning_scene_monitor_.reset(
111 if (planning_scene_monitor_->getPlanningScene())
115 planning_scene_monitor_->startStateMonitor(options.joint_state_topic, options.attached_collision_object_topic);
117 options.publish_planning_scene_topic);
118 planning_scene_monitor_->startSceneMonitor(options.monitored_planning_scene_topic);
127 if (options.wait_for_initial_state_timeout > 0.0)
129 return planning_scene_monitor_->getStateMonitor()->waitForCurrentState(
ros::Time::now(),
130 options.wait_for_initial_state_timeout);
136 bool MoveItCpp::loadPlanningPipelines(
const PlanningPipelineOptions& options)
138 ros::NodeHandle node_handle(options.parent_namespace.empty() ?
"~" : options.parent_namespace);
139 for (
const auto& planning_pipeline_name : options.pipeline_names)
141 if (planning_pipelines_.count(planning_pipeline_name) > 0)
143 ROS_WARN_NAMED(
LOGNAME,
"Skipping duplicate entry for planning pipeline '%s'.", planning_pipeline_name.c_str());
148 planning_pipeline::PlanningPipelinePtr pipeline;
151 if (!pipeline->getPlannerManager())
156 planning_pipelines_[planning_pipeline_name] = pipeline;
159 if (planning_pipelines_.empty())
166 std::vector<std::string> group_names = robot_model_->getJointModelGroupNames();
167 for (
const auto& pipeline_entry : planning_pipelines_)
169 for (
const auto& group_name : group_names)
171 groups_pipelines_map_[group_name] = {};
172 const auto& pipeline = pipeline_entry.second;
173 for (
const auto& planner_configuration : pipeline->getPlannerManager()->getPlannerConfigurations())
175 if (planner_configuration.second.group == group_name)
177 groups_pipelines_map_[group_name].insert(pipeline_entry.first);
186 moveit::core::RobotModelConstPtr MoveItCpp::getRobotModel()
const
196 bool MoveItCpp::getCurrentState(moveit::core::RobotStatePtr& current_state,
double wait_seconds)
198 if (wait_seconds > 0.0 &&
199 !planning_scene_monitor_->getStateMonitor()->waitForCurrentState(
ros::Time::now(), wait_seconds))
211 moveit::core::RobotStatePtr MoveItCpp::getCurrentState(
double wait)
213 moveit::core::RobotStatePtr current_state;
214 getCurrentState(current_state, wait);
215 return current_state;
218 const std::map<std::string, planning_pipeline::PlanningPipelinePtr>& MoveItCpp::getPlanningPipelines()
const
220 return planning_pipelines_;
223 std::set<std::string> MoveItCpp::getPlanningPipelineNames(
const std::string& group_name)
const
225 std::set<std::string> result_names;
226 if (!group_name.empty() && groups_pipelines_map_.count(group_name) == 0)
229 "No planning pipelines loaded for group '%s'. Check planning pipeline and controller setup.",
233 for (
const auto& pipeline_entry : planning_pipelines_)
235 const std::string& pipeline_name = pipeline_entry.first;
237 if (!group_name.empty())
239 const auto& group_pipelines = groups_pipelines_map_.at(group_name);
240 if (group_pipelines.find(pipeline_name) == group_pipelines.end())
243 result_names.insert(pipeline_name);
246 if (result_names.empty())
248 "No planning pipelines loaded for group '%s'. Check planning pipeline and controller setup.",
253 const planning_scene_monitor::PlanningSceneMonitorPtr& MoveItCpp::getPlanningSceneMonitor()
const
255 return planning_scene_monitor_;
258 planning_scene_monitor::PlanningSceneMonitorPtr MoveItCpp::getPlanningSceneMonitorNonConst()
260 return planning_scene_monitor_;
263 const trajectory_execution_manager::TrajectoryExecutionManagerPtr& MoveItCpp::getTrajectoryExecutionManager()
const
265 return trajectory_execution_manager_;
268 trajectory_execution_manager::TrajectoryExecutionManagerPtr MoveItCpp::getTrajectoryExecutionManagerNonConst()
270 return trajectory_execution_manager_;
273 bool MoveItCpp::execute(
const std::string& group_name,
const robot_trajectory::RobotTrajectoryPtr&
robot_trajectory,
283 if (!trajectory_execution_manager_->ensureActiveControllersForGroup(group_name))
285 ROS_ERROR_NAMED(
LOGNAME,
"Execution failed! No active controllers configured for group '%s'", group_name.c_str());
290 moveit_msgs::RobotTrajectory robot_trajectory_msg;
294 trajectory_execution_manager_->push(robot_trajectory_msg);
295 trajectory_execution_manager_->execute();
296 return trajectory_execution_manager_->waitForExecution();
298 trajectory_execution_manager_->pushAndExecute(robot_trajectory_msg);
302 const std::shared_ptr<tf2_ros::Buffer>& MoveItCpp::getTFBuffer()
const
307 void MoveItCpp::clearContents()
309 tf_listener_.reset();
311 planning_scene_monitor_.reset();
312 robot_model_.reset();
313 planning_pipelines_.clear();