Spaces:
Running
Running
RemiFabre
commited on
Commit
·
6919d11
1
Parent(s):
c51a63a
Simplified app exit procedure
Browse files- emotions/main.py +17 -52
emotions/main.py
CHANGED
|
@@ -9,8 +9,6 @@ from datetime import datetime
|
|
| 9 |
import os
|
| 10 |
from pathlib import Path
|
| 11 |
from typing import Any, Literal
|
| 12 |
-
|
| 13 |
-
import numpy as np
|
| 14 |
from fastapi import HTTPException
|
| 15 |
from pydantic import BaseModel, Field
|
| 16 |
from ruamel.yaml import YAML
|
|
@@ -76,7 +74,6 @@ WHEEL_NODE_LAYOUT = {
|
|
| 76 |
},
|
| 77 |
}
|
| 78 |
|
| 79 |
-
SHUTDOWN_MOVE_ID = "grateful1"
|
| 80 |
MOVE_INITIAL_GOTO_DURATION = 0.7
|
| 81 |
|
| 82 |
|
|
@@ -638,34 +635,6 @@ class Emotions(ReachyMiniApp):
|
|
| 638 |
"precision": updated_move.precision if updated_move else None,
|
| 639 |
}
|
| 640 |
|
| 641 |
-
def _play_shutdown_sequence(self, reachy_mini: ReachyMini) -> None:
|
| 642 |
-
"""Play a graceful shutdown move and return to the base pose."""
|
| 643 |
-
if not SHUTDOWN_MOVE_ID:
|
| 644 |
-
return
|
| 645 |
-
try:
|
| 646 |
-
move = self._recorded_emotions.get(SHUTDOWN_MOVE_ID)
|
| 647 |
-
except ValueError:
|
| 648 |
-
self.logger.warning("Shutdown move %s missing from recorded dataset.", SHUTDOWN_MOVE_ID)
|
| 649 |
-
return
|
| 650 |
-
|
| 651 |
-
with self._lock:
|
| 652 |
-
self._pending_move = None
|
| 653 |
-
self._current_move = SHUTDOWN_MOVE_ID
|
| 654 |
-
|
| 655 |
-
try:
|
| 656 |
-
reachy_mini.play_move(move, initial_goto_duration=MOVE_INITIAL_GOTO_DURATION)
|
| 657 |
-
except Exception:
|
| 658 |
-
self.logger.exception("Failed to play shutdown move %s.", SHUTDOWN_MOVE_ID)
|
| 659 |
-
finally:
|
| 660 |
-
with self._lock:
|
| 661 |
-
self._current_move = None
|
| 662 |
-
self._last_completed = time.time()
|
| 663 |
-
|
| 664 |
-
try:
|
| 665 |
-
reachy_mini.goto_target(np.eye(4), antennas=[0.0, 0.0], duration=1.2)
|
| 666 |
-
except Exception:
|
| 667 |
-
self.logger.exception("Unable to interpolate Reachy Mini back to the base pose after shutdown.")
|
| 668 |
-
|
| 669 |
def _register_routes(self) -> None:
|
| 670 |
@self.settings_app.get("/api/emotions")
|
| 671 |
def list_emotions() -> dict[str, Any]:
|
|
@@ -744,28 +713,24 @@ class Emotions(ReachyMiniApp):
|
|
| 744 |
return self._save_review(move_id, payload)
|
| 745 |
|
| 746 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event) -> None:
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 750 |
with self._lock:
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
if move_to_play:
|
| 757 |
-
move = self._recorded_emotions.get(move_to_play)
|
| 758 |
-
reachy_mini.play_move(
|
| 759 |
-
move, initial_goto_duration=MOVE_INITIAL_GOTO_DURATION
|
| 760 |
-
)
|
| 761 |
-
with self._lock:
|
| 762 |
-
self._current_move = None
|
| 763 |
-
self._last_completed = time.time()
|
| 764 |
-
else:
|
| 765 |
-
stop_event.wait(0.01)
|
| 766 |
-
finally:
|
| 767 |
-
if stop_event.is_set():
|
| 768 |
-
self._play_shutdown_sequence(reachy_mini)
|
| 769 |
|
| 770 |
|
| 771 |
if __name__ == "__main__":
|
|
|
|
| 9 |
import os
|
| 10 |
from pathlib import Path
|
| 11 |
from typing import Any, Literal
|
|
|
|
|
|
|
| 12 |
from fastapi import HTTPException
|
| 13 |
from pydantic import BaseModel, Field
|
| 14 |
from ruamel.yaml import YAML
|
|
|
|
| 74 |
},
|
| 75 |
}
|
| 76 |
|
|
|
|
| 77 |
MOVE_INITIAL_GOTO_DURATION = 0.7
|
| 78 |
|
| 79 |
|
|
|
|
| 635 |
"precision": updated_move.precision if updated_move else None,
|
| 636 |
}
|
| 637 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
def _register_routes(self) -> None:
|
| 639 |
@self.settings_app.get("/api/emotions")
|
| 640 |
def list_emotions() -> dict[str, Any]:
|
|
|
|
| 713 |
return self._save_review(move_id, payload)
|
| 714 |
|
| 715 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event) -> None:
|
| 716 |
+
while not stop_event.is_set():
|
| 717 |
+
move_to_play: str | None = None
|
| 718 |
+
with self._lock:
|
| 719 |
+
if self._pending_move:
|
| 720 |
+
move_to_play = self._pending_move
|
| 721 |
+
self._pending_move = None
|
| 722 |
+
self._current_move = move_to_play
|
| 723 |
+
|
| 724 |
+
if move_to_play:
|
| 725 |
+
move = self._recorded_emotions.get(move_to_play)
|
| 726 |
+
reachy_mini.play_move(
|
| 727 |
+
move, initial_goto_duration=MOVE_INITIAL_GOTO_DURATION
|
| 728 |
+
)
|
| 729 |
with self._lock:
|
| 730 |
+
self._current_move = None
|
| 731 |
+
self._last_completed = time.time()
|
| 732 |
+
else:
|
| 733 |
+
stop_event.wait(0.01)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
|
| 735 |
|
| 736 |
if __name__ == "__main__":
|