From d0d42f9d9ff9345ea66603bdd594fff1df7df80f Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Tue, 5 Sep 2023 11:11:07 +0200 Subject: [PATCH] Use struct type instead of array for ros2 messages --- examples/python-ros2-dataflow/control_node.py | 12 ++++++--- .../python-ros2-dataflow/random_turtle.py | 25 ++----------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/examples/python-ros2-dataflow/control_node.py b/examples/python-ros2-dataflow/control_node.py index 15ec4bdd..0ce47943 100755 --- a/examples/python-ros2-dataflow/control_node.py +++ b/examples/python-ros2-dataflow/control_node.py @@ -18,10 +18,14 @@ for i in range(500): f"""Pose: {event["value"]}""".replace("\r", "").replace("\n", " ") ) case "tick": + direction = { + "linear": { + "x": 1.0, + }, + "angular": {"z": 1.0}, + } + node.send_output( "direction", - pa.array( - [random.random() + 1, 0, 0, 0, 0, (random.random() - 0.5) * 5], - type=pa.float64(), - ), + pa.array([direction]), ) diff --git a/examples/python-ros2-dataflow/random_turtle.py b/examples/python-ros2-dataflow/random_turtle.py index 003c39f9..b95ed87f 100755 --- a/examples/python-ros2-dataflow/random_turtle.py +++ b/examples/python-ros2-dataflow/random_turtle.py @@ -42,31 +42,10 @@ for i in range(500): case "INPUT": match event["id"]: case "direction": - direction = { - "linear": { - "x": event["value"][0], - }, - "angular": { - "z": event["value"][5], - }, - } - - twist_writer.publish(direction) + twist_writer.publish(event["value"]) case "external": pose = event.inner()[0].as_py() assert pose["x"] != 5.544445, "turtle should not be at initial x axis" - dora_node.send_output( - "turtle_pose", - pa.array( - [ - pose["x"], - pose["y"], - pose["theta"], - pose["linear_velocity"], - pose["angular_velocity"], - ], - type=pa.float64(), - ), - ) + dora_node.send_output("turtle_pose", event.inner())