Skip to content
Merged
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
4 changes: 4 additions & 0 deletions damiao_motor/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def __init__(
self,
channel: str = "can0",
bustype: str = "socketcan",
fd: bool = False,
bitrate: Optional[int] = None,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -149,6 +150,7 @@ def __init__(
bus_kwargs: Dict[str, Any] = {
"channel": channel,
"interface": bustype,
"fd": fd,
**kwargs,
}
if bitrate is not None:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion damiao_motor/core/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -439,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
arbitration_id=arbitration_id,
data=data,
is_extended_id=False,
is_fd=self._fd,
)
self.bus.send(msg)
except OSError as e:
Expand Down Expand Up @@ -927,6 +932,10 @@ def write_register(self, rid: int, value: float | int) -> None:
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)

Expand Down
Loading