mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-24 13:09:43 +00:00
robstride: remove redundant timeout and max_messages casts
This commit is contained in:
@@ -217,7 +217,7 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
raise ConnectionError(f"Failed to connect to CAN bus: {e}") from e
|
raise ConnectionError(f"Failed to connect to CAN bus: {e}") from e
|
||||||
|
|
||||||
def _query_status_via_clear_fault(
|
def _query_status_via_clear_fault(
|
||||||
self, motor: NameOrID, timeout: float | None = None
|
self, motor: NameOrID, timeout: float = RUNNING_TIMEOUT
|
||||||
) -> tuple[bool, can.Message | None]:
|
) -> tuple[bool, can.Message | None]:
|
||||||
motor_name = self._get_motor_name(motor)
|
motor_name = self._get_motor_name(motor)
|
||||||
motor_id = self._get_motor_id(motor_name)
|
motor_id = self._get_motor_id(motor_name)
|
||||||
@@ -225,8 +225,7 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
data = [0xFF] * 7 + [CAN_CMD_CLEAR_FAULT]
|
data = [0xFF] * 7 + [CAN_CMD_CLEAR_FAULT]
|
||||||
msg = can.Message(arbitration_id=motor_id, data=data, is_extended_id=False)
|
msg = can.Message(arbitration_id=motor_id, data=data, is_extended_id=False)
|
||||||
self._bus().send(msg)
|
self._bus().send(msg)
|
||||||
wait_s = RUNNING_TIMEOUT if timeout is None else float(timeout)
|
return self._recv_status_via_clear_fault(expected_recv_id=recv_id, timeout=timeout)
|
||||||
return self._recv_status_via_clear_fault(expected_recv_id=recv_id, timeout=wait_s)
|
|
||||||
|
|
||||||
def _recv_status_via_clear_fault(
|
def _recv_status_via_clear_fault(
|
||||||
self, expected_recv_id: int | None = None, timeout: float = RUNNING_TIMEOUT
|
self, expected_recv_id: int | None = None, timeout: float = RUNNING_TIMEOUT
|
||||||
@@ -512,7 +511,7 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
def _recv_all_messages_until_quiet(
|
def _recv_all_messages_until_quiet(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
timeout: float,
|
timeout: float = RUNNING_TIMEOUT,
|
||||||
max_messages: int = 4096,
|
max_messages: int = 4096,
|
||||||
) -> list[can.Message]:
|
) -> list[can.Message]:
|
||||||
"""
|
"""
|
||||||
@@ -524,17 +523,17 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
max_messages: Safety cap to prevent unbounded loops.
|
max_messages: Safety cap to prevent unbounded loops.
|
||||||
"""
|
"""
|
||||||
out: list[can.Message] = []
|
out: list[can.Message] = []
|
||||||
cap = max(1, int(max_messages))
|
max_messages = max(1, max_messages)
|
||||||
recv_timeout = max(0.0, float(timeout))
|
timeout = max(0.0, timeout)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while len(out) < cap:
|
while len(out) < max_messages:
|
||||||
msg = self._bus().recv(timeout=recv_timeout)
|
msg = self._bus().recv(timeout=timeout)
|
||||||
if msg is None:
|
if msg is None:
|
||||||
break
|
break
|
||||||
out.append(msg)
|
out.append(msg)
|
||||||
except (can.CanError, OSError) as e:
|
except (can.CanError, OSError) as e:
|
||||||
logger.debug("Error draining CAN RX queue on %s: %s", self.port, e)
|
logger.debug(f"Error draining CAN RX queue on {self.port}: {e}")
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@@ -583,11 +582,11 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
to clear residual frames left on the interface from previous sessions.
|
to clear residual frames left on the interface from previous sessions.
|
||||||
"""
|
"""
|
||||||
drained = 0
|
drained = 0
|
||||||
timeout_s = max(0.0, float(poll_timeout_s))
|
poll_timeout_s = max(0.0, poll_timeout_s)
|
||||||
cap = max(1, int(max_messages))
|
max_messages = max(1, max_messages)
|
||||||
try:
|
try:
|
||||||
while drained < cap:
|
while drained < max_messages:
|
||||||
msg = self._bus().recv(timeout=timeout_s)
|
msg = self._bus().recv(timeout=poll_timeout_s)
|
||||||
if msg is None:
|
if msg is None:
|
||||||
break
|
break
|
||||||
drained += 1
|
drained += 1
|
||||||
@@ -736,7 +735,7 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
recv_id_to_motor[self._get_motor_recv_id(motor)] = motor_name
|
recv_id_to_motor[self._get_motor_recv_id(motor)] = motor_name
|
||||||
# Read every feedback frame until RX goes quiet, then decode all of them.
|
# Read every feedback frame until RX goes quiet, then decode all of them.
|
||||||
# This avoids dropping useful frames when responses from different motors interleave.
|
# This avoids dropping useful frames when responses from different motors interleave.
|
||||||
messages = self._recv_all_messages_until_quiet(timeout=RUNNING_TIMEOUT)
|
messages = self._recv_all_messages_until_quiet()
|
||||||
processed_recv_ids = self._process_feedback_messages(messages)
|
processed_recv_ids = self._process_feedback_messages(messages)
|
||||||
|
|
||||||
for recv_id, motor_name in recv_id_to_motor.items():
|
for recv_id, motor_name in recv_id_to_motor.items():
|
||||||
@@ -946,7 +945,7 @@ class RobstrideMotorsBus(MotorsBusBase):
|
|||||||
msg = can.Message(arbitration_id=motor_id, data=data, is_extended_id=False)
|
msg = can.Message(arbitration_id=motor_id, data=data, is_extended_id=False)
|
||||||
self._bus().send(msg)
|
self._bus().send(msg)
|
||||||
|
|
||||||
messages = self._recv_all_messages_until_quiet(timeout=RUNNING_TIMEOUT)
|
messages = self._recv_all_messages_until_quiet()
|
||||||
processed_recv_ids = self._process_feedback_messages(messages)
|
processed_recv_ids = self._process_feedback_messages(messages)
|
||||||
|
|
||||||
for motor in updated_motors:
|
for motor in updated_motors:
|
||||||
|
|||||||
Reference in New Issue
Block a user