Skip to content

[Bug Fix] fix: initialize CAN channel and prevent duplicate DM control-loop thread start#31

Open
whats2000 wants to merge 4 commits into
i2rt-robotics:mainfrom
whats2000:fix/get-robot-and-can-interface-init
Open

[Bug Fix] fix: initialize CAN channel and prevent duplicate DM control-loop thread start#31
whats2000 wants to merge 4 commits into
i2rt-robotics:mainfrom
whats2000:fix/get-robot-and-can-interface-init

Conversation

@whats2000
Copy link
Copy Markdown

@whats2000 whats2000 commented Apr 8, 2026

What does this PR do?

This PR fixes two initialization and runtime stability issues in the robot stack:

  1. Initializes the CAN channel attribute in the CAN interface constructor so channel state is always defined.
  2. Makes control-loop startup idempotent in DMChainCanInterface by guarding start_thread() so the control thread is not started twice.

These changes improve startup reliability and prevent duplicate control-loop startup.

Why is this needed?

  • Missing or late channel attribute setup can cause inconsistent CAN interface state handling.
  • Starting the control-loop thread multiple times can create unstable state updates and hard-to-debug hardware behavior.

What files are changed?

  • can_interface.py
  • dm_driver.py

How was this tested?

Manual QA

Local validation

  • Verified the fix scope is limited to CAN interface initialization and DM control-loop startup behavior.
  • Focused automated tests: not run.
  • Full test suite: not run.

QA Result

PASS on Yam Ultra hardware and integration flows above.
No regressions observed in startup/control-loop behavior during these runs.

Risks and mitigations

  • Risk: Changes touch startup and threading behavior in the motor control path.
  • Mitigation: Scope is narrow, behavior is guarded and idempotent, and hardware validation was completed on Yam Ultra plus lerobot integration flow.

Checklist

  • PR is scoped to one logical fix set.
  • No unrelated refactors included.
  • Added or updated automated tests where appropriate.
  • QA steps completed and results recorded.

Related commits

  • fix(can_interface): initialize channel attribute in constructor
  • fix(dm_driver): guard duplicate control-loop thread start

Copilot AI review requested due to automatic review settings April 8, 2026 19:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve robot startup stability by fixing CAN interface initialization state and adjusting YAM motor-chain initialization in get_yam_robot to avoid unintended side effects from repeated initialization/startup patterns.

Changes:

  • Initialize CanInterface.channel in the constructor to ensure consistent object state.
  • Change YAM real-hardware motor-chain creation to start the control thread immediately and remove the later manual start_thread() call.
  • Update comments/logging around the YAM initialization sequence.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
i2rt/robots/get_robot.py Changes motor-chain startup timing and wrap-around offset correction flow for real hardware initialization.
i2rt/motor_drivers/can_interface.py Sets self.channel during construction so the interface has a defined channel attribute immediately.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread i2rt/robots/get_robot.py Outdated
Comment thread i2rt/robots/get_robot.py Outdated
Comment thread i2rt/robots/get_robot.py Outdated
@whats2000 whats2000 changed the title [Bug Fix] fix: stabilize get_robot and CAN interface initialization error [Bug Fix] fix: initialize CAN channel and prevent duplicate DM control-loop thread start Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants