42 constexpr
char LOGNAME[] =
"moveit_cpp";
51 const std::shared_ptr<tf2_ros::Buffer>& tf_buffer)
55 tf_buffer_ = std::make_shared<tf2_ros::Buffer>();
56 tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
59 if (!loadPlanningSceneMonitor(options.planning_scene_monitor_options))
61 const std::string error =
"Unable to configure planning scene monitor";
63 throw std::runtime_error(error);
68 const std::string error =
"Unable to construct robot model. Please make sure all needed information is on the "
71 throw std::runtime_error(error);
74 bool load_planning_pipelines =
true;
75 if (load_planning_pipelines && !loadPlanningPipelines(options.planning_pipeline_options))
77 const std::string error =
"Failed to load planning pipelines from parameter server";
79 throw std::runtime_error(error);
83 trajectory_execution_manager_ = std::make_shared<trajectory_execution_manager::TrajectoryExecutionManager>(
84 getRobotModel(), planning_scene_monitor_->getStateMonitor());
89 MoveItCpp::~MoveItCpp()
94 bool MoveItCpp::loadPlanningSceneMonitor(
const PlanningSceneMonitorOptions& options)
96 planning_scene_monitor_ = std::make_shared<planning_scene_monitor::PlanningSceneMonitor>(options.robot_description,
97 tf_buffer_, options.name);
100 if (planning_scene_monitor_->getPlanningScene())
105 planning_scene_monitor_->startStateMonitor(options.joint_state_topic, options.attached_collision_object_topic);
108 options.monitored_planning_scene_topic);
110 planning_scene_monitor_->startSceneMonitor(options.publish_planning_scene_topic);
112 planning_scene_monitor_->startWorldGeometryMonitor();
121 if (options.wait_for_initial_state_timeout > 0.0)
123 return planning_scene_monitor_->getStateMonitor()->waitForCurrentState(
ros::Time::now(),
124 options.wait_for_initial_state_timeout);
130 bool MoveItCpp::loadPlanningPipelines(
const PlanningPipelineOptions& options)
132 ros::NodeHandle node_handle(options.parent_namespace.empty() ?
"~" : options.parent_namespace);
133 for (
const auto& planning_pipeline_name : options.pipeline_names)
135 if (planning_pipelines_.count(planning_pipeline_name) > 0)
137 ROS_WARN_NAMED(
LOGNAME,
"Skipping duplicate entry for planning pipeline '%s'.", planning_pipeline_name.c_str());
146 std::make_shared<planning_pipeline::PlanningPipeline>(getRobotModel(), child_nh,
PLANNING_PLUGIN_PARAM);
148 if (!pipeline->getPlannerManager())
149 throw std::runtime_error(
"Invalid planner manager");
151 planning_pipelines_[planning_pipeline_name] = pipeline;
153 catch (std::exception& ex)
155 ROS_ERROR_NAMED(
LOGNAME,
"Failed to initialize planning pipeline '%s':\n%s", planning_pipeline_name.c_str(),
160 if (planning_pipelines_.empty())
169 moveit::core::RobotModelConstPtr MoveItCpp::getRobotModel()
const
171 return planning_scene_monitor_->getRobotModel();
179 bool MoveItCpp::getCurrentState(moveit::core::RobotStatePtr& current_state,
double wait_seconds)
181 if (wait_seconds > 0.0 &&
182 !planning_scene_monitor_->getStateMonitor()->waitForCurrentState(
ros::Time::now(), wait_seconds))
189 current_state = std::make_shared<moveit::core::RobotState>(scene->getCurrentState());
194 moveit::core::RobotStatePtr MoveItCpp::getCurrentState(
double wait)
196 moveit::core::RobotStatePtr current_state;
197 getCurrentState(current_state, wait);
198 return current_state;
201 const std::map<std::string, planning_pipeline::PlanningPipelinePtr>& MoveItCpp::getPlanningPipelines()
const
203 return planning_pipelines_;
206 planning_scene_monitor::PlanningSceneMonitorConstPtr MoveItCpp::getPlanningSceneMonitor()
const
208 return planning_scene_monitor_;
211 planning_scene_monitor::PlanningSceneMonitorPtr MoveItCpp::getPlanningSceneMonitorNonConst()
213 return planning_scene_monitor_;
216 trajectory_execution_manager::TrajectoryExecutionManagerConstPtr MoveItCpp::getTrajectoryExecutionManager()
const
218 return trajectory_execution_manager_;
221 trajectory_execution_manager::TrajectoryExecutionManagerPtr MoveItCpp::getTrajectoryExecutionManagerNonConst()
223 return trajectory_execution_manager_;
226 bool MoveItCpp::execute(
const std::string& group_name,
const robot_trajectory::RobotTrajectoryPtr&
robot_trajectory,
236 if (!trajectory_execution_manager_->ensureActiveControllersForGroup(group_name))
243 moveit_msgs::RobotTrajectory robot_trajectory_msg;
249 trajectory_execution_manager_->push(robot_trajectory_msg);
250 trajectory_execution_manager_->execute();
251 return trajectory_execution_manager_->waitForExecution();
256 bool MoveItCpp::terminatePlanningPipeline(std::string
const& pipeline_name)
267 catch (
const std::out_of_range& oor)
270 pipeline_name.c_str());
275 std::shared_ptr<const tf2_ros::Buffer> MoveItCpp::getTFBuffer()
const
279 std::shared_ptr<tf2_ros::Buffer> MoveItCpp::getTFBuffer()