Skip to content

Commit 24870c6

Browse files
committed
Wait for joint_states before running test
Signed-off-by: Paul Gesel <[email protected]>
1 parent bfd1c5f commit 24870c6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/lab_sim/test/test_core_objectives.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import time
2-
31
import pytest
2+
import rclpy
43
from moveit_pro_test_utils.objective_test_fixture import (
54
ExecuteObjectiveResource,
65
execute_objective_resource as execute_objective_resource,
@@ -23,6 +22,7 @@
2322
"Plan and Save Trajectory",
2423
"Record and Replay Scanning Motion",
2524
}
25+
2626
skip_objectives = {
2727
"Grasp Planning",
2828
"Joint Diagnostic",
@@ -34,6 +34,22 @@
3434
}
3535

3636

37+
def wait_for_joint_states(timeout: int = 180):
38+
node = rclpy.create_node("test_node")
39+
start_time = node.get_clock().now()
40+
while (node.get_clock().now() - start_time).to_msg().sec < timeout:
41+
if (
42+
node.count_publishers("/joint_states") > 0
43+
and node.count_publishers("/wrist_camera/color") > 0
44+
and node.count_publishers("/display_contacts")
45+
):
46+
return True
47+
rclpy.spin_once(node, timeout_sec=0.1)
48+
raise TimeoutError(
49+
"Timeout waiting for /joint_states and /wrist_camera/color and /display_contacts to start publishing"
50+
)
51+
52+
3753
@pytest.mark.parametrize(
3854
"objective_id, should_cancel",
3955
get_objective_pytest_params("lab_sim", cancel_objectives, skip_objectives),
@@ -43,4 +59,5 @@ def test_all_objectives(
4359
should_cancel: bool,
4460
execute_objective_resource: ExecuteObjectiveResource,
4561
):
62+
wait_for_joint_states()
4663
run_objective(objective_id, should_cancel, execute_objective_resource)

0 commit comments

Comments
 (0)