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