From 06ea8ce0b267aa9d69589c3bcd3394ee11d22d72 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 3 Jan 2024 17:01:46 +0100 Subject: [PATCH] Make turtle movement detection more robust Compare min and max positions instead of using assert with initial position (which can fail spuriously if the first pose arrives before the first movement; and also when the turtle reaches the exact same position again). --- examples/python-ros2-dataflow/random_turtle.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/python-ros2-dataflow/random_turtle.py b/examples/python-ros2-dataflow/random_turtle.py index d466ab1e..3e97228b 100755 --- a/examples/python-ros2-dataflow/random_turtle.py +++ b/examples/python-ros2-dataflow/random_turtle.py @@ -39,6 +39,12 @@ dora_node.merge_external_events(pose_reader) print("looping", flush=True) +# take track of minimum and maximum coordinates of turtle +min_x = 1000 +max_x = 0 +min_y = 1000 +max_y = 0 + for i in range(500): event = dora_node.next() if event is None: @@ -55,8 +61,10 @@ for i in range(500): # ROS2 Event elif event_kind == "external": pose = event.inner()[0].as_py() - if i == CHECK_TICK: - assert ( - pose["x"] != 5.544444561004639 - ), "turtle should not be at initial x axis" + min_x = min([min_x, pose["x"]]) + max_x = max([max_x, pose["x"]]) + min_y = min([min_y, pose["y"]]) + max_y = max([max_y, pose["y"]]) dora_node.send_output("turtle_pose", event.inner()) + +assert max_x - min_x > 1 or max_y - min_y > 1, "no turtle movement"