Skip to content

Commit 94e1df7

Browse files
committed
Add validation test cases for RemoveInCollision&RemovePassed BT actions
Signed-off-by: zz990099 <[email protected]>
1 parent fe9f3af commit 94e1df7

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

nav2_behavior_tree/test/plugins/action/test_remove_in_collision_goals_action.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,70 @@ TEST_F(RemoveInCollisionGoalsTestFixture,
250250
EXPECT_EQ(output_waypoint_statuses[3].waypoint_status, nav2_msgs::msg::WaypointStatus::SKIPPED);
251251
}
252252

253+
TEST_F(RemoveInCollisionGoalsTestFixture,
254+
test_tick_remove_in_collision_goals_find_matching_waypoint_fail)
255+
{
256+
// create tree
257+
std::string xml_txt =
258+
R"(
259+
<root BTCPP_format="4">
260+
<BehaviorTree ID="MainTree">
261+
<RemoveInCollisionGoals service_name="/global_costmap/get_cost_global_costmap"
262+
input_goals="{goals}" output_goals="{goals}"
263+
cost_threshold="253"
264+
input_waypoint_statuses="{waypoint_statuses}"
265+
output_waypoint_statuses="{waypoint_statuses}"/>
266+
</BehaviorTree>
267+
</root>)";
268+
269+
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
270+
271+
// create new goal and set it on blackboard
272+
nav_msgs::msg::Goals poses;
273+
poses.goals.resize(4);
274+
poses.goals[0].pose.position.x = 0.0;
275+
poses.goals[0].pose.position.y = 0.0;
276+
277+
poses.goals[1].pose.position.x = 0.5;
278+
poses.goals[1].pose.position.y = 0.0;
279+
280+
poses.goals[2].pose.position.x = 1.0;
281+
poses.goals[2].pose.position.y = 0.0;
282+
283+
poses.goals[3].pose.position.x = 2.0;
284+
poses.goals[3].pose.position.y = 0.0;
285+
286+
config_->blackboard->set("goals", poses);
287+
288+
// create waypoint_statuses and set it on blackboard
289+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses(poses.goals.size());
290+
for (size_t i = 0 ; i < waypoint_statuses.size() ; ++i) {
291+
waypoint_statuses[i].waypoint_pose = poses.goals[i];
292+
waypoint_statuses[i].waypoint_index = i;
293+
}
294+
// inconsistency between waypoint_statuses and poses
295+
waypoint_statuses[3].waypoint_pose.pose.position.x = 0.0;
296+
297+
config_->blackboard->set("waypoint_statuses", waypoint_statuses);
298+
299+
// tick until node is not running
300+
tree_->rootNode()->executeTick();
301+
while (tree_->rootNode()->status() == BT::NodeStatus::RUNNING) {
302+
tree_->rootNode()->executeTick();
303+
}
304+
305+
// check that it failed and returned the original goals
306+
EXPECT_EQ(tree_->rootNode()->status(), BT::NodeStatus::FAILURE);
307+
nav_msgs::msg::Goals output_poses;
308+
EXPECT_TRUE(config_->blackboard->get("goals", output_poses));
309+
310+
EXPECT_EQ(output_poses.goals.size(), 4u);
311+
EXPECT_EQ(output_poses.goals[0], poses.goals[0]);
312+
EXPECT_EQ(output_poses.goals[1], poses.goals[1]);
313+
EXPECT_EQ(output_poses.goals[2], poses.goals[2]);
314+
EXPECT_EQ(output_poses.goals[3], poses.goals[3]);
315+
}
316+
253317
TEST_F(RemoveInCollisionGoalsTestFixture, test_tick_remove_in_collision_goals_fail)
254318
{
255319
// create tree

nav2_behavior_tree/test/plugins/action/test_remove_passed_goals_action.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,66 @@ TEST_F(RemovePassedGoalsTestFixture,
215215
EXPECT_EQ(output_waypoint_statuses[3].waypoint_status, nav2_msgs::msg::WaypointStatus::PENDING);
216216
}
217217

218+
TEST_F(RemovePassedGoalsTestFixture,
219+
test_tick_remove_passed_goals_find_matching_waypoint_fail)
220+
{
221+
geometry_msgs::msg::Pose pose;
222+
pose.position.x = 0.25;
223+
pose.position.y = 0.0;
224+
225+
transform_handler_->waitForTransform();
226+
transform_handler_->updateRobotPose(pose);
227+
228+
// create tree
229+
std::string xml_txt =
230+
R"(
231+
<root BTCPP_format="4">
232+
<BehaviorTree ID="MainTree">
233+
<RemovePassedGoals radius="0.5" input_goals="{goals}" output_goals="{goals}"
234+
input_waypoint_statuses="{waypoint_statuses}"
235+
output_waypoint_statuses="{waypoint_statuses}"/>
236+
</BehaviorTree>
237+
</root>)";
238+
239+
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
240+
241+
// create new goal and set it on blackboard
242+
nav_msgs::msg::Goals poses;
243+
poses.goals.resize(4);
244+
poses.goals[0].pose.position.x = 0.0;
245+
poses.goals[0].pose.position.y = 0.0;
246+
247+
poses.goals[1].pose.position.x = 0.5;
248+
poses.goals[1].pose.position.y = 0.0;
249+
250+
poses.goals[2].pose.position.x = 1.0;
251+
poses.goals[2].pose.position.y = 0.0;
252+
253+
poses.goals[3].pose.position.x = 2.0;
254+
poses.goals[3].pose.position.y = 0.0;
255+
256+
config_->blackboard->set("goals", poses);
257+
258+
// create waypoint_statuses and set it on blackboard
259+
std::vector<nav2_msgs::msg::WaypointStatus> waypoint_statuses(poses.goals.size());
260+
for (size_t i = 0 ; i < waypoint_statuses.size() ; ++i) {
261+
waypoint_statuses[i].waypoint_pose = poses.goals[i];
262+
waypoint_statuses[i].waypoint_index = i;
263+
}
264+
// inconsistency between waypoint_statuses and poses
265+
waypoint_statuses[1].waypoint_pose.pose.position.x = 0.0;
266+
config_->blackboard->set("waypoint_statuses", waypoint_statuses);
267+
268+
// tick until node is not running
269+
tree_->rootNode()->executeTick();
270+
while (tree_->rootNode()->status() == BT::NodeStatus::RUNNING) {
271+
tree_->rootNode()->executeTick();
272+
}
273+
274+
// check that it failed
275+
EXPECT_EQ(tree_->rootNode()->status(), BT::NodeStatus::FAILURE);
276+
}
277+
218278
int main(int argc, char ** argv)
219279
{
220280
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)