11import os
22import time
3- from collections .abc import Iterable
43from typing import Callable , Optional , Union
54
65import numpy as np
@@ -44,7 +43,7 @@ def home(
4443 output_position_offset : Optional [dict [str , float ]] = None ,
4544 current_threshold : int = 5000 ,
4645 velocity_threshold : float = 0.001 ,
47- callbacks : Optional ["Iterable[Optional[Callable[[], None]]]" ] = None ,
46+ callbacks : Optional [dict [ str , Callable ] ] = None ,
4847 ) -> None :
4948 """
5049 Call the home method for all actuators.
@@ -58,16 +57,17 @@ def home(
5857 Default is 0.0 for knee and 30.0 for ankle.
5958 current_threshold: The current threshold to apply to the actuators during homing. Default is 5000.
6059 velocity_threshold: The velocity threshold to apply to the actuators during homing. Default is 0.001.
61- callbacks ( Optional[Iterable[Optional[Callable[[], None]]]]) :
62- Optional list or iterable of callback functions, one per actuator,
63- to be called when each actuator's homing completes .
60+ callbacks Optional[dict[str, Callable]] :
61+ Optional dictionary of callback functions, one per actuator, to be called when each actuator's
62+ homing completes. Only one callback per actuator is supported, and the tag must match .
6463 Each function should take no arguments and return None. If None, no callbacks are used.
6564 """
6665 if output_position_offset is None :
6766 output_position_offset = {"knee" : 0.0 , "ankle" : np .deg2rad (30.0 )}
6867 if homing_direction is None :
6968 homing_direction = {"knee" : - 1 , "ankle" : - 1 }
70- for actuator , callback in zip (self .actuators .values (), callbacks or [None ] * len (self .actuators )):
69+ for actuator in self .actuators .values ():
70+ callback = callbacks .get (actuator .tag , None ) if callbacks is not None else None
7171 actuator .home (
7272 homing_voltage = homing_voltage ,
7373 homing_frequency = homing_frequency ,
0 commit comments