Skip to content

Commit 50366b7

Browse files
urfeexurrsk
andauthored
[Driver Tests] Unlock protective stop during test case setup (UniversalRobots#1641)
* Use custom logging for ListControllersResponse * Unlock protective stop * Use a while loop instead of a fixed wait --------- Co-authored-by: Rune Søe-Knudsen <41109954+urrsk@users.noreply.github.com>
1 parent 399da65 commit 50366b7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

ur_robot_driver/test/test_common.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def _call_service(node, client, request):
112112
rclpy.spin_until_future_complete(node, future)
113113

114114
if future.result() is not None:
115-
logging.info(" Received result: %s", future.result())
115+
response_str = str(future.result())
116+
if type(future.result()).__name__ == "ListControllers_Response":
117+
controllers_str_list = [f"{c.name}: {c.state}" for c in future.result().controller]
118+
response_str = f"controllers: [{', '.join(controllers_str_list)}]"
119+
logging.info(" Received result: %s", response_str)
116120
return future.result()
117121

118122
raise Exception(f"Error while calling service '{client.srv_name}': {future.exception()}")
@@ -238,17 +242,21 @@ def start_robot(self):
238242
self._check_call(self.power_off())
239243
self._check_call(self.power_on())
240244
self._check_call(self.brake_release())
245+
self._check_call(self.unlock_protective_stop())
241246

242247
time.sleep(1)
243248

244249
robot_mode = self.get_robot_mode()
245-
self._check_call(robot_mode)
246-
if robot_mode.robot_mode.mode != RobotMode.RUNNING:
247-
raise Exception(
248-
f"Incorrect robot mode: Expected {RobotMode.RUNNING}, got {robot_mode.robot_mode.mode}"
249-
)
250-
251-
self._check_call(self.stop())
250+
start_time = time.time()
251+
while time.time() - start_time < TIMEOUT_WAIT_SERVICE:
252+
self._check_call(robot_mode)
253+
if robot_mode.robot_mode.mode == RobotMode.RUNNING:
254+
self._check_call(self.stop())
255+
return
256+
time.sleep(0.1)
257+
raise Exception(
258+
f"Incorrect robot mode: Expected {RobotMode.RUNNING}, got {robot_mode.robot_mode.mode}"
259+
)
252260

253261
def _check_call(self, result):
254262
if not result.success:

0 commit comments

Comments
 (0)