Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ ignore_errors = false
module = "lerobot.cameras.*"
ignore_errors = false

# [[tool.mypy.overrides]]
# module = "lerobot.motors.*"
# ignore_errors = false
[[tool.mypy.overrides]]
module = "lerobot.motors.*"
ignore_errors = false

# [[tool.mypy.overrides]]
# module = "lerobot.robots.*"
Expand Down
10 changes: 6 additions & 4 deletions src/lerobot/motors/calibration_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self, bus: MotorsBus, groups: dict[str, list[str]] | None = None):

self.bus = bus
self.groups = groups if groups is not None else {"all": list(bus.motors)}
self.group_names = list(groups)
self.group_names = list(self.groups)
self.current_group = self.group_names[0]

if not bus.is_connected:
Expand All @@ -230,18 +230,20 @@ def __init__(self, bus: MotorsBus, groups: dict[str, list[str]] | None = None):
self.calibration = bus.read_calibration()
self.res_table = bus.model_resolution_table
self.present_cache = {
m: bus.read("Present_Position", m, normalize=False) for motors in groups.values() for m in motors
m: bus.read("Present_Position", m, normalize=False)
for motors in self.groups.values()
for m in motors
}

pygame.init()
self.font = pygame.font.Font(None, FONT_SIZE)

label_pad = max(self.font.size(m)[0] for ms in groups.values() for m in ms)
label_pad = max(self.font.size(m)[0] for ms in self.groups.values() for m in ms)
self.label_pad = label_pad
width = 40 + label_pad + BAR_LEN + 6 + BTN_W + 10 + SAVE_W + 10
self.controls_bottom = 10 + SAVE_H
self.base_y = self.controls_bottom + TOP_GAP
height = self.base_y + PADDING_Y * len(groups[self.current_group]) + 40
height = self.base_y + PADDING_Y * len(self.groups[self.current_group]) + 40

self.screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Motors range finder")
Expand Down
18 changes: 9 additions & 9 deletions src/lerobot/motors/dynamixel/dynamixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ def read_calibration(self) -> dict[str, MotorCalibration]:
for motor, m in self.motors.items():
calibration[motor] = MotorCalibration(
id=m.id,
drive_mode=drive_modes[motor],
homing_offset=offsets[motor],
range_min=mins[motor],
range_max=maxes[motor],
drive_mode=int(drive_modes[motor]),
homing_offset=int(offsets[motor]),
range_min=int(mins[motor]),
range_max=int(maxes[motor]),
)

