15 #include "nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.hpp"
17 namespace nav2_behavior_tree
20 IsWithinPathTrackingBoundsCondition::IsWithinPathTrackingBoundsCondition(
21 const std::string & condition_name,
22 const BT::NodeConfiguration & conf)
23 : BT::ConditionNode(condition_name, conf)
25 auto node = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
26 logger_ = node->get_logger();
27 clock_ = node->get_clock();
32 getInput<double>(
"max_error_left", max_error_left_);
33 getInput<double>(
"max_error_right", max_error_right_);
34 getInput<double>(
"max_error_heading", max_error_heading_);
35 if (max_error_right_ < 0.0) {
36 RCLCPP_WARN_ONCE(logger_,
"max_error_right should be positive, using absolute value");
37 max_error_right_ = std::abs(max_error_right_);
39 if (max_error_left_ < 0.0) {
40 RCLCPP_WARN_ONCE(logger_,
"max_error_left should be positive, using absolute value");
41 max_error_left_ = std::abs(max_error_left_);
43 if (max_error_heading_ < 0.0) {
44 RCLCPP_WARN_ONCE(logger_,
"max_error_heading should be positive, using absolute value");
45 max_error_heading_ = std::abs(max_error_heading_);
51 if (!BT::isStatusActive(status())) {
57 if (!getInput<nav2_msgs::msg::TrackingFeedback>(
"tracking_feedback", tracking_feedback_)) {
58 return BT::NodeStatus::SUCCESS;
60 double position_tracking_error = tracking_feedback_.position_tracking_error;
61 double heading_tracking_error = tracking_feedback_.heading_tracking_error;
62 bool is_within_position_bounds;
63 if (position_tracking_error >= 0.0) {
64 is_within_position_bounds = (position_tracking_error <= max_error_left_);
66 is_within_position_bounds = (std::abs(position_tracking_error) <= max_error_right_);
69 bool is_within_heading_bounds = std::abs(heading_tracking_error) <= max_error_heading_;
71 if (is_within_position_bounds && is_within_heading_bounds) {
72 return BT::NodeStatus::SUCCESS;
78 "Robot is out of path tracking bounds! Position error: %.2f, Heading error: %.2f",
79 position_tracking_error, heading_tracking_error);
80 return BT::NodeStatus::FAILURE;
86 #include "behaviortree_cpp/bt_factory.h"
87 BT_REGISTER_NODES(factory)
90 "IsWithinPathTrackingBounds");
A BT::ConditionNode that returns SUCCESS when the current path tracking error is within specified bou...
BT::NodeStatus tick() override
The main override required by a BT action.
void initialize()
Function to read parameters and initialize class variables.