18 #include "nav2_util/robot_utils.hpp"
19 #include "geometry_msgs/msg/pose_stamped.hpp"
20 #include "nav2_util/node_utils.hpp"
22 #include "nav2_behavior_tree/plugins/condition/goal_reached_condition.hpp"
24 namespace nav2_behavior_tree
27 GoalReachedCondition::GoalReachedCondition(
28 const std::string & condition_name,
29 const BT::NodeConfiguration & conf)
30 : BT::ConditionNode(condition_name, conf)
32 auto node = config().blackboard->get<rclcpp::Node::SharedPtr>(
"node");
34 robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string>(
35 node,
"robot_base_frame",
this);
45 node_ = config().blackboard->get<rclcpp::Node::SharedPtr>(
"node");
47 nav2_util::declare_parameter_if_not_declared(
48 node_,
"goal_reached_tol",
49 rclcpp::ParameterValue(0.25));
50 node_->get_parameter_or<
double>(
"goal_reached_tol", goal_reached_tol_, 0.25);
51 tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>(
"tf_buffer");
53 node_->get_parameter(
"transform_tolerance", transform_tolerance_);
58 if (!BT::isStatusActive(status())) {
63 return BT::NodeStatus::SUCCESS;
65 return BT::NodeStatus::FAILURE;
70 geometry_msgs::msg::PoseStamped goal;
71 getInput(
"goal", goal);
73 geometry_msgs::msg::PoseStamped current_pose;
74 if (!nav2_util::getCurrentPose(
75 current_pose, *tf_, goal.header.frame_id, robot_base_frame_, transform_tolerance_))
77 RCLCPP_DEBUG(node_->get_logger(),
"Current robot pose is not available.");
81 double dx = goal.pose.position.x - current_pose.pose.position.x;
82 double dy = goal.pose.position.y - current_pose.pose.position.y;
84 return (dx * dx + dy * dy) <= (goal_reached_tol_ * goal_reached_tol_);
89 #include "behaviortree_cpp/bt_factory.h"
90 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.