Nav2 Navigation Stack - lyrical  lyrical
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 
48 class GoalUpdater : public BT::DecoratorNode
49 {
50 public:
57  const std::string & xml_tag_name,
58  const BT::NodeConfiguration & conf);
59 
64  static BT::PortsList providedPorts()
65  {
66  // Register JSON definitions for the types used in the ports
67  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
68  BT::RegisterJsonDefinition<nav_msgs::msg::Goals>();
69 
70  return {
71  BT::InputPort<geometry_msgs::msg::PoseStamped>("input_goal", "Original Goal"),
72  BT::InputPort<nav_msgs::msg::Goals>("input_goals", "Original Goals"),
73  BT::OutputPort<geometry_msgs::msg::PoseStamped>(
74  "output_goal",
75  "Received Goal by subscription"),
76  BT::OutputPort<nav_msgs::msg::Goals>(
77  "output_goals",
78  "Received Goals by subscription")
79  };
80  }
81 
82 private:
86  void initialize();
90  void createROSInterfaces();
95  BT::NodeStatus tick() override;
96 
101  void callback_updated_goal(const geometry_msgs::msg::PoseStamped::ConstSharedPtr & msg);
102 
107  void callback_updated_goals(const nav_msgs::msg::Goals::ConstSharedPtr & msg);
108 
109  nav2::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_sub_;
110  nav2::Subscription<nav_msgs::msg::Goals>::SharedPtr goals_sub_;
111 
112  geometry_msgs::msg::PoseStamped last_goal_received_;
113  bool last_goal_received_set_{false};
114  nav_msgs::msg::Goals last_goals_received_;
115  bool last_goals_received_set_{false};
116 
117  nav2::LifecycleNode::SharedPtr node_;
118  rclcpp::CallbackGroup::SharedPtr callback_group_;
119  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
120  std::string goal_updater_topic_;
121  std::string goals_updater_topic_;
122  std::chrono::milliseconds bt_loop_duration_;
123 };
124 
125 } // namespace nav2_behavior_tree
126 
127 #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.