feat(motors): switch Damiao motors to MIT mode in configure_motors#3753
Open
xixinzhang wants to merge 2 commits into
Open
feat(motors): switch Damiao motors to MIT mode in configure_motors#3753xixinzhang wants to merge 2 commits into
xixinzhang wants to merge 2 commits into
Conversation
DamiaoMotorsBus assumed motors were already flashed to MIT control mode but never enforced or established it. A motor flashed to POS_VEL / VEL / TORQUE_POS by DM_Tool would silently misinterpret MIT-format CAN frames, producing erratic motion with no diagnostic. Mirror the sibling RobstrideMotorsBus pattern: track per-motor operation mode in memory, write CTRL_MODE = MIT to each motor's RAM at every configure_motors() call, and guard MIT control sends with an in-memory assertion. RAM-only write, no flash wear; re-issued on every connect. Wires up the previously-unused CAN_CMD_WRITE_PARAM, ControlMode, and MotorVariable constants from tables.py.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds operation mode tracking and switching for Damiao motors, specifically ensuring motors are in MIT control mode before accepting MIT control commands.
Changes:
- Introduces a
_switch_operation_modemethod that sends a CAN parameter write command to change the motor's control mode. - During
configure_motors, each motor is now explicitly switched to MIT mode before being enabled. - Runtime guards are added in
_mit_controland_mit_control_batchto reject commands if the motor isn't confirmed to be in MIT mode.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+299
to
+300
| if self._recv_motor_response(expected_recv_id=recv_id, timeout=MEDIUM_TIMEOUT_SEC) is not None: | ||
| self.operation_mode[motor_name] = mode |
Comment on lines
+157
to
+158
| # Motor Mode | ||
| self.operation_mode: dict[str, ControlMode] = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DamiaoMotorsBusassumed motors were already flashed to MIT control mode but never enforced or established it. A motor flashed to POS_VEL / VEL / TORQUE_POS by DM_Tool would silently misinterpret MIT-format frames with no diagnostic.This PR mirrors the sibling
RobstrideMotorsBuspattern: writeCTRL_MODE = MITto each motor's RAM inconfigure_motors()and assert the cached mode before MIT control sends. RAM-only write, no flash wear; re-issued on every connect.Test plan
uv run ruff check src/lerobot/motors/damiao/— passes.