Skip to content

Commit 0ffd668

Browse files
committed
Updating to TrackingFeedback and styling issues
Signed-off-by: silanus23 <berkantali23@outlook.com>
1 parent fcc2629 commit 0ffd668

File tree

4 files changed

+47
-54
lines changed

4 files changed

+47
-54
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@
1818
#include <string>
1919
#include <memory>
2020
#include <mutex>
21+
2122
#include "behaviortree_cpp/condition_node.h"
2223
#include "nav2_ros_common/lifecycle_node.hpp"
23-
#include "nav2_msgs/msg/tracking_error_feedback.hpp"
24+
#include "nav2_msgs/msg/tracking_feedback.hpp"
2425
#include "rclcpp/rclcpp.hpp"
25-
#include "nav2_ros_common/lifecycle_node.hpp"
2626
#include "sensor_msgs/msg/battery_state.hpp"
27-
#include "behaviortree_cpp/condition_node.h"
2827

2928
namespace nav2_behavior_tree
3029
{
3130

3231
/**
33-
* @brief A BT::ConditionNode that subscribes to /tracking_error and returns SUCCESS
32+
* @brief A BT::ConditionNode that subscribes to /tracking_feedback and returns SUCCESS
3433
* if the error is within the max_error input port, FAILURE otherwise
3534
*/
3635
class IsWithinPathTrackingBoundsCondition : public BT::ConditionNode
@@ -61,12 +60,12 @@ class IsWithinPathTrackingBoundsCondition : public BT::ConditionNode
6160
nav2::LifecycleNode::SharedPtr node_;
6261
rclcpp::CallbackGroup::SharedPtr callback_group_;
6362
rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
64-
rclcpp::Subscription<nav2_msgs::msg::TrackingErrorFeedback>::SharedPtr tracking_error_sub_;
63+
rclcpp::Subscription<nav2_msgs::msg::TrackingFeedback>::SharedPtr tracking_feedback_sub_;
6564
double last_error_{0.0};
6665
double max_error_{1.5};
6766
std::chrono::milliseconds bt_loop_duration_;
6867

69-
void trackingErrorCallback(const nav2_msgs::msg::TrackingErrorFeedback::SharedPtr msg);
68+
void trackingFeedbackCallback(const nav2_msgs::msg::TrackingFeedback::SharedPtr msg);
7069
};
7170

7271
} // namespace nav2_behavior_tree

‎nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ IsWithinPathTrackingBoundsCondition::IsWithinPathTrackingBoundsCondition(
2929
false);
3030
callback_group_executor_.add_callback_group(callback_group_, node_->get_node_base_interface());
3131

