Skip to content

Commit 86ab643

Browse files
committed
Add validation tests for waypoint_statuses output of RemoveInCollisionGoals and RemovePassedGoals
Signed-off-by: zz990099 <771647586@qq.com>
1 parent 8c32a8f commit 86ab643

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed

nav2_behavior_tree/test/plugins/action/test_remove_in_collision_goals_action.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,71 @@ TEST_F(RemoveInCollisionGoalsTestFixture, test_tick_remove_in_collision_goals_su
181181
EXPECT_EQ(output_poses.goals[2], poses.goals[2]);
182182
}
183183

184+
TEST_F(RemoveInCollisionGoalsTestFixture,
185+
test_tick_remove_in_collision_goals_success_and_output_waypoint_statues)
186+
{
187+
// create tree
188+
std::string xml_txt =
189+
R"(
190+
<root BTCPP_format="4">
191+
<BehaviorTree ID="MainTree">
192+
<RemoveInCollisionGoals service_name="/global_costmap/get_cost_global_costmap" input_goals="{goals}" output_goals="{goals}" cost_threshold="253" waypoint_statuses_id="waypoint_statuses"/>
193+
</BehaviorTree>
194+
</root>)";
195+
196+
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
197+
198+
// create new goal and set it on blackboard
199+
nav_msgs::msg::Goals poses;
200+
poses.goals.resize(4);
201+
poses.goals[0].pose.position.x = 0.0;
202+
poses.goals[0].pose.position.y = 0.0;
203+
204+
poses.goals[1].pose.position.x = 0.5;
205+
poses.goals[1].pose.position.y = 0.0;
206+
207+
poses.goals[2].pose.position.x = 1.0;
208+
poses.goals[2].pose.position.y = 0.0;
209+
210+
poses.goals[3].pose.position.x = 2.0;
211+
poses.goals[3].pose.position.y = 0.0;
212+
213+
config_->blackboard->set("goals", poses);
214+
215+
// create waypoint_statuses and set it on blackboard
216+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses(poses.goals.size());
217+
for (size_t i = 0 ; i < waypoint_statuses.size() ; ++i) {
218+
waypoint_statuses[i].goal = poses.goals[i];
219+
waypoint_statuses[i].index = i;
220+
}
221+
config_->blackboard->set("waypoint_statuses", waypoint_statuses);
222+
223+
// tick until node is not running
224+
tree_->rootNode()->executeTick();
225+
while (tree_->rootNode()->status() == BT::NodeStatus::RUNNING) {
226+
tree_->rootNode()->executeTick();
227+
}
228+
229+
EXPECT_EQ(tree_->rootNode()->status(), BT::NodeStatus::SUCCESS);
230+
// check that it removed the point in range
231+
nav_msgs::msg::Goals output_poses;
232+
EXPECT_TRUE(config_->blackboard->get("goals", output_poses));
233+
234+
EXPECT_EQ(output_poses.goals.size(), 3u);
235+
EXPECT_EQ(output_poses.goals[0], poses.goals[0]);
236+
EXPECT_EQ(output_poses.goals[1], poses.goals[1]);
237+
EXPECT_EQ(output_poses.goals[2], poses.goals[2]);
238+
239+
// check the waypoint_statuses
240+
std::vector<nav2_msgs::msg::WaypointStatus> output_waypoint_statuses;
241+
EXPECT_TRUE(config_->blackboard->get("waypoint_statuses", output_waypoint_statuses));
242+
EXPECT_EQ(output_waypoint_statuses.size(), 4u);
243+
EXPECT_EQ(output_waypoint_statuses[0].waypoint_status, nav2_msgs::msg::WaypointStatus::PENDING);
244+
EXPECT_EQ(output_waypoint_statuses[1].waypoint_status, nav2_msgs::msg::WaypointStatus::PENDING);
245+
EXPECT_EQ(output_waypoint_statuses[2].waypoint_status, nav2_msgs::msg::WaypointStatus::PENDING);
246+
EXPECT_EQ(output_waypoint_statuses[3].waypoint_status, nav2_msgs::msg::WaypointStatus::SKIPPED);
247+
}
248+
184249
TEST_F(RemoveInCollisionGoalsTestFixture, test_tick_remove_in_collision_goals_fail)
185250
{
186251
// create tree

nav2_behavior_tree/test/plugins/action/test_remove_passed_goals_action.cpp

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class RemovePassedGoalsTestFixture : public ::testing::Test
3939

4040
config_ = new BT::NodeConfiguration();
4141
transform_handler_ = std::make_shared<nav2_behavior_tree::TransformHandler>(node_);
42+
transform_handler_->activate();
4243

4344
// Create the blackboard that will be shared by all of the nodes in the tree
4445
config_->blackboard = BT::Blackboard::create();
@@ -98,7 +99,6 @@ TEST_F(RemovePassedGoalsTestFixture, test_tick)
9899
pose.position.x = 0.25;
99100
pose.position.y = 0.0;
100101

101-
transform_handler_->activate();
102102
transform_handler_->waitForTransform();
103103
transform_handler_->updateRobotPose(pose);
104104

@@ -144,6 +144,75 @@ TEST_F(RemovePassedGoalsTestFixture, test_tick)
144144
EXPECT_EQ(output_poses.goals[1], poses.goals[3]);
145145
}
146146

147+
TEST_F(RemovePassedGoalsTestFixture,
148+
test_tick_remove_passed_goals_success_and_output_waypoint_statuses)
149+
{
150+
geometry_msgs::msg::Pose pose;
151+
pose.position.x = 0.25;
152+
pose.position.y = 0.0;
153+
154+
transform_handler_->waitForTransform();
155+
transform_handler_->updateRobotPose(pose);
156+
157+
// create tree
158+
std::string xml_txt =
159+
R"(
160+
<root BTCPP_format="4">
161+
<BehaviorTree ID="MainTree">
162+
<RemovePassedGoals radius="0.5" input_goals="{goals}" output_goals="{goals}" waypoint_statuses_id="waypoint_statuses"/>
163+
</BehaviorTree>
164+
</root>)";
165+
166+
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
167+
168+
// create new goal and set it on blackboard
169+
nav_msgs::msg::Goals poses;
170+
poses.goals.resize(4);
171+
poses.goals[0].pose.position.x = 0.0;
172+
poses.goals[0].pose.position.y = 0.0;
173+
174+
poses.goals[1].pose.position.x = 0.5;
175+
poses.goals[1].pose.position.y = 0.0;
176+
177+
poses.goals[2].pose.position.x = 1.0;
178+
poses.goals[2].pose.position.y = 0.0;
179+
180+
poses.goals[3].pose.position.x = 2.0;
181+
poses.goals[3].pose.position.y = 0.0;
182+
183+
config_->blackboard->set("goals", poses);
184+
185+
// create waypoint_statuses and set it on blackboard
186+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses(poses.goals.size());
187+
for (size_t i = 0 ; i < waypoint_statuses.size() ; ++i) {
188+
waypoint_statuses[i].goal = poses.goals[i];
189+
waypoint_statuses[i].index = i;
190+
}
191+
config_->blackboard->set("waypoint_statuses", waypoint_statuses);
192+
193+
// tick until node succeeds
194+
while (tree_->rootNode()->status() != BT::NodeStatus::SUCCESS) {
195+
tree_->rootNode()->executeTick();
196+
}
197+
198+
// check that it removed the point in range
199+
nav_msgs::msg::Goals output_poses;
200+
EXPECT_TRUE(config_->blackboard->get("goals", output_poses));
201+
202+
EXPECT_EQ(output_poses.goals.size(), 2u);
203+
EXPECT_EQ(output_poses.goals[0], poses.goals[2]);
204+
EXPECT_EQ(output_poses.goals[1], poses.goals[3]);
205+
206+
// check the waypoint_statuses
207+
std::vector<nav2_msgs::msg::WaypointStatus> output_waypoint_statuses;
208+
EXPECT_TRUE(config_->blackboard->get("waypoint_statuses", output_waypoint_statuses));
209+
EXPECT_EQ(output_waypoint_statuses.size(), 4u);
210+
EXPECT_EQ(output_waypoint_statuses[0].waypoint_status, nav2_msgs::msg::WaypointStatus::COMPLETED);
211+
EXPECT_EQ(output_waypoint_statuses[1].waypoint_status, nav2_msgs::msg::WaypointStatus::COMPLETED);
212+
EXPECT_EQ(output_waypoint_statuses[2].waypoint_status, nav2_msgs::msg::WaypointStatus::PENDING);
213+
EXPECT_EQ(output_waypoint_statuses[3].waypoint_status, nav2_msgs::msg::WaypointStatus::PENDING);
214+
}
215+
147216
int main(int argc, char ** argv)
148217
{
149218
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)