15 #include "nav2_behavior_tree/plugins/condition/are_poses_near_condition.hpp"
17 namespace nav2_behavior_tree
20 ArePosesNearCondition::ArePosesNearCondition(
21 const std::string & condition_name,
22 const BT::NodeConfiguration & conf)
23 : BT::ConditionNode(condition_name, conf)
25 auto node = config().blackboard->get<rclcpp::Node::SharedPtr>(
"node");
26 global_frame_ = BT::deconflictPortAndParamFrame<std::string>(
27 node,
"global_frame",
this);
32 node_ = config().blackboard->get<rclcpp::Node::SharedPtr>(
"node");
33 tf_ = config().blackboard->get<std::shared_ptr<tf2_ros::Buffer>>(
"tf_buffer");
34 node_->get_parameter(
"transform_tolerance", transform_tolerance_);
39 if (!BT::isStatusActive(status())) {
44 return BT::NodeStatus::SUCCESS;
46 return BT::NodeStatus::FAILURE;
51 geometry_msgs::msg::PoseStamped pose1, pose2;
53 getInput(
"ref_pose", pose1);
54 getInput(
"target_pose", pose2);
55 getInput(
"tolerance", tol);
57 if (pose1.header.frame_id != pose2.header.frame_id) {
58 if (!nav2_util::transformPoseInTargetFrame(
59 pose1, pose1, *tf_, global_frame_, transform_tolerance_) ||
60 !nav2_util::transformPoseInTargetFrame(
61 pose2, pose2, *tf_, global_frame_, transform_tolerance_))
63 RCLCPP_ERROR(node_->get_logger(),
"Failed to transform poses to the same frame");
68 double dx = pose1.pose.position.x - pose2.pose.position.x;
69 double dy = pose1.pose.position.y - pose2.pose.position.y;
70 return (dx * dx + dy * dy) <= (tol * tol);
75 #include "behaviortree_cpp/bt_factory.h"
76 BT_REGISTER_NODES(factory)
A BT::ConditionNode that returns SUCCESS when a specified goal is reached and FAILURE otherwise.
BT::NodeStatus tick() override
The main override required by a BT action.
bool arePosesNearby()
Checks if the current robot pose lies within a given distance from the goal.
void initialize()
Function to read parameters and initialize class variables.