Skip to content

Commit 806bc68

Browse files
stevedanomodolorJoshua Wallace
authored andcommitted
preempt/cancel test for time behavior, spin pluguin (ros-navigation#3301)
* include preempt/cancel test for time behavior, spin pluguin * linting * fix bug in code
1 parent c415c76 commit 806bc68

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

nav2_system_tests/src/behaviors/spin/spin_behavior_tester.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ void SpinBehaviorTester::deactivate()
123123

124124
bool SpinBehaviorTester::defaultSpinBehaviorTest(
125125
const float target_yaw,
126-
const double tolerance)
126+
const double tolerance,
127+
const bool nonblocking_action,
128+
const bool cancel_action)
127129
{
128130
if (!is_active_) {
129131
RCLCPP_ERROR(node_->get_logger(), "Not activated");
@@ -181,6 +183,16 @@ bool SpinBehaviorTester::defaultSpinBehaviorTest(
181183
return false;
182184
}
183185

186+
if (!nonblocking_action) {
187+
return true;
188+
}
189+
if (cancel_action) {
190+
sleep(2);
191+
// cancel the goal
192+
auto cancel_response = client_ptr_->async_cancel_goal(goal_handle_future.get());
193+
rclcpp::spin_until_future_complete(node_, cancel_response);
194+
}
195+
184196
// Wait for the server to be done with the goal
185197
auto result_future = client_ptr_->async_get_result(goal_handle);
186198

@@ -347,5 +359,4 @@ void SpinBehaviorTester::amclPoseCallback(
347359
{
348360
initial_pose_received_ = true;
349361
}
350-
351362
} // namespace nav2_system_tests

nav2_system_tests/src/behaviors/spin/spin_behavior_tester.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class SpinBehaviorTester
5757
// Runs a single test with given target yaw
5858
bool defaultSpinBehaviorTest(
5959
float target_yaw,
60-
double tolerance = 0.1);
60+
double tolerance = 0.1,
61+
bool nonblocking_action = true,
62+
bool cancel_action = false);
6163

6264
void activate();
6365

nav2_system_tests/src/behaviors/spin/test_spin_behavior_node.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,40 @@ TEST_P(SpinBehaviorTestFixture, testSpinRecovery)
8080
}
8181
}
8282

83+
TEST_F(SpinBehaviorTestFixture, testSpinPreemption)
84+
{
85+
// Goal
86+
float target_yaw = 3.0 * M_PIf32;
87+
float tolerance = 0.1;
88+
bool nonblocking_action = false;
89+
bool success = false;
90+
91+
// Send the first goal
92+
success = spin_recovery_tester->defaultSpinBehaviorTest(
93+
target_yaw, tolerance,
94+
nonblocking_action);
95+
EXPECT_EQ(true, success);
96+
// Preempt goal
97+
sleep(2);
98+
success = false;
99+
float prempt_target_yaw = 4.0 * M_PIf32;
100+
float preempt_tolerance = 0.1;
101+
success = spin_recovery_tester->defaultSpinBehaviorTest(prempt_target_yaw, preempt_tolerance);
102+
EXPECT_EQ(false, success);
103+
}
104+
105+
TEST_F(SpinBehaviorTestFixture, testSpinCancel)
106+
{
107+
// Goal
108+
float target_yaw = 4.0 * M_PIf32;
109+
float tolerance = 0.1;
110+
bool nonblocking_action = true, cancel_action = true, success = false;
111+
success = spin_recovery_tester->defaultSpinBehaviorTest(
112+
target_yaw, tolerance,
113+
nonblocking_action, cancel_action);
114+
EXPECT_EQ(false, success);
115+
}
116+
83117
INSTANTIATE_TEST_SUITE_P(
84118
SpinRecoveryTests,
85119
SpinBehaviorTestFixture,

0 commit comments

Comments
 (0)