apirrone
commited on
Commit
·
087df0d
1
Parent(s):
66a5bd7
update
Browse files- reachy_mini_greetings/main.py +79 -32
reachy_mini_greetings/main.py
CHANGED
|
@@ -14,7 +14,22 @@ import time
|
|
| 14 |
class GreetingsApp(ReachyMiniApp):
|
| 15 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 16 |
head_tracker = HeadTracker()
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
t0 = time.time()
|
| 20 |
while not stop_event.is_set():
|
|
@@ -22,58 +37,90 @@ class GreetingsApp(ReachyMiniApp):
|
|
| 22 |
# cv2.imshow("frame", frame)
|
| 23 |
# cv2.waitKey(1)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
time.sleep(0.2)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
time.sleep(0.5)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
pose = create_head_pose(0.0, 0.02, -0.02, 20, 0, 0)
|
| 38 |
-
reachy_mini.goto_target(
|
|
|
|
|
|
|
| 39 |
time.sleep(0.2)
|
| 40 |
|
| 41 |
pose = create_head_pose(0.0, -0.02, -0.02, -20, 0, 0)
|
| 42 |
-
reachy_mini.goto_target(
|
|
|
|
|
|
|
| 43 |
time.sleep(0.2)
|
| 44 |
|
| 45 |
pose = create_head_pose(0, 0, 0, 0, 0, 0)
|
| 46 |
-
reachy_mini.goto_target(
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
# pose = create_head_pose(0, 0, 0, 0, -15, 30)
|
| 54 |
-
# reachy_mini.goto_target(pose, duration=1, method="ease_in_out")
|
| 55 |
-
# time.sleep(0.5)
|
| 56 |
-
|
| 57 |
-
# pose = create_head_pose(0, 0, 0, 0, 15, 20)
|
| 58 |
-
# reachy_mini.goto_target(pose, duration=1, method="ease_in_out")
|
| 59 |
-
# time.sleep(0.5)
|
| 60 |
-
|
| 61 |
-
# pose = create_head_pose(0, 0, 0, 0, -20, -40)
|
| 62 |
-
# reachy_mini.goto_target(pose, duration=1, method="ease_in_out")
|
| 63 |
-
# time.sleep(0.5)
|
| 64 |
|
| 65 |
pose = create_head_pose(0, 0, 0.02, 0, -20, -140)
|
| 66 |
reachy_mini.goto_target(
|
| 67 |
-
pose,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
)
|
| 69 |
time.sleep(0.5)
|
| 70 |
|
| 71 |
pose = create_head_pose(0, 0, 0, 0, 0, 0)
|
| 72 |
-
reachy_mini.goto_target(
|
|
|
|
|
|
|
| 73 |
|
|
|
|
|
|
|
| 74 |
pose = create_head_pose(0, 0, 0.02, 0, -30, 100)
|
| 75 |
reachy_mini.goto_target(
|
| 76 |
-
pose,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
)
|
| 78 |
time.sleep(0.5)
|
| 79 |
|
|
|
|
| 14 |
class GreetingsApp(ReachyMiniApp):
|
| 15 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 16 |
head_tracker = HeadTracker()
|
| 17 |
+
emotions = RecordedMoves("pollen-robotics/reachy-mini-emotions-library")
|
| 18 |
+
|
| 19 |
+
moves = [
|
| 20 |
+
"proud1",
|
| 21 |
+
"proud2",
|
| 22 |
+
"success1",
|
| 23 |
+
"cheerful1",
|
| 24 |
+
"welcoming1",
|
| 25 |
+
"loving1",
|
| 26 |
+
"surprised1",
|
| 27 |
+
]
|
| 28 |
+
is_scared = True
|
| 29 |
+
# did_one_turn = False
|
| 30 |
+
# tracking = False
|
| 31 |
+
# was_tracking = False
|
| 32 |
+
# tracking_lost_since = time.time()
|
| 33 |
|
| 34 |
t0 = time.time()
|
| 35 |
while not stop_event.is_set():
|
|
|
|
| 37 |
# cv2.imshow("frame", frame)
|
| 38 |
# cv2.waitKey(1)
|
| 39 |
|
| 40 |
+
# if did_one_turn:
|
| 41 |
+
# eye_center, roll = head_tracker.get_head_position(frame)
|
| 42 |
+
# if eye_center is not None:
|
| 43 |
+
# tracking = True
|
| 44 |
+
# else:
|
| 45 |
+
# tracking_lost_since = time.time()
|
| 46 |
|
| 47 |
+
# if time.time() - tracking_lost_since > 2:
|
| 48 |
+
# tracking = False
|
|
|
|
| 49 |
|
| 50 |
+
# if eye_center is not None and tracking:
|
| 51 |
+
# h, w, _ = frame.shape
|
| 52 |
+
# eye_center = (eye_center + 1) / 2
|
| 53 |
+
# eye_center[0] *= w
|
| 54 |
+
# eye_center[1] *= h
|
| 55 |
+
# reachy_mini.look_at_image(*eye_center, duration=0.0)
|
| 56 |
+
|
| 57 |
+
# if not did_one_turn and not tracking:
|
| 58 |
+
pose = create_head_pose(0, 0, 0, 0, 0, 0)
|
| 59 |
+
reachy_mini.goto_target(
|
| 60 |
+
pose, duration=1, antennas=[0, 0], method="ease_in_out"
|
| 61 |
+
)
|
| 62 |
time.sleep(0.5)
|
| 63 |
|
| 64 |
+
if is_scared:
|
| 65 |
+
reachy_mini.media.play_sound("impatient1.wav")
|
| 66 |
+
pose = create_head_pose(-0.01, 0, -0.035, 0, 15, 0)
|
| 67 |
+
reachy_mini.goto_target(
|
| 68 |
+
pose, duration=0.3, antennas=[-1.5, 1.5], method="ease_in_out"
|
| 69 |
+
)
|
| 70 |
+
time.sleep(0.2)
|
| 71 |
+
|
| 72 |
+
pose = create_head_pose(0, 0, -0.02, 0, 0, 0)
|
| 73 |
+
reachy_mini.goto_target(
|
| 74 |
+
pose, duration=2, antennas=[-1, 1], method="ease_in_out"
|
| 75 |
+
)
|
| 76 |
+
time.sleep(0.5)
|
| 77 |
+
is_scared = False
|
| 78 |
+
|
| 79 |
pose = create_head_pose(0.0, 0.02, -0.02, 20, 0, 0)
|
| 80 |
+
reachy_mini.goto_target(
|
| 81 |
+
pose, duration=0.5, antennas=[-1.5, 0], method="ease_in_out"
|
| 82 |
+
)
|
| 83 |
time.sleep(0.2)
|
| 84 |
|
| 85 |
pose = create_head_pose(0.0, -0.02, -0.02, -20, 0, 0)
|
| 86 |
+
reachy_mini.goto_target(
|
| 87 |
+
pose, duration=0.5, antennas=[0, 1.6], method="ease_in_out"
|
| 88 |
+
)
|
| 89 |
time.sleep(0.2)
|
| 90 |
|
| 91 |
pose = create_head_pose(0, 0, 0, 0, 0, 0)
|
| 92 |
+
reachy_mini.goto_target(
|
| 93 |
+
pose, duration=0.5, antennas=[0, 0], method="ease_in_out"
|
| 94 |
+
)
|
| 95 |
+
reachy_mini.play_move(
|
| 96 |
+
emotions.get(np.random.choice(moves)), initial_goto_duration=1.0
|
| 97 |
+
)
|
| 98 |
+
reachy_mini.media.play_sound("confused1.wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
pose = create_head_pose(0, 0, 0.02, 0, -20, -140)
|
| 101 |
reachy_mini.goto_target(
|
| 102 |
+
pose,
|
| 103 |
+
body_yaw=np.deg2rad(-100),
|
| 104 |
+
duration=1,
|
| 105 |
+
antennas=[-1.5, 0],
|
| 106 |
+
method="ease_in_out",
|
| 107 |
)
|
| 108 |
time.sleep(0.5)
|
| 109 |
|
| 110 |
pose = create_head_pose(0, 0, 0, 0, 0, 0)
|
| 111 |
+
reachy_mini.goto_target(
|
| 112 |
+
pose, duration=1, antennas=[0, 0], method="ease_in_out"
|
| 113 |
+
)
|
| 114 |
|
| 115 |
+
if np.random.rand() < 0.2:
|
| 116 |
+
reachy_mini.media.play_sound("dance1.wav")
|
| 117 |
pose = create_head_pose(0, 0, 0.02, 0, -30, 100)
|
| 118 |
reachy_mini.goto_target(
|
| 119 |
+
pose,
|
| 120 |
+
body_yaw=np.deg2rad(80),
|
| 121 |
+
duration=1,
|
| 122 |
+
antennas=[0, 1.5],
|
| 123 |
+
method="ease_in_out",
|
| 124 |
)
|
| 125 |
time.sleep(0.5)
|
| 126 |
|