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.

plot_node.py 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Module for visualizing robot data and states.
  2. This module provides functionality for plotting and displaying various aspects
  3. of the robot's state, including positions, movements, and sensor data.
  4. """
  5. import os
  6. import cv2
  7. from dora import Node
  8. IMAGE_WIDTH = int(os.getenv("IMAGE_WIDTH", "1280"))
  9. IMAGE_HEIGHT = int(os.getenv("IMAGE_HEIGHT", "720"))
  10. FONT = cv2.FONT_HERSHEY_SIMPLEX
  11. node = Node()
  12. joint = None
  13. text = None
  14. action = None
  15. for event in node:
  16. if event["type"] == "INPUT":
  17. dora_id = event["id"]
  18. if dora_id == "position":
  19. joint = event["value"].to_numpy()
  20. if "text" in dora_id:
  21. text = event["value"][0].as_py()
  22. if "action" in dora_id:
  23. action = event["value"].to_numpy()
  24. if dora_id == "image":
  25. image = (
  26. event["value"].to_numpy().reshape((IMAGE_HEIGHT, IMAGE_WIDTH, 3)).copy()
  27. )
  28. if action is not None:
  29. cv2.putText(
  30. image,
  31. f"action: {action}",
  32. (20, 40),
  33. FONT,
  34. 0.5,
  35. (190, 250, 0),
  36. 2,
  37. )
  38. if joint is not None:
  39. cv2.putText(
  40. image,
  41. f"pos: {joint}",
  42. (20, 20),
  43. FONT,
  44. 0.5,
  45. (190, 250, 100),
  46. 2,
  47. )
  48. cv2.imshow("frame", image)
  49. if cv2.waitKey(1) & 0xFF == ord("q"):
  50. break