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