Spaces:
Running
Running
refactor: clarify DoA variable names and log angle as degrees L/R
Browse files- doa_tracker/main.py +18 -15
doa_tracker/main.py
CHANGED
|
@@ -4,8 +4,6 @@ from reachy_mini import ReachyMini, ReachyMiniApp
|
|
| 4 |
import numpy as np
|
| 5 |
import time
|
| 6 |
import requests
|
| 7 |
-
# from pydantic import BaseModel
|
| 8 |
-
import pprint
|
| 9 |
|
| 10 |
|
| 11 |
class DoaTracker(ReachyMiniApp):
|
|
@@ -29,28 +27,33 @@ class DoaTracker(ReachyMiniApp):
|
|
| 29 |
time.sleep(0.5)
|
| 30 |
continue
|
| 31 |
|
| 32 |
-
pprint.pprint(d)
|
| 33 |
-
|
| 34 |
if not d or not d["speech_detected"]:
|
| 35 |
time.sleep(0.2)
|
| 36 |
continue
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
time.sleep(0.6) # let the move finish; motor noise skews DoA
|
| 50 |
else:
|
| 51 |
time.sleep(0.2)
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
app = DoaTracker()
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import time
|
| 6 |
import requests
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
class DoaTracker(ReachyMiniApp):
|
|
|
|
| 27 |
time.sleep(0.5)
|
| 28 |
continue
|
| 29 |
|
|
|
|
|
|
|
| 30 |
if not d or not d["speech_detected"]:
|
| 31 |
time.sleep(0.2)
|
| 32 |
continue
|
| 33 |
|
| 34 |
+
# So 0 means left, π/2 means straight ahead and π means right.
|
| 35 |
+
doa = d["angle"]
|
| 36 |
+
if abs(doa - last_doa) > THRESHOLD:
|
| 37 |
+
print(fmt_doa(doa))
|
| 38 |
+
dir_head = np.array([np.sin(doa), np.cos(doa), 0.0])
|
| 39 |
+
print(dir_head)
|
| 40 |
+
head_rot = reachy_mini.get_current_head_pose()[:3, :3]
|
| 41 |
+
print(head_rot)
|
| 42 |
+
dir_world = head_rot @ dir_head
|
| 43 |
+
print(dir_world)
|
| 44 |
+
reachy_mini.look_at_world(*dir_world, duration=1.0)
|
| 45 |
+
last_doa = doa
|
| 46 |
time.sleep(0.6) # let the move finish; motor noise skews DoA
|
| 47 |
else:
|
| 48 |
time.sleep(0.2)
|
| 49 |
|
| 50 |
|
| 51 |
+
def fmt_doa(angle: float) -> str:
|
| 52 |
+
"""Format a DoA angle (0 = left, π/2 = front, π = right) as degrees off center."""
|
| 53 |
+
deg = np.degrees(angle) - 90
|
| 54 |
+
side = "L" if deg < 0 else "R" if deg > 0 else ""
|
| 55 |
+
return f"{abs(deg):.0f}° {side}".strip()
|
| 56 |
+
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
app = DoaTracker()
|