moveit2
The MoveIt Motion Planning Framework for ROS 2.
hybrid_planning_manager.h
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: The hybrid planning manager component node that serves as the control unit of the whole architecture.
37  */
38 
39 #pragma once
40 
41 #include <rclcpp/rclcpp.hpp>
42 #include <rclcpp_action/rclcpp_action.hpp>
43 
44 #include <moveit_msgs/action/local_planner.hpp>
45 #include <moveit_msgs/action/global_planner.hpp>
46 #include <moveit_msgs/action/hybrid_planner.hpp>
47 
49 
50 #include <pluginlib/class_loader.hpp>
51 
53 {
57 class HybridPlanningManager : public rclcpp::Node
58 {
59 public:
61  HybridPlanningManager(const rclcpp::NodeOptions& options);
62 
65  {
66  // Join the thread used for long-running callbacks
67  if (long_callback_thread_.joinable())
68  {
69  long_callback_thread_.join();
70  }
71  }
72 
77  std::shared_ptr<HybridPlanningManager> shared_from_this()
78  {
79  return std::static_pointer_cast<HybridPlanningManager>(Node::shared_from_this());
80  }
81 
86  bool initialize();
87 
91  void cancelHybridManagerGoals() noexcept;
92 
98  std::shared_ptr<rclcpp_action::ServerGoalHandle<moveit_msgs::action::HybridPlanner>> goal_handle);
99 
105 
110  bool sendLocalPlannerAction();
111 
116  void sendHybridPlanningResponse(bool success);
117 
118 private:
119  // Planner logic plugin loader
120  std::unique_ptr<pluginlib::ClassLoader<PlannerLogicInterface>> planner_logic_plugin_loader_;
121 
122  // Planner logic instance to implement reactive behavior
123  std::shared_ptr<PlannerLogicInterface> planner_logic_instance_;
124 
125  // Timer to trigger events periodically
126  rclcpp::TimerBase::SharedPtr timer_;
127 
128  // Flag that indicates whether the manager is initialized
129  bool initialized_;
130 
131  // Flag that indicates hybrid planning has been canceled
132  std::atomic<bool> stop_hybrid_planning_;
133 
134  // Shared hybrid planning goal handle
135  std::shared_ptr<rclcpp_action::ServerGoalHandle<moveit_msgs::action::HybridPlanner>> hybrid_planning_goal_handle_;
136 
137  // Frequently updated feedback for the hybrid planning action requester
138  std::shared_ptr<moveit_msgs::action::HybridPlanner_Feedback> hybrid_planning_progess_;
139 
140  // Planning request action clients
141  rclcpp_action::Client<moveit_msgs::action::LocalPlanner>::SharedPtr local_planner_action_client_;
142  rclcpp_action::Client<moveit_msgs::action::GlobalPlanner>::SharedPtr global_planner_action_client_;
143 
144  // Hybrid planning request action server
145  rclcpp_action::Server<moveit_msgs::action::HybridPlanner>::SharedPtr hybrid_planning_request_server_;
146 
147  // Global solution subscriber
148  rclcpp::Subscription<moveit_msgs::msg::MotionPlanResponse>::SharedPtr global_solution_sub_;
149 
150  // This thread is used for long-running callbacks. It's a member so they do not go out of scope.
151  std::thread long_callback_thread_;
152 
153  // A unique callback group, to avoid mixing callbacks with other action servers
154  rclcpp::CallbackGroup::SharedPtr cb_group_;
155 };
156 } // namespace moveit::hybrid_planning
HybridPlanningManager(const rclcpp::NodeOptions &options)
Constructor.
std::shared_ptr< HybridPlanningManager > shared_from_this()
void executeHybridPlannerGoal(std::shared_ptr< rclcpp_action::ServerGoalHandle< moveit_msgs::action::HybridPlanner >> goal_handle)