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 #include <chrono>
23 
24 #include "behaviortree_cpp/decorator_node.h"
25 #include "behaviortree_cpp/json_export.h"
26 #include "geometry_msgs/msg/pose_stamped.hpp"
27 #include "nav_msgs/msg/goals.hpp"
28 #include "nav2_behavior_tree/bt_utils.hpp"
29 #include "nav2_behavior_tree/json_utils.hpp"
30 #include "rclcpp/rclcpp.hpp"
31 
32 
33 namespace nav2_behavior_tree
34 {
35 
42 class GoalUpdater : public BT::DecoratorNode
43 {
44 public:
51  const std::string & xml_tag_name,
52  const BT::NodeConfiguration & conf);
53 
58  static BT::PortsList providedPorts()
59  {
60  // Register JSON definitions for the types used in the ports
61  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
62  BT::RegisterJsonDefinition<nav_msgs::msg::Goals>();
63 
64  return {
65  BT::InputPort<geometry_msgs::msg::PoseStamped>("input_goal", "Original Goal"),
66  BT::InputPort<nav_msgs::msg::Goals>("input_goals", "Original Goals"),
67  BT::OutputPort<geometry_msgs::msg::PoseStamped>("output_goal",
68  "Received Goal by subscription"),
69  BT::OutputPort<nav_msgs::msg::Goals>("output_goals",
70  "Received Goals by subscription")
71  };
72  }
73 
74 private:
78  void initialize();
82  void createROSInterfaces();
87  BT::NodeStatus tick() override;
88 
93  void callback_updated_goal(const geometry_msgs::msg::PoseStamped::SharedPtr msg);
94 
99  void callback_updated_goals(const nav_msgs::msg::Goals::SharedPtr msg);
100 
101  nav2::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_sub_;
102  nav2::Subscription<nav_msgs::msg::Goals>::SharedPtr goals_sub_;
103 
104  geometry_msgs::msg::PoseStamped last_goal_received_;
105  bool last_goal_received_set_{false};
106  nav_msgs::msg::Goals last_goals_received_;
107  bool last_goals_received_set_{false};
108 
109  nav2::LifecycleNode::SharedPtr node_;
110  rclcpp::CallbackGroup::SharedPtr callback_group_;
111  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
112  std::string goal_updater_topic_;
113  std::string goals_updater_topic_;
114  std::chrono::milliseconds bt_loop_duration_;
115 };
116 
117 } // namespace nav2_behavior_tree
118 
119 #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.