Skip to content

Commit 7a02bf6

Browse files
committed
Styling changes
Signed-off-by: silanus23 <[email protected]>
1 parent 6b4e7f8 commit 7a02bf6

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string>
1919
#include <memory>
2020
#include <mutex>
21+
#include <limits>
2122

2223
#include "behaviortree_cpp/condition_node.h"
2324
#include "nav2_ros_common/lifecycle_node.hpp"
@@ -51,12 +52,12 @@ class IsWithinPathTrackingBoundsCondition : public BT::ConditionNode
5152
static BT::PortsList providedPorts()
5253
{
5354
return {
54-
BT::InputPort<double>("max_error", 0.5, "Maximum allowed tracking error")
55+
BT::InputPort<double>("max_error", "Maximum allowed tracking error")
5556
};
5657
}
5758

5859
private:
59-
nav2::LifecycleNode::SharedPtr node_;
60+
rclcpp::Logger logger_{rclcpp::get_logger("is_within_path_tracking_bounds_node")};
6061
rclcpp::CallbackGroup::SharedPtr callback_group_;
6162
rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
6263
rclcpp::Subscription<nav2_msgs::msg::TrackingFeedback>::SharedPtr tracking_feedback_sub_;

nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ IsWithinPathTrackingBoundsCondition::IsWithinPathTrackingBoundsCondition(
2121
const std::string & condition_name,
2222
const BT::NodeConfiguration & conf)
2323
: BT::ConditionNode(condition_name, conf),
24-
last_error_(0.0)
24+
last_error_(std::numeric_limits<double>::max())
2525
{
26-
node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node");
27-
callback_group_ = node_->create_callback_group(
26+
auto node = config().blackboard->get<nav2::LifecycleNode::SharedPtr>("node");
27+
callback_group_ = node->create_callback_group(
2828
rclcpp::CallbackGroupType::MutuallyExclusive,
2929
false);
30-
callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
30+
callback_group_executor_.add_callback_group(callback_group_, node->get_node_base_interface());
3131

32-
tracking_feedback_sub_ = node_->create_subscription<nav2_msgs::msg::TrackingFeedback>(
33-
"/tracking_feedback",
32+
tracking_feedback_sub_ = node->create_subscription<nav2_msgs::msg::TrackingFeedback>(
33+
"tracking_feedback",
3434
std::bind(&IsWithinPathTrackingBoundsCondition::trackingFeedbackCallback, this,
3535
std::placeholders::_1),
3636
rclcpp::SystemDefaultsQoS(),
@@ -39,8 +39,8 @@ IsWithinPathTrackingBoundsCondition::IsWithinPathTrackingBoundsCondition(
3939
bt_loop_duration_ =
4040
config().blackboard->template get<std::chrono::milliseconds>("bt_loop_duration");
4141

42-
RCLCPP_DEBUG(node_->get_logger(), "Initialized IsWithinPathTrackingBoundsCondition BT node");
43-
RCLCPP_INFO_ONCE(node_->get_logger(), "Waiting for tracking error");
42+
RCLCPP_INFO_ONCE(logger_, "Waiting for tracking error");
43+
RCLCPP_INFO(logger_, "Initialized IsWithinPathTrackingBoundsCondition BT node");
4444
initialize();
4545
}
4646

@@ -64,15 +64,19 @@ BT::NodeStatus IsWithinPathTrackingBoundsCondition::tick()
6464
callback_group_executor_.spin_all(bt_loop_duration_);
6565

6666
if (!getInput("max_error", max_error_)) {
67-
RCLCPP_ERROR(node_->get_logger(), "max_error parameter not provided");
68-
max_error_ = 1.0; // Default fallback
67+
RCLCPP_ERROR(logger_, "max_error parameter not provided");
68+
return BT::NodeStatus::FAILURE;
6969
}
7070

7171
if (max_error_ < 0.0) {
72-
RCLCPP_WARN(node_->get_logger(), "max_error should be positive, using absolute value");
72+
RCLCPP_WARN(logger_, "max_error should be positive, using absolute value");
7373
max_error_ = std::abs(max_error_);
7474
}
7575

76+
if (last_error_ == std::numeric_limits<double>::max()) {
77+
RCLCPP_WARN(logger_, "No tracking feedback received yet.");
78+
}
79+
7680
if (last_error_ <= max_error_) {
7781
return BT::NodeStatus::SUCCESS;
7882
}

0 commit comments

Comments
 (0)