Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
controller_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__CONTROLLER_SELECTOR_NODE_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CONTROLLER_SELECTOR_NODE_HPP_
18 
19 #include <memory>
20 #include <string>
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 
39 class ControllerSelector : public BT::SyncActionNode
40 {
41 public:
49  const std::string & xml_tag_name,
50  const BT::NodeConfiguration & conf);
51 
56  static BT::PortsList providedPorts()
57  {
58  return {
59  BT::InputPort<std::string>(
60  "default_controller",
61  "the default controller to use if there is not any external topic message received."),
62 
63  BT::InputPort<std::string>(
64  "topic_name",
65  "controller_selector",
66  "the input topic name to select the controller"),
67 
68  BT::OutputPort<std::string>(
69  "selected_controller",
70  "Selected controller by subscription")
71  };
72  }
73 
74 private:
78  void initialize();
82  void createROSInterfaces();
83 
87  BT::NodeStatus tick() override;
88 
94  void callbackControllerSelect(const std_msgs::msg::String::SharedPtr msg);
95 
96  nav2::Subscription<std_msgs::msg::String>::SharedPtr controller_selector_sub_;
97 
98  std::string last_selected_controller_;
99 
100  nav2::LifecycleNode::SharedPtr node_;
101  rclcpp::CallbackGroup::SharedPtr callback_group_;
102  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
103 
104  std::string topic_name_;
105 };
106 
107 } // namespace nav2_behavior_tree
108 
109 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CONTROLLER_SELECTOR_NODE_HPP_
The ControllerSelector behavior is used to switch the controller that will be used by the controller ...
ControllerSelector(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::ControllerSelector.
static BT::PortsList providedPorts()
Creates list of BT ports.