lucasfiotti commited on
Commit ·
9450081
1
Parent(s): 83e06b1
Update space
Browse files- coquille/programme1.py +96 -0
- coquille/programme2.py +70 -0
coquille/programme1.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import threading
|
| 2 |
+
from reachy_mini import ReachyMini, ReachyMiniApp
|
| 3 |
+
from reachy_mini.utils import create_head_pose
|
| 4 |
+
import numpy as np
|
| 5 |
+
import time
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Test(ReachyMiniApp):
|
| 10 |
+
# Optional: URL to a custom configuration page for the app
|
| 11 |
+
# eg. "http://localhost:8042"
|
| 12 |
+
custom_app_url: str | None = "http://0.0.0.0:8042"
|
| 13 |
+
# Optional: specify a media backend ("gstreamer", "gstreamer_no_video", "default", etc.)
|
| 14 |
+
# On the wireless, use gstreamer_no_video to optimise CPU usage if the app does not use video streaming
|
| 15 |
+
request_media_backend: str | None = None
|
| 16 |
+
|
| 17 |
+
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 18 |
+
t0 = time.time()
|
| 19 |
+
|
| 20 |
+
antennas_enabled = True
|
| 21 |
+
sound_play_requested = False
|
| 22 |
+
|
| 23 |
+
# You can ignore this part if you don't want to add settings to your app. If you set custom_app_url to None, you have to remove this part as well.
|
| 24 |
+
# === vvv ===
|
| 25 |
+
class AntennaState(BaseModel):
|
| 26 |
+
enabled: bool
|
| 27 |
+
|
| 28 |
+
@self.settings_app.post("/antennas")
|
| 29 |
+
def update_antennas_state(state: AntennaState):
|
| 30 |
+
nonlocal antennas_enabled
|
| 31 |
+
antennas_enabled = state.enabled
|
| 32 |
+
return {"antennas_enabled": antennas_enabled}
|
| 33 |
+
|
| 34 |
+
@self.settings_app.post("/play_sound")
|
| 35 |
+
def request_sound_play():
|
| 36 |
+
nonlocal sound_play_requested
|
| 37 |
+
sound_play_requested = True
|
| 38 |
+
|
| 39 |
+
# === ^^^ ===
|
| 40 |
+
|
| 41 |
+
# Main control loop
|
| 42 |
+
while not stop_event.is_set():
|
| 43 |
+
t_start = time.time()
|
| 44 |
+
while time.time() - t_start < 5:
|
| 45 |
+
t = time.time() - t0
|
| 46 |
+
roll_deg = 30.0 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 47 |
+
head_pose = create_head_pose(roll=roll_deg, degrees=True)
|
| 48 |
+
reachy_mini.set_target(head=head_pose)
|
| 49 |
+
time.sleep(0.02)
|
| 50 |
+
t_start = time.time()
|
| 51 |
+
while time.time() - t_start < 5:
|
| 52 |
+
t = time.time() - t0
|
| 53 |
+
pitch_deg = 30.0 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 54 |
+
head_pose = create_head_pose(pitch=pitch_deg, degrees=True)
|
| 55 |
+
reachy_mini.set_target(head=head_pose)
|
| 56 |
+
time.sleep(0.02)
|
| 57 |
+
|
| 58 |
+
t_start = time.time()
|
| 59 |
+
while time.time() - t_start < 5:
|
| 60 |
+
t = time.time() - t0
|
| 61 |
+
yaw_deg = 30.0 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 62 |
+
head_pose = create_head_pose(yaw=yaw_deg, degrees=True)
|
| 63 |
+
reachy_mini.set_target(head=head_pose)
|
| 64 |
+
time.sleep(0.02)
|
| 65 |
+
|
| 66 |
+
t_start = time.time()
|
| 67 |
+
while time.time() - t_start < 5:
|
| 68 |
+
t = time.time() - t0
|
| 69 |
+
x_pos = 0.03 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 70 |
+
head_pose = create_head_pose(x=x_pos)
|
| 71 |
+
reachy_mini.set_target(head=head_pose)
|
| 72 |
+
time.sleep(0.02)
|
| 73 |
+
|
| 74 |
+
t_start = time.time()
|
| 75 |
+
while time.time() - t_start < 5:
|
| 76 |
+
t = time.time() - t0
|
| 77 |
+
y_pos = 0.03 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 78 |
+
head_pose = create_head_pose(y=y_pos)
|
| 79 |
+
reachy_mini.set_target(head=head_pose)
|
| 80 |
+
time.sleep(0.02)
|
| 81 |
+
|
| 82 |
+
t_start = time.time()
|
| 83 |
+
while time.time() - t_start < 5:
|
| 84 |
+
t = time.time() - t0
|
| 85 |
+
z_pos = 0.015 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 86 |
+
head_pose = create_head_pose(z=z_pos)
|
| 87 |
+
reachy_mini.set_target(head=head_pose)
|
| 88 |
+
time.sleep(0.02)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
app = Test()
|
| 93 |
+
try:
|
| 94 |
+
app.wrapped_run()
|
| 95 |
+
except KeyboardInterrupt:
|
| 96 |
+
app.stop()
|
coquille/programme2.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import threading
|
| 2 |
+
from reachy_mini import ReachyMini, ReachyMiniApp
|
| 3 |
+
from reachy_mini.utils import create_head_pose
|
| 4 |
+
import numpy as np
|
| 5 |
+
import time
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Test(ReachyMiniApp):
|
| 10 |
+
# Optional: URL to a custom configuration page for the app
|
| 11 |
+
# eg. "http://localhost:8042"
|
| 12 |
+
custom_app_url: str | None = "http://0.0.0.0:8042"
|
| 13 |
+
# Optional: specify a media backend ("gstreamer", "gstreamer_no_video", "default", etc.)
|
| 14 |
+
# On the wireless, use gstreamer_no_video to optimise CPU usage if the app does not use video streaming
|
| 15 |
+
request_media_backend: str | None = None
|
| 16 |
+
|
| 17 |
+
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 18 |
+
t0 = time.time()
|
| 19 |
+
|
| 20 |
+
antennas_enabled = True
|
| 21 |
+
sound_play_requested = False
|
| 22 |
+
|
| 23 |
+
# You can ignore this part if you don't want to add settings to your app. If you set custom_app_url to None, you have to remove this part as well.
|
| 24 |
+
# === vvv ===
|
| 25 |
+
class AntennaState(BaseModel):
|
| 26 |
+
enabled: bool
|
| 27 |
+
|
| 28 |
+
@self.settings_app.post("/antennas")
|
| 29 |
+
def update_antennas_state(state: AntennaState):
|
| 30 |
+
nonlocal antennas_enabled
|
| 31 |
+
antennas_enabled = state.enabled
|
| 32 |
+
return {"antennas_enabled": antennas_enabled}
|
| 33 |
+
|
| 34 |
+
@self.settings_app.post("/play_sound")
|
| 35 |
+
def request_sound_play():
|
| 36 |
+
nonlocal sound_play_requested
|
| 37 |
+
sound_play_requested = True
|
| 38 |
+
|
| 39 |
+
# === ^^^ ===
|
| 40 |
+
|
| 41 |
+
# Main control loop
|
| 42 |
+
while not stop_event.is_set():
|
| 43 |
+
|
| 44 |
+
t_start = time.time()
|
| 45 |
+
while time.time() - t_start < 15.0:
|
| 46 |
+
t = time.time() - t0
|
| 47 |
+
y_m = 0.03 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 48 |
+
pitch_deg = 30.0 * np.sin(2.0 * np.pi * 0.6 * t)
|
| 49 |
+
head_pose = create_head_pose(y=y_m, pitch=pitch_deg, degrees=True)
|
| 50 |
+
reachy_mini.set_target(head=head_pose)
|
| 51 |
+
time.sleep(0.01)
|
| 52 |
+
|
| 53 |
+
t_start = time.time()
|
| 54 |
+
while time.time() - t_start < 15.0:
|
| 55 |
+
t = time.time() - t0
|
| 56 |
+
x_m = 0.03 * np.cos(2.0 * np.pi * 0.2 * t)
|
| 57 |
+
y_m = 0.03 * np.sin(2.0 * np.pi * 0.2 * t)
|
| 58 |
+
z_m = 0.0
|
| 59 |
+
head_pose = create_head_pose(x=x_m, y=y_m, z=z_m, degrees=True)
|
| 60 |
+
reachy_mini.set_target(head=head_pose)
|
| 61 |
+
time.sleep(0.01)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
app = Test()
|
| 67 |
+
try:
|
| 68 |
+
app.wrapped_run()
|
| 69 |
+
except KeyboardInterrupt:
|
| 70 |
+
app.stop()
|