32-
tracking_error_sub_ = node_->create_subscription<nav2_msgs::msg::TrackingErrorFeedback>(
33-
"/tracking_error",
34-
std::bind(&IsWithinPathTrackingBoundsCondition::trackingErrorCallback, this,
32+
tracking_feedback_sub_ = node_->create_subscription<nav2_msgs::msg::TrackingFeedback>(
33+
"/tracking_feedback",
34+
std::bind(&IsWithinPathTrackingBoundsCondition::trackingFeedbackCallback, this,
3535
std::placeholders::_1),
3636
rclcpp::SystemDefaultsQoS(),
3737
callback_group_);
@@ -44,8 +44,8 @@ IsWithinPathTrackingBoundsCondition::IsWithinPathTrackingBoundsCondition(
4444
initialize();
4545
}
4646

47-
void IsWithinPathTrackingBoundsCondition::trackingErrorCallback(
48-
const nav2_msgs::msg::TrackingErrorFeedback::SharedPtr msg)
47+
void IsWithinPathTrackingBoundsCondition::trackingFeedbackCallback(
48+
const nav2_msgs::msg::TrackingFeedback::SharedPtr msg)
4949
{
5050
last_error_ = msg->tracking_error;
5151
}
@@ -74,6 +74,6 @@ BT::NodeStatus IsWithinPathTrackingBoundsCondition::tick()
7474
#include "behaviortree_cpp/bt_factory.h"
7575
BT_REGISTER_NODES(factory)
7676
{
77-
factory.registerNodeType<nav2_behavior_tree::IsWithinPathTrackingBoundsCondition>
78-
("IsWithinPathTrackingBounds>");
77+
factory.registerNodeType<nav2_behavior_tree::IsWithinPathTrackingBoundsCondition>(
78+
"IsWithinPathTrackingBounds");
7979
}

‎nav2_behavior_tree/test/plugins/condition/CMakeLists.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ plugin_add_test(test_condition_is_path_valid test_is_path_valid.cpp nav2_is_path
2828

2929
plugin_add_test(test_are_error_codes_present test_are_error_codes_present.cpp nav2_would_a_controller_recovery_help_condition_bt_node)
3030

31-
plugin_add_test(test_condition_is_within_path_tracking_bounds test_is_within_path_tracking_bounds.cpp nav2_is_within_path_tracking_bounds_condition_bt_node)
31+
plugin_add_test(test_condition_is_within_path_tracking_bounds test_is_within_path_tracking_bounds.cpp
32+
nav2_is_within_path_tracking_bounds_condition_bt_node)
3233

3334
plugin_add_test(test_would_a_controller_recovery_help
3435
test_would_a_controller_recovery_help.cpp

‎nav2_behavior_tree/test/plugins/condition/test_is_within_path_tracking_bounds.cpp‎

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <string>
1919
#include <chrono>
2020

21-
#include "nav2_msgs/msg/tracking_error_feedback.hpp"
21+
#include "nav2_msgs/msg/tracking_feedback.hpp"
2222

2323
#include "utils/test_behavior_tree_fixture.hpp"
2424
#include "nav2_behavior_tree/plugins/condition/is_within_path_tracking_bounds_condition.hpp"
@@ -48,17 +48,17 @@ class IsWithinPathTrackingBoundsConditionTestFixture : public ::testing::Test
4848
factory_->registerNodeType<nav2_behavior_tree::IsWithinPathTrackingBoundsCondition>(
4949
"IsWithinPathTrackingBounds");
5050

51-
tracking_error_pub_ = node_->create_publisher<nav2_msgs::msg::TrackingErrorFeedback>(
52-
"/tracking_error",
51+
tracking_feedback_pub_ = node_->create_publisher<nav2_msgs::msg::TrackingFeedback>(
52+
"/tracking_feedback",
5353
rclcpp::SystemDefaultsQoS());
54-
tracking_error_pub_->on_activate();
54+
tracking_feedback_pub_->on_activate();
5555
}
5656

5757
static void TearDownTestCase()
5858
{
5959
delete config_;
6060
config_ = nullptr;
61-
tracking_error_pub_.reset();
61+
tracking_feedback_pub_.reset();
6262
node_.reset();
6363
factory_.reset();
6464
executor_.reset();
@@ -69,7 +69,7 @@ class IsWithinPathTrackingBoundsConditionTestFixture : public ::testing::Test
6969
static rclcpp::executors::SingleThreadedExecutor::SharedPtr executor_;
7070
static BT::NodeConfiguration * config_;
7171
static std::shared_ptr<BT::BehaviorTreeFactory> factory_;
72-
static nav2::Publisher<nav2_msgs::msg::TrackingErrorFeedback>::SharedPtr tracking_error_pub_;
72+
static nav2::Publisher<nav2_msgs::msg::TrackingFeedback>::SharedPtr tracking_feedback_pub_;
7373
};
7474

7575
nav2::LifecycleNode::SharedPtr IsWithinPathTrackingBoundsConditionTestFixture::node_ = nullptr;
@@ -78,8 +78,8 @@ IsWithinPathTrackingBoundsConditionTestFixture::executor_ = nullptr;
7878
BT::NodeConfiguration * IsWithinPathTrackingBoundsConditionTestFixture::config_ = nullptr;
7979
std::shared_ptr<BT::BehaviorTreeFactory> IsWithinPathTrackingBoundsConditionTestFixture::factory_ =
8080
nullptr;
81-
nav2::Publisher<nav2_msgs::msg::TrackingErrorFeedback>::SharedPtr
82-
IsWithinPathTrackingBoundsConditionTestFixture::tracking_error_pub_ = nullptr;
81+
nav2::Publisher<nav2_msgs::msg::TrackingFeedback>::SharedPtr
82+
IsWithinPathTrackingBoundsConditionTestFixture::tracking_feedback_pub_ = nullptr;
8383

8484
TEST_F(IsWithinPathTrackingBoundsConditionTestFixture, test_behavior_within_bounds)
8585
{
@@ -94,30 +94,30 @@ TEST_F(IsWithinPathTrackingBoundsConditionTestFixture, test_behavior_within_boun
9494
auto tree = factory_->createTreeFromText(xml_txt, config_->blackboard);
9595

9696
// Test case 1: Error is within bounds (should return SUCCESS)
97-
nav2_msgs::msg::TrackingErrorFeedback tracking_error_msg;
98-
tracking_error_msg.tracking_error = 0.5;
99-
tracking_error_pub_->publish(tracking_error_msg);
97+
nav2_msgs::msg::TrackingFeedback tracking_feedback_msg;
98+
tracking_feedback_msg.tracking_error = 0.5;
99+
tracking_feedback_pub_->publish(tracking_feedback_msg);
100100
std::this_thread::sleep_for(std::chrono::milliseconds(100));
101101
executor_->spin_some();
102102
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
103103

104104
// Test case 2: Error is exactly at the boundary (should return SUCCESS)
105-
tracking_error_msg.tracking_error = 1.0;
106-
tracking_error_pub_->publish(tracking_error_msg);
105+
tracking_feedback_msg.tracking_error = 1.0;
106+
tracking_feedback_pub_->publish(tracking_feedback_msg);
107107
std::this_thread::sleep_for(std::chrono::milliseconds(100));
108108
executor_->spin_some();
109109
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
110110

111111
// Test case 3: Error exceeds bounds (should return FAILURE)
112-
tracking_error_msg.tracking_error = 1.5;
113-
tracking_error_pub_->publish(tracking_error_msg);
112+
tracking_feedback_msg.tracking_error = 1.5;
113+
tracking_feedback_pub_->publish(tracking_feedback_msg);
114114
std::this_thread::sleep_for(std::chrono::milliseconds(100));
115115
executor_->spin_some();
116116
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::FAILURE);
117117

118118
// Test case 4: Zero error (should return SUCCESS)
119-
tracking_error_msg.tracking_error = 0.0;
120-
tracking_error_pub_->publish(tracking_error_msg);
119+
tracking_feedback_msg.tracking_error = 0.0;
120+
tracking_feedback_pub_->publish(tracking_feedback_msg);
121121
std::this_thread::sleep_for(std::chrono::milliseconds(100));
122122
executor_->spin_some();
123123
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
@@ -136,26 +136,19 @@ TEST_F(IsWithinPathTrackingBoundsConditionTestFixture, test_behavior_different_m
136136
auto tree = factory_->createTreeFromText(xml_txt, config_->blackboard);
137137

138138
// Test case 1: Error is within smaller bounds (should return SUCCESS)
139-
nav2_msgs::msg::TrackingErrorFeedback tracking_error_msg;
140-
tracking_error_msg.tracking_error = 0.1;
141-
tracking_error_pub_->publish(tracking_error_msg);
139+
nav2_msgs::msg::TrackingFeedback tracking_feedback_msg;
140+
tracking_feedback_msg.tracking_error = 0.1;
141+
tracking_feedback_pub_->publish(tracking_feedback_msg);
142142
std::this_thread::sleep_for(std::chrono::milliseconds(100));
143143
executor_->spin_some();
144144
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
145145

146146
// Test case 2: Error exceeds smaller bounds (should return FAILURE)
147-
tracking_error_msg.tracking_error = 0.3;
148-
tracking_error_pub_->publish(tracking_error_msg);
147+
tracking_feedback_msg.tracking_error = 0.3;
148+
tracking_feedback_pub_->publish(tracking_feedback_msg);
149149
std::this_thread::sleep_for(std::chrono::milliseconds(100));
150150
executor_->spin_some();
151151
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::FAILURE);
152-
153-
// Test case 3: Error is exactly at the boundary (should return SUCCESS)
154-
tracking_error_msg.tracking_error = 0.2;
155-
tracking_error_pub_->publish(tracking_error_msg);
156-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
157-
executor_->spin_some();
158-
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
159152
}
160153

161154
TEST_F(IsWithinPathTrackingBoundsConditionTestFixture, test_behavior_large_error_values)
@@ -171,16 +164,16 @@ TEST_F(IsWithinPathTrackingBoundsConditionTestFixture, test_behavior_large_error
171164
auto tree = factory_->createTreeFromText(xml_txt, config_->blackboard);
172165

173166
// Test case 1: Large error within bounds (should return SUCCESS)
174-
nav2_msgs::msg::TrackingErrorFeedback tracking_error_msg;
175-
tracking_error_msg.tracking_error = 4.9;
176-
tracking_error_pub_->publish(tracking_error_msg);
167+
nav2_msgs::msg::TrackingFeedback tracking_feedback_msg;
168+
tracking_feedback_msg.tracking_error = 4.9;
169+
tracking_feedback_pub_->publish(tracking_feedback_msg);
177170
std::this_thread::sleep_for(std::chrono::milliseconds(100));
178171
executor_->spin_some();
179172
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
180173

181174
// Test case 2: Very large error exceeding bounds (should return FAILURE)
182-
tracking_error_msg.tracking_error = 10.0;
183-
tracking_error_pub_->publish(tracking_error_msg);
175+
tracking_feedback_msg.tracking_error = 10.0;
176+
tracking_feedback_pub_->publish(tracking_feedback_msg);
184177
std::this_thread::sleep_for(std::chrono::milliseconds(100));
185178
executor_->spin_some();
186179
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::FAILURE);
@@ -199,16 +192,16 @@ TEST_F(IsWithinPathTrackingBoundsConditionTestFixture, test_behavior_edge_cases)
199192
auto tree = factory_->createTreeFromText(xml_txt, config_->blackboard);
200193

201194
// Test case 1: Zero max_error with zero tracking error (should return SUCCESS)
202-
nav2_msgs::msg::TrackingErrorFeedback tracking_error_msg;
203-
tracking_error_msg.tracking_error = 0.0;
204-
tracking_error_pub_->publish(tracking_error_msg);
195+
nav2_msgs::msg::TrackingFeedback tracking_feedback_msg;
196+
tracking_feedback_msg.tracking_error = 0.0;
197+
tracking_feedback_pub_->publish(tracking_feedback_msg);
205198
std::this_thread::sleep_for(std::chrono::milliseconds(100));
206199
executor_->spin_some();
207200
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::SUCCESS);
208201

209202
// Test case 2: Zero max_error with any positive tracking error (should return FAILURE)
210-
tracking_error_msg.tracking_error = 0.001;
211-
tracking_error_pub_->publish(tracking_error_msg);
203+
tracking_feedback_msg.tracking_error = 0.001;
204+
tracking_feedback_pub_->publish(tracking_feedback_msg);
212205
std::this_thread::sleep_for(std::chrono::milliseconds(100));
213206
executor_->spin_some();
214207
EXPECT_EQ(tree.tickOnce(), BT::NodeStatus::FAILURE);
@@ -227,4 +220,4 @@ int main(int argc, char ** argv)
227220
rclcpp::shutdown();
228221

229222
return all_successful;
230-
}
223+
}

0 commit comments

Comments
 (0)