Skip to content

Commit 9653653

Browse files
committed
misc: change callbacks input to dict. Cleans up types.
1 parent 2529054 commit 9653653

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

examples/fsm_walking_python_controller.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,11 @@ def ankle_homing_complete():
263263
)
264264
print("Ankle homing complete!")
265265

266+
callbacks = {"knee": knee_homing_complete, "ankle": ankle_homing_complete}
267+
266268
with osl, osl_fsm:
267269
osl.update()
268-
osl.home(callbacks=[knee_homing_complete, ankle_homing_complete])
270+
osl.home(callbacks=callbacks)
269271
input("Press Enter to start walking...")
270272

271273
# knee

opensourceleg/robots/osl.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import time
3-
from collections.abc import Iterable
43
from typing import Callable, Optional, Union
54

65
import 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

Comments
 (0)