18 #include "rclcpp/rclcpp.hpp"
19 #include "geometry_msgs/msg/pose_stamped.hpp"
20 #include "behaviortree_cpp_v3/decorator_node.h"
21 #include "nav2_behavior_tree/plugins/decorator/goal_updated_controller.hpp"
24 namespace nav2_behavior_tree
28 const std::string & name,
29 const BT::NodeConfiguration & conf)
30 : BT::DecoratorNode(name, conf)
34 BT::NodeStatus GoalUpdatedController::tick()
36 if (status() == BT::NodeStatus::IDLE) {
40 config().blackboard->get<std::vector<geometry_msgs::msg::PoseStamped>>(
"goals", goals_);
41 config().blackboard->get<geometry_msgs::msg::PoseStamped>(
"goal", goal_);
43 goal_was_updated_ =
true;
46 setStatus(BT::NodeStatus::RUNNING);
48 std::vector<geometry_msgs::msg::PoseStamped> current_goals;
49 config().blackboard->get<std::vector<geometry_msgs::msg::PoseStamped>>(
"goals", current_goals);
50 geometry_msgs::msg::PoseStamped current_goal;
51 config().blackboard->get<geometry_msgs::msg::PoseStamped>(
"goal", current_goal);
53 if (goal_ != current_goal || goals_ != current_goals) {
55 goals_ = current_goals;
56 goal_was_updated_ =
true;
62 if ((child_node_->status() == BT::NodeStatus::RUNNING) || goal_was_updated_) {
63 goal_was_updated_ =
false;
64 const BT::NodeStatus child_state = child_node_->executeTick();
66 switch (child_state) {
67 case BT::NodeStatus::RUNNING:
68 return BT::NodeStatus::RUNNING;
70 case BT::NodeStatus::SUCCESS:
71 return BT::NodeStatus::SUCCESS;
73 case BT::NodeStatus::FAILURE:
75 return BT::NodeStatus::FAILURE;
84 #include "behaviortree_cpp_v3/bt_factory.h"
85 BT_REGISTER_NODES(factory)
A BT::DecoratorNode that ticks its child if the goal was updated.
GoalUpdatedController(const std::string &name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::GoalUpdatedController.