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_pose.py 3.7 kB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. """TODO: Add docstring."""
  2. import time
  3. import numpy as np
  4. import pyarrow as pa
  5. from dora import Node
  6. node = Node()
  7. top_z = -0.43
  8. low_z = -0.57
  9. roll = 1.86
  10. pitch = 1.43
  11. yaw_open = 0.8
  12. yaw_close = -0.5
  13. def grab(target_x, target_y, low_z, top_z, roll, pitch, yaw_open, yaw_close, last_x, last_y):
  14. node.send_output(
  15. "action",
  16. pa.array([target_x, target_y, top_z, roll, pitch, yaw_open]),
  17. metadata={"encoding": "xyzrpy"},
  18. )
  19. time.sleep(0.6)
  20. node.send_output(
  21. "action",
  22. pa.array([target_x, target_y, low_z, roll, pitch, yaw_open]),
  23. metadata={"encoding": "xyzrpy"},
  24. )
  25. time.sleep(0.2)
  26. node.send_output(
  27. "action",
  28. pa.array([target_x, target_y, low_z, roll, pitch, yaw_close]),
  29. metadata={"encoding": "xyzrpy"},
  30. )
  31. time.sleep(0.4)
  32. node.send_output(
  33. "action",
  34. pa.array([target_x, target_y, top_z, roll, pitch, yaw_close]),
  35. metadata={"encoding": "xyzrpy"},
  36. )
  37. time.sleep(0.5)
  38. node.send_output(
  39. "action",
  40. pa.array([0.05, 0.0, top_z, roll, pitch, yaw_close]),
  41. metadata={"encoding": "xyzrpy"},
  42. )
  43. def place(place_x, place_y, place_z, top_z, roll, pitch, yaw_open, yaw_close, last_x, last_y):
  44. node.send_output(
  45. "action",
  46. pa.array([place_x, place_y, top_z, roll, pitch, yaw_close]),
  47. metadata={"encoding": "xyzrpy"},
  48. )
  49. time.sleep(0.6)
  50. node.send_output(
  51. "action",
  52. pa.array([place_x, place_y, place_z, roll, pitch, yaw_close]),
  53. metadata={"encoding": "xyzrpy"},
  54. )
  55. time.sleep(0.2)
  56. node.send_output(
  57. "action",
  58. pa.array([place_x, place_y, place_z, roll, pitch, yaw_open]),
  59. metadata={"encoding": "xyzrpy"},
  60. )
  61. time.sleep(0.3)
  62. node.send_output(
  63. "action",
  64. pa.array([place_x, place_y, top_z, roll, pitch, yaw_open]),
  65. metadata={"encoding": "xyzrpy"},
  66. )
  67. time.sleep(0.3)
  68. node.send_output(
  69. "action",
  70. pa.array([0.05, 0.0, top_z, roll, pitch, yaw_open]),
  71. metadata={"encoding": "xyzrpy"},
  72. )
  73. time.sleep(0.6)
  74. node.send_output(
  75. "action",
  76. pa.array([0.05, 0.0, top_z, roll, pitch, yaw_open]),
  77. metadata={"encoding": "xyzrpy"},
  78. )
  79. last_x = 0
  80. last_y = 0
  81. last_z = 0
  82. for event in node:
  83. if event["type"] == "INPUT":
  84. if event["id"] == "pose":
  85. values = event["value"]
  86. values = values.to_numpy()
  87. print(values)
  88. if len(values) == 0:
  89. continue
  90. x = values[0]
  91. y = values[1]
  92. z = values[2]
  93. action = event["metadata"]["action"]
  94. # Adjust z with the size of the gripper
  95. z = z + 0.06
  96. match action:
  97. case "grab":
  98. y = y + -0.01
  99. grab(
  100. x,
  101. y,
  102. z,
  103. top_z,
  104. roll,
  105. pitch,
  106. yaw_open,
  107. yaw_close,
  108. last_x,
  109. last_y
  110. )
  111. case "release":
  112. place(
  113. x,
  114. y,
  115. z,
  116. top_z,
  117. roll,
  118. pitch,
  119. yaw_open,
  120. yaw_close,
  121. last_x,
  122. last_y
  123. )
  124. last_x = -0.05
  125. last_y = 0.04
  126. last_z = z