Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
planner_selector_node.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2020 Pablo IƱigo Blasco
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PLANNER_SELECTOR_NODE_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PLANNER_SELECTOR_NODE_HPP_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "std_msgs/msg/string.hpp"
23 
24 #include "behaviortree_cpp_v3/action_node.h"
25 
26 #include "rclcpp/rclcpp.hpp"
27 
28 namespace nav2_behavior_tree
29 {
30 
38 class PlannerSelector : public BT::SyncActionNode
39 {
40 public:
48  const std::string & xml_tag_name,
49  const BT::NodeConfiguration & conf);
50 
55  static BT::PortsList providedPorts()
56  {
57  return {
58  BT::InputPort<std::string>(
59  "default_planner",
60  "the default planner to use if there is not any external topic message received."),
61 
62  BT::InputPort<std::string>(
63  "topic_name",
64  "planner_selector",
65  "the input topic name to select the planner"),
66 
67  BT::OutputPort<std::string>(
68  "selected_planner",
69  "Selected planner by subscription")
70  };
71  }
72 
73 private:
77  BT::NodeStatus tick() override;
78 
84  void callbackPlannerSelect(const std_msgs::msg::String::SharedPtr msg);
85 
86 
87  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr planner_selector_sub_;
88 
89  std::string last_selected_planner_;
90 
91  rclcpp::Node::SharedPtr node_;
92  rclcpp::CallbackGroup::SharedPtr callback_group_;
93  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
94 
95  std::string topic_name_;
96 };
97 
98 } // namespace nav2_behavior_tree
99 
100 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__PLANNER_SELECTOR_NODE_HPP_
The PlannerSelector behavior is used to switch the planner that will be used by the planner server....
PlannerSelector(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::PlannerSelector.
static BT::PortsList providedPorts()
Creates list of BT ports.