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.

parse_point.py 1.7 kB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """TODO: Add docstring."""
  2. import json
  3. import os
  4. import time
  5. import numpy as np
  6. import pyarrow as pa
  7. from dora import Node
  8. node = Node()
  9. IMAGE_RESIZE_RATIO = float(os.getenv("IMAGE_RESIZE_RATIO", "1.0"))
  10. arrive_time = time.time()
  11. for event in node:
  12. if event["type"] == "INPUT":
  13. text = event["value"][0].as_py()
  14. width = event["metadata"]["width"]
  15. height = event["metadata"]["height"]
  16. values = event["value"].to_numpy().reshape((-1, 2))
  17. values = values * int(1 / IMAGE_RESIZE_RATIO)
  18. # Do point 0 first
  19. if len(values) == 0:
  20. continue
  21. elif len(values) > 1:
  22. point = values[-1]
  23. rz = int((width / 2) - point[0]) / (width / 2)
  24. x_distance = min(height, height - point[1])
  25. y = 0
  26. if abs(rz) > 0.75:
  27. rz = np.deg2rad(45) * np.sign(rz)
  28. elif abs(rz) > 0.5:
  29. rz = np.deg2rad(30) * np.sign(rz)
  30. elif abs(rz) > 0.3:
  31. rz = np.deg2rad(20) * np.sign(rz)
  32. elif abs(rz) > 0.1:
  33. rz = np.deg2rad(10) * np.sign(rz)
  34. else:
  35. x = 0
  36. if x_distance > (height * 0.7):
  37. x = 0.7
  38. elif x_distance > (height * 0.5):
  39. x = 0.6
  40. elif x_distance > (height * 0.25):
  41. x = 0.5
  42. else:
  43. x = 0
  44. if x_distance < (height * 0.25):
  45. print("ARRIVED!")
  46. time.sleep(1.0)
  47. if time.time() - arrive_time > 4.0:
  48. node.send_output("arrived", pa.array([]))
  49. arrive_time = time.time()
  50. # Action
  51. action = pa.array([x, y, 0, 0, 0, rz])
  52. node.send_output("action", action)