19 #include "nav2_util/robot_utils.hpp"
20 #include "nav2_util/geometry_utils.hpp"
21 #include "nav2_ros_common/tf2_factories.hpp"
23 #include "nav2_behavior_tree/plugins/condition/distance_traveled_condition.hpp"
25 namespace nav2_behavior_tree
28 DistanceTraveledCondition::DistanceTraveledCondition(
29 const std::string & condition_name,
30 const BT::NodeConfiguration & conf)
31 : BT::ConditionNode(condition_name, conf),
33 transform_tolerance_(0.1)
39 getInput(
"distance", distance_);
41 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
42 tf_ = config().blackboard->get<nav2::TransformBuffer::SharedPtr>(
"tf_buffer");
43 node_->get_parameter(
"transform_tolerance", transform_tolerance_);
45 global_frame_ = BT::deconflictPortAndParamFrame<std::string>(
46 node_,
"global_frame",
this);
47 robot_base_frame_ = BT::deconflictPortAndParamFrame<std::string>(
48 node_,
"robot_base_frame",
this);
53 if (!BT::isStatusActive(status())) {
55 if (!nav2_util::getCurrentPose(
56 start_pose_, *tf_, global_frame_, robot_base_frame_,
57 transform_tolerance_))
59 RCLCPP_DEBUG(node_->get_logger(),
"Current robot pose is not available.");
61 return BT::NodeStatus::FAILURE;
65 geometry_msgs::msg::PoseStamped current_pose;
66 if (!nav2_util::getCurrentPose(
67 current_pose, *tf_, global_frame_, robot_base_frame_,
68 transform_tolerance_))
70 RCLCPP_DEBUG(node_->get_logger(),
"Current robot pose is not available.");
71 return BT::NodeStatus::FAILURE;
75 auto travelled = nav2_util::geometry_utils::euclidean_distance(
76 start_pose_.pose, current_pose.pose);
78 if (travelled < distance_) {
79 return BT::NodeStatus::FAILURE;
83 start_pose_ = current_pose;
85 return BT::NodeStatus::SUCCESS;
90 #include "behaviortree_cpp/bt_factory.h"
91 BT_REGISTER_NODES(factory)
A BT::ConditionNode that returns SUCCESS every time the robot travels a specified distance and FAILUR...
BT::NodeStatus tick() override
The main override required by a BT action.
void initialize()
Function to read parameters and initialize class variables.