From 15f0d6d8dc9bc60cde255d3430c5622f5e25d1c6 Mon Sep 17 00:00:00 2001 From: umeow0716 Date: Fri, 29 May 2026 14:02:03 +0800 Subject: [PATCH 1/3] feat: add support for flexible data frame (fd) option in DaMiaoController and DaMiaoMotor --- damiao_motor/core/controller.py | 4 ++++ damiao_motor/core/motor.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/damiao_motor/core/controller.py b/damiao_motor/core/controller.py index 699e0d5..45194e0 100644 --- a/damiao_motor/core/controller.py +++ b/damiao_motor/core/controller.py @@ -116,6 +116,7 @@ def __init__( self, channel: str = "can0", bustype: str = "socketcan", + fd: bool = False, bitrate: Optional[int] = None, **kwargs: Any, ) -> None: @@ -149,6 +150,7 @@ def __init__( bus_kwargs: Dict[str, Any] = { "channel": channel, "interface": bustype, + "fd": fd, **kwargs, } if bitrate is not None: @@ -162,6 +164,7 @@ def __init__( self._polling_thread: Optional[threading.Thread] = None self._polling_active = False self._polling_lock = threading.Lock() + self._fd = fd # ----------------------- # Motor management @@ -192,6 +195,7 @@ def add_motor( feedback_id=feedback_id, bus=self.bus, motor_type=motor_type, + fd=self._fd, **kwargs, ) self.motors[motor_id] = motor diff --git a/damiao_motor/core/motor.py b/damiao_motor/core/motor.py index 45953b4..a2c8ff4 100644 --- a/damiao_motor/core/motor.py +++ b/damiao_motor/core/motor.py @@ -279,6 +279,7 @@ def __init__( motor_id: int, feedback_id: int, bus: can.Bus, + fd: bool, *, motor_type: str, p_min: Optional[float] = None, @@ -323,6 +324,7 @@ def __init__( self.register_request_time_lock = threading.Lock() self.register_reply_time: Dict[int, float] = {} self.register_reply_time_lock = threading.Lock() + self._fd = fd def _resolve_limits(self, motor_type: str) -> Dict[str, float]: """Resolve limits from motor_type preset. Returns a dict of the 6 P/V/T limit values.""" @@ -439,7 +441,7 @@ def send_raw(self, data: bytes, arbitration_id: int | None = None) -> None: try: msg = can.Message( - arbitration_id=arbitration_id, data=data, is_extended_id=False + arbitration_id=arbitration_id, data=data, is_extended_id=False, is_fd=self._fd ) self.bus.send(msg) except OSError as e: From 7d50d971f998b78e1184a40e8f649e691d58cc7c Mon Sep 17 00:00:00 2001 From: umeow0716 Date: Sat, 30 May 2026 15:05:28 +0800 Subject: [PATCH 2/3] feat: clear stale cache before sending write command in DaMiaoMotor --- damiao_motor/core/motor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/damiao_motor/core/motor.py b/damiao_motor/core/motor.py index a2c8ff4..2b84251 100644 --- a/damiao_motor/core/motor.py +++ b/damiao_motor/core/motor.py @@ -928,6 +928,10 @@ def write_register(self, rid: int, value: float | int) -> None: raise ValueError( f"Unknown data_type: {reg_info.data_type} for register {rid}" ) + + # Clear stale cache before sending write command. + with self.registers_lock: + self.registers.pop(rid, None) # Send write command self._send_register_cmd(0x55, rid, data_bytes) From 2254bcf48f8bda4c4b7227e53724ed23d9a282e1 Mon Sep 17 00:00:00 2001 From: umeow0716 Date: Wed, 3 Jun 2026 20:14:03 +0800 Subject: [PATCH 3/3] style: format motor core with ruff --- damiao_motor/core/motor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/damiao_motor/core/motor.py b/damiao_motor/core/motor.py index 2b84251..40b9dcb 100644 --- a/damiao_motor/core/motor.py +++ b/damiao_motor/core/motor.py @@ -441,7 +441,10 @@ def send_raw(self, data: bytes, arbitration_id: int | None = None) -> None: try: msg = can.Message( - arbitration_id=arbitration_id, data=data, is_extended_id=False, is_fd=self._fd + arbitration_id=arbitration_id, + data=data, + is_extended_id=False, + is_fd=self._fd, ) self.bus.send(msg) except OSError as e: @@ -928,7 +931,7 @@ def write_register(self, rid: int, value: float | int) -> None: raise ValueError( f"Unknown data_type: {reg_info.data_type} for register {rid}" ) - + # Clear stale cache before sending write command. with self.registers_lock: self.registers.pop(rid, None)