moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
local_planner_component.hpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2020, 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: Sebastian Jahr
36 Description: A local planner component node that is customizable through plugins that implement the local planning
37 problem solver algorithm and the trajectory matching and blending.
38 */
39
40#pragma once
41
42#include <rclcpp/rclcpp.hpp>
43#include <rclcpp/version.h>
44#include <rclcpp_action/rclcpp_action.hpp>
45
46#include <pluginlib/class_loader.hpp>
47
48#include <moveit_msgs/action/local_planner.hpp>
49#include <moveit_msgs/msg/motion_plan_response.hpp>
50#include <moveit_msgs/msg/robot_trajectory.hpp>
51
52#include <std_msgs/msg/float64.hpp>
53#include <std_msgs/msg/float64_multi_array.hpp>
54
55#include <trajectory_msgs/msg/joint_trajectory.hpp>
56
61
62// For Rolling, Kilted, and newer
63#if RCLCPP_VERSION_GTE(29, 6, 0)
64#include <tf2_ros/buffer.hpp>
65#include <tf2_ros/transform_listener.hpp>
66// For Jazzy and older
67#else
68#include <tf2_ros/buffer.h>
69#include <tf2_ros/transform_listener.h>
70#endif
71
72// Forward declaration of parameter class allows users to implement custom parameters
78{
81enum class LocalPlannerState : int8_t
82{
83 ABORT = -1,
84 ERROR = 0,
85 UNCONFIGURED = 1,
88};
89
94{
95public:
97 LocalPlannerComponent(const rclcpp::NodeOptions& options);
98
101 {
102 // Join the thread used for long-running callbacks
103 if (long_callback_thread_.joinable())
104 {
105 long_callback_thread_.join();
106 }
107 }
108
115 bool initialize();
116
120 void executeIteration();
121
122 // This function is required to make this class a valid NodeClass
123 // see https://docs.ros2.org/foxy/api/rclcpp_components/register__node__macro_8hpp.html
124 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface() // NOLINT
125 {
126 return node_->get_node_base_interface(); // NOLINT
127 }
128
129private:
131 void reset();
132
133 std::shared_ptr<rclcpp::Node> node_;
134
135 // Planner configuration
136 std::shared_ptr<local_planner_parameters::Params> config_;
137
138 // Current planner state. Must be thread-safe
139 std::atomic<LocalPlannerState> state_;
140
141 // Timer to periodically call executeIteration()
142 rclcpp::TimerBase::SharedPtr timer_;
143
144 // Latest action goal handle
145 std::shared_ptr<rclcpp_action::ServerGoalHandle<moveit_msgs::action::LocalPlanner>> local_planning_goal_handle_;
146
147 // Local planner feedback
148 std::shared_ptr<moveit_msgs::action::LocalPlanner::Feedback> local_planner_feedback_;
149
150 // Planning scene monitor to get the current planning scene
151 planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
152
153 // TF
154 std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
155 std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
156
157 // Global solution listener
158 rclcpp::Subscription<moveit_msgs::msg::MotionPlanResponse>::SharedPtr global_solution_subscriber_;
159
160 // Local planning request action server
161 rclcpp_action::Server<moveit_msgs::action::LocalPlanner>::SharedPtr local_planning_request_server_;
162
163 // Local solution publisher
164 rclcpp::Publisher<trajectory_msgs::msg::JointTrajectory>::SharedPtr local_trajectory_publisher_;
165 rclcpp::Publisher<std_msgs::msg::Float64MultiArray>::SharedPtr local_solution_publisher_;
166
167 // Local constraint solver plugin loader
168 std::unique_ptr<pluginlib::ClassLoader<LocalConstraintSolverInterface>> local_constraint_solver_plugin_loader_;
169
170 // Local constrain solver instance to compute a local solution each iteration
171 std::shared_ptr<LocalConstraintSolverInterface> local_constraint_solver_instance_;
172
173 // Trajectory operator plugin
174 std::unique_ptr<pluginlib::ClassLoader<TrajectoryOperatorInterface>> trajectory_operator_loader_;
175
176 // Trajectory_operator instance handle trajectory matching and blending
177 std::shared_ptr<TrajectoryOperatorInterface> trajectory_operator_instance_;
178
179 // This thread is used for long-running callbacks. It's a member so they do not go out of scope.
180 std::thread long_callback_thread_;
181
182 // A unique callback group, to avoid mixing callbacks with other action servers
183 rclcpp::CallbackGroup::SharedPtr cb_group_;
184};
185} // namespace moveit::hybrid_planning
#define MOVEIT_STRUCT_FORWARD(C)
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface()