Skip to content

Commit 0a8bc48

Browse files
committed
Add validation tests for waypoint_statuses output of RemoveInCollisionGoals
Signed-off-by: zz990099 <[email protected]>
1 parent 8c32a8f commit 0a8bc48

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
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

0 commit comments

Comments
 (0)