18 #include "nav2_util/robot_utils.hpp"
19 #include "geometry_msgs/msg/pose_stamped.hpp"
20 #include "nav2_ros_common/node_utils.hpp"
21 #include "nav2_ros_common/tf2_factories.hpp"
23 #include "nav2_behavior_tree/plugins/condition/goal_reached_condition.hpp"
25 namespace nav2_behavior_tree
28 GoalReachedCondition::GoalReachedCondition(
29 const std::string & condition_name,
30 const BT::NodeConfiguration & conf)
31 : BT::ConditionNode(condition_name, conf)
33 auto node = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
35 robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string>(
36 node,
"robot_base_frame",
this);
46 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
48 goal_reached_tol_ = node_->declare_or_get_parameter(
"goal_reached_tol", 0.25);
49 tf_ = config().blackboard->get<nav2::TransformBuffer::SharedPtr>(
"tf_buffer");
51 node_->get_parameter(
"transform_tolerance", transform_tolerance_);
56 if (!BT::isStatusActive(status())) {
61 return BT::NodeStatus::SUCCESS;
63 return BT::NodeStatus::FAILURE;
68 geometry_msgs::msg::PoseStamped goal;
69 getInput(
"goal", goal);
71 geometry_msgs::msg::PoseStamped current_pose;
72 if (!nav2_util::getCurrentPose(
73 current_pose, *tf_, goal.header.frame_id, robot_base_frame_, transform_tolerance_))
75 RCLCPP_DEBUG(node_->get_logger(),
"Current robot pose is not available.");
79 double dx = goal.pose.position.x - current_pose.pose.position.x;
80 double dy = goal.pose.position.y - current_pose.pose.position.y;
82 return (dx * dx + dy * dy) <= (goal_reached_tol_ * goal_reached_tol_);
87 #include "behaviortree_cpp/bt_factory.h"
88 BT_REGISTER_NODES(factory)
A BT::ConditionNode that returns SUCCESS when a specified goal is reached and FAILURE otherwise.
void initialize()
Function to read parameters and initialize class variables.
void cleanup()
Cleanup function.
BT::NodeStatus tick() override
The main override required by a BT action.
~GoalReachedCondition() override
A destructor for nav2_behavior_tree::GoalReachedCondition.
bool isGoalReached()
Checks if the current robot pose lies within a given distance from the goal.