dance
Browse files- jericho/dance.py +135 -0
jericho/dance.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import threading
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from reachy_mini import ReachyMini, ReachyMiniApp
|
| 6 |
+
from reachy_mini.utils import create_head_pose
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TestDance1(ReachyMiniApp):
|
| 10 |
+
|
| 11 |
+
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 12 |
+
|
| 13 |
+
reachy_mini.goto_target(create_head_pose(), antennas=[0.0, 0.0], duration=1.0)
|
| 14 |
+
|
| 15 |
+
start_time = time.time()
|
| 16 |
+
|
| 17 |
+
while not stop_event.is_set():
|
| 18 |
+
t = time.time()
|
| 19 |
+
elapsed_time = t - start_time
|
| 20 |
+
|
| 21 |
+
compteur = int(elapsed_time / 2)
|
| 22 |
+
|
| 23 |
+
antennas_offset = np.deg2rad(20 * np.sin(2 * np.pi * 0.5 * t))
|
| 24 |
+
|
| 25 |
+
sinus_rot = np.deg2rad(20 * np.sin(2 * np.pi * 0.5 * t))
|
| 26 |
+
sinus_trans = 0.03 * np.sin(2 * np.pi * 0.5 * t)
|
| 27 |
+
|
| 28 |
+
current_roll = 0.0
|
| 29 |
+
current_pitch = 0.0
|
| 30 |
+
current_yaw = 0.0
|
| 31 |
+
current_x = 0.0
|
| 32 |
+
current_y = 0.0
|
| 33 |
+
current_z = 0.0
|
| 34 |
+
|
| 35 |
+
if compteur < 3:
|
| 36 |
+
current_roll = sinus_rot
|
| 37 |
+
elif compteur < 6:
|
| 38 |
+
current_pitch = sinus_rot
|
| 39 |
+
elif compteur < 9:
|
| 40 |
+
current_yaw = sinus_rot
|
| 41 |
+
elif compteur < 12:
|
| 42 |
+
current_x = sinus_trans
|
| 43 |
+
elif compteur < 15:
|
| 44 |
+
current_y = sinus_trans
|
| 45 |
+
elif compteur < 18:
|
| 46 |
+
current_z = sinus_trans
|
| 47 |
+
else:
|
| 48 |
+
start_time = time.time()
|
| 49 |
+
continue
|
| 50 |
+
|
| 51 |
+
head_pose = create_head_pose(
|
| 52 |
+
x=current_x,
|
| 53 |
+
y=current_y,
|
| 54 |
+
z=current_z,
|
| 55 |
+
roll=current_roll,
|
| 56 |
+
pitch=current_pitch,
|
| 57 |
+
yaw=current_yaw,
|
| 58 |
+
degrees=False,
|
| 59 |
+
mm=False,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
reachy_mini.set_target(head=head_pose, antennas=[antennas_offset, antennas_offset])
|
| 63 |
+
|
| 64 |
+
time.sleep(0.01)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class TestDance2(ReachyMiniApp):
|
| 68 |
+
|
| 69 |
+
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 70 |
+
|
| 71 |
+
reachy_mini.goto_target(create_head_pose(), antennas=[0.0, 0.0], duration=1.0)
|
| 72 |
+
|
| 73 |
+
start_time = time.time()
|
| 74 |
+
|
| 75 |
+
while not stop_event.is_set():
|
| 76 |
+
t = time.time()
|
| 77 |
+
elapsed_time = t - start_time
|
| 78 |
+
|
| 79 |
+
compteur = int(elapsed_time / 2)
|
| 80 |
+
|
| 81 |
+
antennas_offset = np.deg2rad(20 * np.sin(2 * np.pi * 0.5 * t))
|
| 82 |
+
|
| 83 |
+
sinus_rot = np.deg2rad(20 * np.sin(2 * np.pi * 0.5 * 4 * t))
|
| 84 |
+
sinus_trans = 0.03 * np.sin(2 * np.pi * 0.5 * t)
|
| 85 |
+
cosinus_trans = 0.03 * np.cos(2 * np.pi * 0.5 * t)
|
| 86 |
+
|
| 87 |
+
current_roll = 0.0
|
| 88 |
+
current_pitch = 0.0
|
| 89 |
+
current_yaw = 0.0
|
| 90 |
+
current_x = 0.0
|
| 91 |
+
current_y = 0.0
|
| 92 |
+
current_z = 0.0
|
| 93 |
+
|
| 94 |
+
if compteur < 3:
|
| 95 |
+
current_pitch = sinus_rot
|
| 96 |
+
current_y = sinus_trans
|
| 97 |
+
elif compteur < 6:
|
| 98 |
+
current_x = sinus_trans
|
| 99 |
+
current_y = cosinus_trans
|
| 100 |
+
else:
|
| 101 |
+
start_time = time.time()
|
| 102 |
+
continue
|
| 103 |
+
|
| 104 |
+
head_pose = create_head_pose(
|
| 105 |
+
x=current_x,
|
| 106 |
+
y=current_y,
|
| 107 |
+
z=current_z,
|
| 108 |
+
roll=current_roll,
|
| 109 |
+
pitch=current_pitch,
|
| 110 |
+
yaw=current_yaw,
|
| 111 |
+
degrees=False,
|
| 112 |
+
mm=False,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
reachy_mini.set_target(head=head_pose, antennas=[antennas_offset, antennas_offset])
|
| 116 |
+
|
| 117 |
+
time.sleep(0.01)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
print("Lancement manuel depuis le terminal...")
|
| 122 |
+
|
| 123 |
+
with ReachyMini(media_backend="no_media") as robot:
|
| 124 |
+
|
| 125 |
+
# 👉 Choisis ici ta danse
|
| 126 |
+
# mon_app = TestDance1()
|
| 127 |
+
mon_app = TestDance2()
|
| 128 |
+
|
| 129 |
+
stop_event = threading.Event()
|
| 130 |
+
|
| 131 |
+
try:
|
| 132 |
+
mon_app.run(robot, stop_event)
|
| 133 |
+
except KeyboardInterrupt:
|
| 134 |
+
print("\nArrêt du programme")
|
| 135 |
+
stop_event.set()
|