Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
goal_updater_node.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2020 Francisco Martin Rico
3 // Copyright (c) 2024 Angsa Robotics
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATER_NODE_HPP_
18 #define NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATER_NODE_HPP_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "behaviortree_cpp/decorator_node.h"
24 #include "behaviortree_cpp/json_export.h"
25 #include "geometry_msgs/msg/pose_stamped.hpp"
26 #include "nav_msgs/msg/goals.hpp"
27 #include "nav2_behavior_tree/bt_utils.hpp"
28 #include "nav2_behavior_tree/json_utils.hpp"
29 #include "rclcpp/rclcpp.hpp"
30 
31 
32 namespace nav2_behavior_tree
33 {
34 
41 class GoalUpdater : public BT::DecoratorNode
42 {
43 public:
50  const std::string & xml_tag_name,
51  const BT::NodeConfiguration & conf);
52 
57  static BT::PortsList providedPorts()
58  {
59  // Register JSON definitions for the types used in the ports
60  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
61  BT::RegisterJsonDefinition<nav_msgs::msg::Goals>();
62 
63  return {
64  BT::InputPort<geometry_msgs::msg::PoseStamped>("input_goal", "Original Goal"),
65  BT::InputPort<nav_msgs::msg::Goals>("input_goals", "Original Goals"),
66  BT::OutputPort<geometry_msgs::msg::PoseStamped>("output_goal",
67  "Received Goal by subscription"),
68  BT::OutputPort<nav_msgs::msg::Goals>("output_goals",
69  "Received Goals by subscription")
70  };
71  }
72 
73 private:
77  void initialize();
81  void createROSInterfaces();
86  BT::NodeStatus tick() override;
87 
92  void callback_updated_goal(const geometry_msgs::msg::PoseStamped::SharedPtr msg);
93 
98  void callback_updated_goals(const nav_msgs::msg::Goals::SharedPtr msg);
99 
100  nav2::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_sub_;
101  nav2::Subscription<nav_msgs::msg::Goals>::SharedPtr goals_sub_;
102 
103  geometry_msgs::msg::PoseStamped last_goal_received_;
104  bool last_goal_received_set_{false};
105  nav_msgs::msg::Goals last_goals_received_;
106  bool last_goals_received_set_{false};
107 
108  nav2::LifecycleNode::SharedPtr node_;
109  rclcpp::CallbackGroup::SharedPtr callback_group_;
110  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
111  std::string goal_updater_topic_;
112  std::string goals_updater_topic_;
113 };
114 
115 } // namespace nav2_behavior_tree
116 
117 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATER_NODE_HPP_
A BT::DecoratorNode that subscribes to a goal topic and updates the current goal on the blackboard.
GoalUpdater(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::GoalUpdater.
static BT::PortsList providedPorts()
Creates list of BT ports.