Spaces:
Running
Running
RemiFabre commited on
Commit ·
100f98d
1
Parent(s): c1f8d54
refactor: extract listening antenna blending into helper
Browse files
src/reachy_mini_conversation_demo/moves.py
CHANGED
|
@@ -525,6 +525,8 @@ class MovementManager:
|
|
| 525 |
idle_for = current_time - self.state.last_activity_time
|
| 526 |
if idle_for >= self.idle_inactivity_delay:
|
| 527 |
try:
|
|
|
|
|
|
|
| 528 |
_, current_antennas = self.current_robot.get_current_joint_positions()
|
| 529 |
current_head_pose = self.current_robot.get_current_head_pose()
|
| 530 |
|
|
@@ -625,6 +627,46 @@ class MovementManager:
|
|
| 625 |
)
|
| 626 |
return (secondary_head_pose, (0, 0), 0)
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
def _update_face_tracking(self, current_time: float) -> None:
|
| 629 |
"""Get face tracking offsets from camera worker thread."""
|
| 630 |
if self.camera_worker is not None:
|
|
@@ -704,37 +746,7 @@ class MovementManager:
|
|
| 704 |
|
| 705 |
# 6) Apply listening antenna freeze or blend-back
|
| 706 |
head, antennas, body_yaw = global_full_body_pose
|
| 707 |
-
|
| 708 |
-
listening = self._is_listening
|
| 709 |
-
listening_antennas = self._listening_antennas
|
| 710 |
-
blend = self._antenna_unfreeze_blend
|
| 711 |
-
blend_duration = self._antenna_blend_duration
|
| 712 |
-
last_update = self._last_listening_blend_time
|
| 713 |
-
self._last_listening_blend_time = now_monotonic
|
| 714 |
-
|
| 715 |
-
if listening:
|
| 716 |
-
antennas_cmd = listening_antennas
|
| 717 |
-
new_blend = 0.0
|
| 718 |
-
else:
|
| 719 |
-
dt = max(0.0, now_monotonic - last_update)
|
| 720 |
-
if blend_duration <= 0:
|
| 721 |
-
new_blend = 1.0
|
| 722 |
-
else:
|
| 723 |
-
new_blend = min(1.0, blend + dt / blend_duration)
|
| 724 |
-
antennas_cmd = (
|
| 725 |
-
listening_antennas[0] * (1.0 - new_blend) + antennas[0] * new_blend,
|
| 726 |
-
listening_antennas[1] * (1.0 - new_blend) + antennas[1] * new_blend,
|
| 727 |
-
)
|
| 728 |
-
|
| 729 |
-
if listening:
|
| 730 |
-
self._antenna_unfreeze_blend = 0.0
|
| 731 |
-
else:
|
| 732 |
-
self._antenna_unfreeze_blend = new_blend
|
| 733 |
-
if new_blend >= 1.0:
|
| 734 |
-
self._listening_antennas = (
|
| 735 |
-
float(antennas[0]),
|
| 736 |
-
float(antennas[1]),
|
| 737 |
-
)
|
| 738 |
|
| 739 |
# 7) Single set_target call - the only control point
|
| 740 |
try:
|
|
|
|
| 525 |
idle_for = current_time - self.state.last_activity_time
|
| 526 |
if idle_for >= self.idle_inactivity_delay:
|
| 527 |
try:
|
| 528 |
+
# These 2 functions return the latest available sensor data from the robot, but don't perform I/O synchronously.
|
| 529 |
+
# Therefore, we accept calling them inside the control loop.
|
| 530 |
_, current_antennas = self.current_robot.get_current_joint_positions()
|
| 531 |
current_head_pose = self.current_robot.get_current_head_pose()
|
| 532 |
|
|
|
|
| 627 |
)
|
| 628 |
return (secondary_head_pose, (0, 0), 0)
|
| 629 |
|
| 630 |
+
def _calculate_blended_antennas(
|
| 631 |
+
self, target_antennas: Tuple[float, float]
|
| 632 |
+
) -> Tuple[float, float]:
|
| 633 |
+
"""Blend target antennas with listening freeze state and update blending."""
|
| 634 |
+
now = self._now()
|
| 635 |
+
listening = self._is_listening
|
| 636 |
+
listening_antennas = self._listening_antennas
|
| 637 |
+
blend = self._antenna_unfreeze_blend
|
| 638 |
+
blend_duration = self._antenna_blend_duration
|
| 639 |
+
last_update = self._last_listening_blend_time
|
| 640 |
+
self._last_listening_blend_time = now
|
| 641 |
+
|
| 642 |
+
if listening:
|
| 643 |
+
antennas_cmd = listening_antennas
|
| 644 |
+
new_blend = 0.0
|
| 645 |
+
else:
|
| 646 |
+
dt = max(0.0, now - last_update)
|
| 647 |
+
if blend_duration <= 0:
|
| 648 |
+
new_blend = 1.0
|
| 649 |
+
else:
|
| 650 |
+
new_blend = min(1.0, blend + dt / blend_duration)
|
| 651 |
+
antennas_cmd = (
|
| 652 |
+
listening_antennas[0] * (1.0 - new_blend)
|
| 653 |
+
+ target_antennas[0] * new_blend,
|
| 654 |
+
listening_antennas[1] * (1.0 - new_blend)
|
| 655 |
+
+ target_antennas[1] * new_blend,
|
| 656 |
+
)
|
| 657 |
+
|
| 658 |
+
if listening:
|
| 659 |
+
self._antenna_unfreeze_blend = 0.0
|
| 660 |
+
else:
|
| 661 |
+
self._antenna_unfreeze_blend = new_blend
|
| 662 |
+
if new_blend >= 1.0:
|
| 663 |
+
self._listening_antennas = (
|
| 664 |
+
float(target_antennas[0]),
|
| 665 |
+
float(target_antennas[1]),
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
+
return antennas_cmd
|
| 669 |
+
|
| 670 |
def _update_face_tracking(self, current_time: float) -> None:
|
| 671 |
"""Get face tracking offsets from camera worker thread."""
|
| 672 |
if self.camera_worker is not None:
|
|
|
|
| 746 |
|
| 747 |
# 6) Apply listening antenna freeze or blend-back
|
| 748 |
head, antennas, body_yaw = global_full_body_pose
|
| 749 |
+
antennas_cmd = self._calculate_blended_antennas(antennas)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 750 |
|
| 751 |
# 7) Single set_target call - the only control point
|
| 752 |
try:
|