return calibration
Expand All @@ -198,15 +198,15 @@ def write_calibration(self, calibration_dict: dict[str, MotorCalibration], cache
if cache:
self.calibration = calibration_dict

def disable_torque(self, motors: str | list[str] | None = None, num_retry: int = 0) -> None:
def disable_torque(self, motors: int | str | list[str] | None = None, num_retry: int = 0) -> None:
for motor in self._get_motors_list(motors):
self.write("Torque_Enable", motor, TorqueMode.DISABLED.value, num_retry=num_retry)

def _disable_torque(self, motor: int, model: str, num_retry: int = 0) -> None:
addr, length = get_address(self.model_ctrl_table, model, "Torque_Enable")
self._write(addr, length, motor, TorqueMode.DISABLED.value, num_retry=num_retry)

def enable_torque(self, motors: str | list[str] | None = None, num_retry: int = 0) -> None:
def enable_torque(self, motors: int | str | list[str] | None = None, num_retry: int = 0) -> None:
for motor in self._get_motors_list(motors):
self.write("Torque_Enable", motor, TorqueMode.ENABLED.value, num_retry=num_retry)

Expand All @@ -230,12 +230,12 @@ def _decode_sign(self, data_name: str, ids_values: dict[int, int]) -> dict[int,

return ids_values

def _get_half_turn_homings(self, positions: dict[NameOrID, Value]) -> dict[NameOrID, Value]:
def _get_half_turn_homings(self, positions: dict[str, Value]) -> dict[str, Value]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the change for _get_half_turn_homings motivated from the fact that the function is only ever called with a dict[str,Value] as an input?

"""
On Dynamixel Motors:
Present_Position = Actual_Position + Homing_Offset
"""
half_turn_homings = {}
half_turn_homings: dict[str, Value] = {}
for motor, pos in positions.items():
model = self._get_motor_model(motor)
max_res = self.model_resolution_table[model] - 1
Expand All @@ -258,6 +258,6 @@ def broadcast_ping(self, num_retry: int = 0, raise_on_error: bool = False) -> di
if raise_on_error:
raise ConnectionError(self.packet_handler.getTxRxResult(comm))

return
return None

return {id_: data[0] for id_, data in data_list.items()}
20 changes: 10 additions & 10 deletions src/lerobot/motors/feetech/feetech.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(

self.port_handler = scs.PortHandler(self.port)
# HACK: monkeypatch
self.port_handler.setPacketTimeout = patch_setPacketTimeout.__get__(
self.port_handler.setPacketTimeout = patch_setPacketTimeout.__get__( # type: ignore[method-assign]
self.port_handler, scs.PortHandler
)
self.packet_handler = scs.PacketHandler(protocol_version)
Expand Down Expand Up @@ -262,9 +262,9 @@ def read_calibration(self) -> dict[str, MotorCalibration]:
calibration[motor] = MotorCalibration(
id=m.id,
drive_mode=0,
homing_offset=offsets[motor],
range_min=mins[motor],
range_max=maxes[motor],
homing_offset=int(offsets[motor]),
range_min=int(mins[motor]),
range_max=int(maxes[motor]),
)

return calibration
Expand All @@ -279,20 +279,20 @@ def write_calibration(self, calibration_dict: dict[str, MotorCalibration], cache
if cache:
self.calibration = calibration_dict

def _get_half_turn_homings(self, positions: dict[NameOrID, Value]) -> dict[NameOrID, Value]:
def _get_half_turn_homings(self, positions: dict[str, Value]) -> dict[str, Value]:
"""
On Feetech Motors:
Present_Position = Actual_Position - Homing_Offset
"""
half_turn_homings = {}
half_turn_homings: dict[str, Value] = {}
for motor, pos in positions.items():
model = self._get_motor_model(motor)
max_res = self.model_resolution_table[model] - 1
half_turn_homings[motor] = pos - int(max_res / 2)

return half_turn_homings

def disable_torque(self, motors: str | list[str] | None = None, num_retry: int = 0) -> None:
def disable_torque(self, motors: int | str | list[str] | None = None, num_retry: int = 0) -> None:
for motor in self._get_motors_list(motors):
self.write("Torque_Enable", motor, TorqueMode.DISABLED.value, num_retry=num_retry)
self.write("Lock", motor, 0, num_retry=num_retry)
Expand All @@ -303,7 +303,7 @@ def _disable_torque(self, motor: int, model: str, num_retry: int = 0) -> None:
addr, length = get_address(self.model_ctrl_table, model, "Lock")
self._write(addr, length, motor, 0, num_retry=num_retry)

def enable_torque(self, motors: str | list[str] | None = None, num_retry: int = 0) -> None:
def enable_torque(self, motors: int | str | list[str] | None = None, num_retry: int = 0) -> None:
for motor in self._get_motors_list(motors):
self.write("Torque_Enable", motor, TorqueMode.ENABLED.value, num_retry=num_retry)
self.write("Lock", motor, 1, num_retry=num_retry)
Expand Down Expand Up @@ -334,7 +334,7 @@ def _split_into_byte_chunks(self, value: int, length: int) -> list[int]:
def _broadcast_ping(self) -> tuple[dict[int, int], int]:
import scservo_sdk as scs

data_list = {}
data_list: dict[int, int] = {}

status_length = 6

Expand Down Expand Up @@ -414,7 +414,7 @@ def broadcast_ping(self, num_retry: int = 0, raise_on_error: bool = False) -> di
if not self._is_comm_success(comm):
if raise_on_error:
raise ConnectionError(self.packet_handler.getTxRxResult(comm))
return
return None

ids_errors = {id_: status for id_, status in ids_status.items() if self._is_error(status)}
if ids_errors:
Expand Down
Loading
Loading