Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
path_handler_selector_node.hpp
1 // Copyright (c) 2025 Maurice Alexander Purnawan
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PATH_HANDLER_SELECTOR_NODE_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PATH_HANDLER_SELECTOR_NODE_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <chrono>
21 
22 #include "std_msgs/msg/string.hpp"
23 
24 #include "behaviortree_cpp/action_node.h"
25 
26 #include "nav2_ros_common/lifecycle_node.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
45 class PathHandlerSelector : public BT::SyncActionNode
46 {
47 public:
55  const std::string & xml_tag_name,
56  const BT::NodeConfiguration & conf);
57 
62  static BT::PortsList providedPorts()
63  {
64  return {
65  BT::InputPort<std::string>(
66  "default_path_handler",
67  "the default path_handler to use if there is not any external topic message received."),
68 
69  BT::InputPort<std::string>(
70  "topic_name",
71  "path_handler_selector",
72  "the input topic name to select the path_handler"),
73 
74  BT::OutputPort<std::string>(
75  "selected_path_handler",
76  "Selected path_handler by subscription")
77  };
78  }
79 
80 private:
84  void initialize();
88  void createROSInterfaces();
89 
93  BT::NodeStatus tick() override;
94 
100  void callbackPathHandlerSelect(const std_msgs::msg::String::ConstSharedPtr & msg);
101 
102  nav2::Subscription<std_msgs::msg::String>::SharedPtr path_handler_selector_sub_;
103 
104  std::string last_selected_path_handler_;
105 
106  nav2::LifecycleNode::SharedPtr node_;
107  rclcpp::CallbackGroup::SharedPtr callback_group_;
108  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
109 
110  std::string topic_name_;
111  std::chrono::milliseconds bt_loop_duration_;
112 };
113 
114 } // namespace nav2_behavior_tree
115 
116 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PATH_HANDLER_SELECTOR_NODE_HPP_
The PathHandlerSelector behavior is used to switch the path handler of the controller server....
PathHandlerSelector(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::PathHandlerSelector.
static BT::PortsList providedPorts()
Creates list of BT ports.