moveit2
The MoveIt Motion Planning Framework for ROS 2.
global_planner_component.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2021, 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 global planner component node that is customizable through plugins.
37  */
38 
39 #pragma once
40 
41 #include <rclcpp/rclcpp.hpp>
42 #include <rclcpp_action/rclcpp_action.hpp>
43 
44 #include <pluginlib/class_loader.hpp>
45 
47 
48 #include <moveit_msgs/action/global_planner.hpp>
49 #include <moveit_msgs/msg/motion_plan_request.hpp>
50 #include <moveit_msgs/msg/motion_plan_response.hpp>
51 
53 {
54 // Component node containing the global planner
56 {
57 public:
59  GlobalPlannerComponent(const rclcpp::NodeOptions& options);
60 
63  {
64  // Join the thread used for long-running callbacks
65  if (long_callback_thread_.joinable())
66  {
67  long_callback_thread_.join();
68  }
69  }
70 
71  // This function is required to make this class a valid NodeClass
72  // see https://docs.ros2.org/foxy/api/rclcpp_components/register__node__macro_8hpp.html
73  // Skip linting due to unconventional function naming
74  rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface() // NOLINT
75  {
76  return node_->get_node_base_interface(); // NOLINT
77  }
78 
79 private:
80  std::shared_ptr<rclcpp::Node> node_;
81 
82  std::string planner_plugin_name_;
83 
84  // Global planner plugin loader
85  std::unique_ptr<pluginlib::ClassLoader<GlobalPlannerInterface>> global_planner_plugin_loader_;
86 
87  // Global planner instance
88  std::shared_ptr<GlobalPlannerInterface> global_planner_instance_;
89 
90  // Global planning request action server
91  rclcpp_action::Server<moveit_msgs::action::GlobalPlanner>::SharedPtr global_planning_request_server_;
92 
93  // Global trajectory publisher
94  rclcpp::Publisher<moveit_msgs::msg::MotionPlanResponse>::SharedPtr global_trajectory_pub_;
95 
96  // Goal callback for global planning request action server
97  void globalPlanningRequestCallback(
98  const std::shared_ptr<rclcpp_action::ServerGoalHandle<moveit_msgs::action::GlobalPlanner>>& goal_handle);
99 
100  // Initialize planning scene monitor and load pipelines
101  bool initializeGlobalPlanner();
102 
103  // This thread is used for long-running callbacks. It's a member so they do not go out of scope.
104  std::thread long_callback_thread_;
105 
106  // A unique callback group, to avoid mixing callbacks with other action servers
107  rclcpp::CallbackGroup::SharedPtr cb_group_;
108 };
109 
110 } // namespace moveit::hybrid_planning
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface()
GlobalPlannerComponent(const rclcpp::NodeOptions &options)
Constructor.