You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

random_turtle.py 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import time, random
  2. from dora import Node
  3. from dora_ros2_bridge import *
  4. import pyarrow as pa
  5. dora_node = Node()
  6. context = Ros2Context()
  7. node = context.new_node("turtle_teleop", "/ros2_demo", Ros2NodeOptions(rosout=True))
  8. topic_qos = Ros2QosPolicies(reliable=True, max_blocking_time=0.1)
  9. turtle_twist_topic = node.create_topic(
  10. "/turtle1/cmd_vel", "geometry_msgs::Twist", topic_qos
  11. )
  12. twist_writer = node.create_publisher(turtle_twist_topic)
  13. turtle_pose_topic = node.create_topic("/turtle1/pose", "turtlesim::Pose", topic_qos)
  14. pose_reader = node.create_subscription(turtle_pose_topic)
  15. print("looping", flush=True)
  16. for event in dora_node:
  17. match event["type"]:
  18. case "INPUT":
  19. match event["id"]:
  20. case "direction":
  21. direction = {
  22. "linear": {
  23. "x": event["data"][0],
  24. },
  25. "angular": {
  26. "z": event["data"][5],
  27. },
  28. }
  29. print(direction, flush=True)
  30. twist_writer.publish(direction)
  31. case "tick":
  32. pose = pose_reader.next()
  33. if pose == None:
  34. print("stop", flush=True)
  35. continue
  36. dora_node.send_output(
  37. "turtle_pose",
  38. pa.array(
  39. [
  40. pose["x"],
  41. pose["y"],
  42. pose["theta"],
  43. pose["linear_velocity"],
  44. pose["angular_velocity"],
  45. ],
  46. type=pa.uint8(),
  47. ),
  48. )

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl