Browse Source

Use struct type instead of array for ros2 messages

tags/v0.2.5-alpha.3
haixuanTao 2 years ago
parent
commit
d0d42f9d9f
2 changed files with 10 additions and 27 deletions
  1. +8
    -4
      examples/python-ros2-dataflow/control_node.py
  2. +2
    -23
      examples/python-ros2-dataflow/random_turtle.py

+ 8
- 4
examples/python-ros2-dataflow/control_node.py View File

@@ -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]),
)

+ 2
- 23
examples/python-ros2-dataflow/random_turtle.py View File

@@ -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())

Loading…
Cancel
Save