Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
goal_updater_node.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2020 Francisco Martin Rico
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__DECORATOR__GOAL_UPDATER_NODE_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__GOAL_UPDATER_NODE_HPP_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "geometry_msgs/msg/pose_stamped.hpp"
23 
24 #include "behaviortree_cpp/decorator_node.h"
25 
26 #include "behaviortree_cpp/json_export.h"
27 #include "nav2_behavior_tree/json_utils.hpp"
28 #include "rclcpp/rclcpp.hpp"
29 
30 namespace nav2_behavior_tree
31 {
32 
44 class GoalUpdater : public BT::DecoratorNode
45 {
46 public:
53  const std::string & xml_tag_name,
54  const BT::NodeConfiguration & conf);
55 
60  static BT::PortsList providedPorts()
61  {
62  // Register JSON definitions for the types used in the ports
63  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
64 
65  return {
66  BT::InputPort<geometry_msgs::msg::PoseStamped>("input_goal", "Original Goal"),
67  BT::OutputPort<geometry_msgs::msg::PoseStamped>(
68  "output_goal",
69  "Received Goal by subscription"),
70  };
71  }
72 
73 private:
78  BT::NodeStatus tick() override;
79 
84  void callback_updated_goal(const geometry_msgs::msg::PoseStamped::SharedPtr msg);
85 
86  rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_sub_;
87 
88  geometry_msgs::msg::PoseStamped last_goal_received_;
89 
90  rclcpp::Node::SharedPtr node_;
91  rclcpp::CallbackGroup::SharedPtr callback_group_;
92  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
93 };
94 
95 } // namespace nav2_behavior_tree
96 
97 #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.