Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
goal_checker_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__GOAL_CHECKER_SELECTOR_NODE_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__GOAL_CHECKER_SELECTOR_NODE_HPP_
18 
19 #include <memory>
20 #include <string>
21 #include <chrono>
22 
23 #include "std_msgs/msg/string.hpp"
24 
25 #include "behaviortree_cpp/action_node.h"
26 
27 #include "nav2_ros_common/lifecycle_node.hpp"
28 
29 namespace nav2_behavior_tree
30 {
31 
46 class GoalCheckerSelector : public BT::SyncActionNode
47 {
48 public:
56  const std::string & xml_tag_name,
57  const BT::NodeConfiguration & conf);
58 
63  static BT::PortsList providedPorts()
64  {
65  return {
66  BT::InputPort<std::string>(
67  "default_goal_checker",
68  "the default goal_checker to use if there is not any external topic message received."),
69 
70  BT::InputPort<std::string>(
71  "topic_name",
72  "goal_checker_selector",
73  "the input topic name to select the goal_checker"),
74 
75  BT::OutputPort<std::string>(
76  "selected_goal_checker",
77  "Selected goal_checker by subscription")
78  };
79  }
80 
81 private:
85  void initialize();
89  void createROSInterfaces();
90 
94  BT::NodeStatus tick() override;
95 
101  void callbackGoalCheckerSelect(const std_msgs::msg::String::ConstSharedPtr & msg);
102 
103  nav2::Subscription<std_msgs::msg::String>::SharedPtr goal_checker_selector_sub_;
104 
105  std::string last_selected_goal_checker_;
106 
107  nav2::LifecycleNode::SharedPtr node_;
108  rclcpp::CallbackGroup::SharedPtr callback_group_;
109  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
110 
111  std::string topic_name_;
112  std::chrono::milliseconds bt_loop_duration_;
113 };
114 
115 } // namespace nav2_behavior_tree
116 
117 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__GOAL_CHECKER_SELECTOR_NODE_HPP_
The GoalCheckerSelector behavior is used to switch the goal checker of the controller server....
static BT::PortsList providedPorts()
Creates list of BT ports.
GoalCheckerSelector(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::GoalCheckerSelector.