Skip to content

Commit 9eaaac0

Browse files
committed
Implement new timeout in rotation test
1 parent d0ff910 commit 9eaaac0

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

clearpath_tests/clearpath_tests/rotation_test.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
# POSSIBILITY OF SUCH DAMAGE.
2929

3030
from clearpath_config.common.types.platform import Platform
31-
from clearpath_generator_common.common import BaseGenerator
3231
from clearpath_tests.mobility_test import MobilityTestNode
3332
from clearpath_tests.test_node import ClearpathTestResult
3433
from clearpath_tests.tf import ConfigurableTransformListener
34+
from clearpath_tests.timer import Timeout
35+
3536
from geometry_msgs.msg import Vector3Stamped
3637
import rclpy
37-
from rclpy.duration import Duration
3838
from rclpy.qos import qos_profile_sensor_data
3939
from sensor_msgs.msg import Imu
4040
from tf2_geometry_msgs import do_transform_vector3
@@ -140,14 +140,14 @@ def run_test(self):
140140
self.start()
141141

142142
# wait until we get the first IMU message or 10s passes
143-
start_time = self.get_clock().now()
144-
timeout_duration = Duration(seconds=10)
143+
timeout = Timeout(self, 10.0)
145144
while (
146145
self.latest_imu is None
147-
and self.get_clock().now() - start_time <= timeout_duration
146+
and not timeout.elapsed
148147
and not self.test_error
149148
):
150-
rclpy.spin_once(self)
149+
rclpy.spin_once(self, timeout_sec=1.0)
150+
timeout.abort()
151151

152152
if self.test_error:
153153
self.get_logger().warning(f'Test aborted due to an error: {self.test_error_msg}')
@@ -162,13 +162,14 @@ def run_test(self):
162162

163163
# start turning, but wait 1s for us to get up to speed before recording data
164164
self.cmd_vel.twist.angular.z = self.max_speed
165-
startup_wait = Duration(seconds=1.0)
166-
start_time = self.get_clock().now()
165+
timeout = Timeout(self, 1.0)
167166
while (
168167
not self.test_error
169-
and self.get_clock().now() - start_time <= startup_wait
168+
and not timeout.elapsed
170169
):
171-
rclpy.spin_once(self)
170+
rclpy.spin_once(self, timeout_sec=1.0)
171+
timeout.abort()
172+
172173
if self.test_error:
173174
self.record_data = False
174175
self.cmd_vel.twist.angular.z = 0.0
@@ -177,14 +178,15 @@ def run_test(self):
177178

178179
# record data for 10s
179180
self.record_data = True
180-
test_wait = Duration(seconds=10)
181-
start_time = self.get_clock().now()
181+
timeout = Timeout(self, 10.0)
182182
while (
183183
not self.test_error
184-
and self.get_clock().now() - start_time <= test_wait
184+
and not timeout.elapsed
185185
):
186-
rclpy.spin_once(self)
186+
rclpy.spin_once(self, timeout_sec=1.0)
187+
timeout.abort()
187188
self.record_data = False
189+
188190
if self.test_error:
189191
self.cmd_vel.twist.angular.z = 0.0
190192
self.get_logger().warning(f'Test aborted due to an error: {self.test_error_msg}')
@@ -193,10 +195,10 @@ def run_test(self):
193195
# stop driving
194196
# wait 1s to ensure we publish the command
195197
self.cmd_vel.twist.angular.z = 0.0
196-
test_wait = Duration(seconds=1)
197-
start_time = self.get_clock().now()
198-
while self.get_clock().now() - start_time <= test_wait:
199-
rclpy.spin_once(self)
198+
timeout = Timeout(self, 1.0)
199+
while not timeout.elapsed:
200+
rclpy.spin_once(self, timeout_sec=1.0)
201+
timeout.abort()
200202

201203
# process the results
202204
results = self.test_results

0 commit comments

Comments
 (0)