moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
moveit_cpp.hpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2019, PickNik Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of PickNik Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Henning Kayser
36 Desc: A high level interface that does not require the use of ROS Actions, Services, and Messages to access the
37 core MoveIt functionality
38*/
39
40#pragma once
41
42#include <rclcpp/rclcpp.hpp>
48#include <tf2_ros/buffer.h>
49
50namespace moveit_cpp
51{
52MOVEIT_CLASS_FORWARD(MoveItCpp); // Defines MoveItCppPtr, ConstPtr, WeakPtr... etc
53
55{
56public:
59 {
61 : joint_state_topic(planning_scene_monitor::PlanningSceneMonitor::DEFAULT_JOINT_STATES_TOPIC)
63 planning_scene_monitor::PlanningSceneMonitor::DEFAULT_ATTACHED_COLLISION_OBJECT_TOPIC)
64 , monitored_planning_scene_topic(planning_scene_monitor::PlanningSceneMonitor::MONITORED_PLANNING_SCENE_TOPIC)
65 , publish_planning_scene_topic(planning_scene_monitor::PlanningSceneMonitor::DEFAULT_PLANNING_SCENE_TOPIC)
66 {
67 }
68
69 void load(const rclcpp::Node::SharedPtr& node)
70 {
71 const std::string ns = "planning_scene_monitor_options";
72 node->get_parameter_or(ns + ".name", name, std::string("planning_scene_monitor"));
73 node->get_parameter_or(ns + ".robot_description", robot_description, std::string("robot_description"));
74 node->get_parameter_or(ns + ".wait_for_initial_state_timeout", wait_for_initial_state_timeout, 0.0);
75 }
76 std::string name;
77 std::string robot_description;
78 const std::string joint_state_topic;
83 };
84
87 {
88 void load(const rclcpp::Node::SharedPtr& node)
89 {
90 const std::string ns = "planning_pipelines.";
91 node->get_parameter(ns + "pipeline_names", pipeline_names);
92 node->get_parameter(ns + "namespace", parent_namespace);
93 }
94 std::vector<std::string> pipeline_names;
95 std::string parent_namespace;
96 };
97
110
112 MoveItCpp(const rclcpp::Node::SharedPtr& node);
113 MoveItCpp(const rclcpp::Node::SharedPtr& node, const Options& options);
114
120 MoveItCpp(const MoveItCpp&) = delete;
121 MoveItCpp& operator=(const MoveItCpp&) = delete;
122
123 MoveItCpp(MoveItCpp&& other) = default;
124 MoveItCpp& operator=(MoveItCpp&& other) = default;
125
127 ~MoveItCpp();
128
130 moveit::core::RobotModelConstPtr getRobotModel() const;
131
133 const rclcpp::Node::SharedPtr& getNode() const;
134
137 bool getCurrentState(moveit::core::RobotStatePtr& current_state, double wait_seconds);
138
141 moveit::core::RobotStatePtr getCurrentState(double wait_seconds = 0.0);
142
144 const std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr>& getPlanningPipelines() const;
145
147 planning_scene_monitor::PlanningSceneMonitorConstPtr getPlanningSceneMonitor() const;
148 planning_scene_monitor::PlanningSceneMonitorPtr getPlanningSceneMonitorNonConst();
149
150 std::shared_ptr<const tf2_ros::Buffer> getTFBuffer() const;
151 std::shared_ptr<tf2_ros::Buffer> getTFBuffer();
152
154 trajectory_execution_manager::TrajectoryExecutionManagerConstPtr getTrajectoryExecutionManager() const;
155 trajectory_execution_manager::TrajectoryExecutionManagerPtr getTrajectoryExecutionManagerNonConst();
156
164 [[deprecated("MoveItCpp::execute() no longer requires a blocking parameter")]] moveit_controller_manager::ExecutionStatus
165 execute(const robot_trajectory::RobotTrajectoryPtr& robot_trajectory, bool blocking,
166 const std::vector<std::string>& controllers = std::vector<std::string>());
167
169 execute(const robot_trajectory::RobotTrajectoryPtr& robot_trajectory,
170 const std::vector<std::string>& controllers = std::vector<std::string>());
171
173 bool terminatePlanningPipeline(const std::string& pipeline_name);
174
175private:
176 // Core properties and instances
177 rclcpp::Node::SharedPtr node_;
178 planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
179
180 // Planning
181 std::unordered_map<std::string, planning_pipeline::PlanningPipelinePtr> planning_pipelines_;
182 std::unordered_map<std::string, std::set<std::string>> groups_algorithms_map_;
183
184 // Execution
185 trajectory_execution_manager::TrajectoryExecutionManagerPtr trajectory_execution_manager_;
186
187 rclcpp::Logger logger_;
188
190 bool loadPlanningSceneMonitor(const PlanningSceneMonitorOptions& options);
191
193 bool loadPlanningPipelines(const PlanningPipelineOptions& options);
194};
195} // namespace moveit_cpp
#define MOVEIT_CLASS_FORWARD(C)
MoveItCpp(MoveItCpp &&other)=default
std::shared_ptr< const tf2_ros::Buffer > getTFBuffer() const
MoveItCpp & operator=(const MoveItCpp &)=delete
moveit_controller_manager::ExecutionStatus execute(const robot_trajectory::RobotTrajectoryPtr &robot_trajectory, bool blocking, const std::vector< std::string > &controllers=std::vector< std::string >())
Execute a trajectory on the planning group specified by the robot's trajectory using the trajectory e...
moveit::core::RobotModelConstPtr getRobotModel() const
Get the RobotModel object.
const std::unordered_map< std::string, planning_pipeline::PlanningPipelinePtr > & getPlanningPipelines() const
Get all loaded planning pipeline instances mapped to their reference names.
~MoveItCpp()
Destructor.
planning_scene_monitor::PlanningSceneMonitorConstPtr getPlanningSceneMonitor() const
Get the stored instance of the planning scene monitor.
bool getCurrentState(moveit::core::RobotStatePtr &current_state, double wait_seconds)
Get the current state queried from the current state monitor.
planning_scene_monitor::PlanningSceneMonitorPtr getPlanningSceneMonitorNonConst()
const rclcpp::Node::SharedPtr & getNode() const
Get the ROS node this instance operates on.
bool terminatePlanningPipeline(const std::string &pipeline_name)
Utility to terminate the given planning pipeline.
trajectory_execution_manager::TrajectoryExecutionManagerConstPtr getTrajectoryExecutionManager() const
Get the stored instance of the trajectory execution manager.
MoveItCpp(const MoveItCpp &)=delete
This class owns unique resources (e.g. action clients, threads) and its not very meaningful to copy....
MoveItCpp & operator=(MoveItCpp &&other)=default
trajectory_execution_manager::TrajectoryExecutionManagerPtr getTrajectoryExecutionManagerNonConst()
Parameter container for initializing MoveItCpp.
PlanningPipelineOptions planning_pipeline_options
Options(const rclcpp::Node::SharedPtr &node)
PlanningSceneMonitorOptions planning_scene_monitor_options
struct contains the the variables used for loading the planning pipeline
void load(const rclcpp::Node::SharedPtr &node)
Specification of options to use when constructing the MoveItCpp class.
void load(const rclcpp::Node::SharedPtr &node)