Skip to content

fix(dm_driver): start control loop when start_thread=True#59

Closed
nu-jliu wants to merge 2 commits into
mainfrom
fix/dm-driver-start-thread-guard
Closed

fix(dm_driver): start control loop when start_thread=True#59
nu-jliu wants to merge 2 commits into
mainfrom
fix/dm-driver-start-thread-guard

Conversation

@nu-jliu

@nu-jliu nu-jliu commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
  • i2rt/motor_drivers/dm_driver.py: initialize start_thread_flag to False in DMChainCanInterface.init instead of to the start_thread argument. Setting it to True before calling start_thread() made the guard if self.start_thread_flag: return short-circuit, so the 250 Hz control loop never spawned on the default start_thread=True path. The failure was silent: _motor_on() already set self.state and self.running, so there was no exception or hang -- set_commands() was never flushed and read_states() returned a stale snapshot.
  • i2rt/motor_drivers/tests/test_dm_driver.py: add a hardware-free regression matrix (CAN + _motor_on mocked) covering every call pattern -- start_thread True/False crossed with the number of explicit start_thread() calls -- asserting the loop thread spawns exactly once where requested, stays idempotent under repeated calls, and never spawns when the caller opts out.

nu-jliu and others added 2 commits May 29, 2026 16:31
- i2rt/motor_drivers/dm_driver.py: initialize start_thread_flag to False in
  DMChainCanInterface.__init__ instead of to the start_thread argument. Setting it
  to True before calling start_thread() made the guard `if self.start_thread_flag:
  return` short-circuit, so the 250 Hz control loop never spawned on the default
  start_thread=True path. The failure was silent: _motor_on() already set self.state
  and self.running, so there was no exception or hang -- set_commands() was never
  flushed and read_states() returned a stale snapshot.
- i2rt/motor_drivers/tests/test_dm_driver.py: add a hardware-free regression matrix
  (CAN + _motor_on mocked) covering every call pattern -- start_thread True/False
  crossed with the number of explicit start_thread() calls -- asserting the loop
  thread spawns exactly once where requested, stays idempotent under repeated calls,
  and never spawns when the caller opts out.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@nu-jliu nu-jliu closed this Jun 25, 2026
@nu-jliu nu-jliu deleted the fix/dm-driver-start-thread-guard branch June 25, 2026 02:12
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.

1 participant