Skip to content

fix(machine): select the WCS through the driver - #636

Merged
knipknap merged 1 commit into
barebaric:mainfrom
medoix:fix/ruida-current-wcs
Oct 26, 2026
Merged

knipknap merged 1 commit into
barebaric:mainfrom
medoix:fix/ruida-current-wcs

Conversation

@medoix

@medoix medoix commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR change?

Selecting the "Current position" origin (Ruida WCS CURRENT) never reached the Ruida driver.

  • MachineController.switch_active_wcs() sent the WCS name to the device with run_raw(). That works where the name is a command (G54 to G59 on G-code controllers), but the Ruida names (MACHINE, ANCHOR, CURRENT, SET_POINT) are not rpascript. The adapter kept MACHINE, so the switch was logged as Device did not confirm WCS switch to CURRENT, got MACHINE.
  • After any reconnect, sync_active_wcs_from_device() read MACHINE back from the adapter and reset the machine's selection, so jobs could silently run from the machine origin instead.

Changes:

  • switch_active_wcs() calls driver.select_wcs() instead of run_raw().
  • The base Driver.select_wcs() now sends the name with run_raw(), so GRBL and other G-code drivers send exactly what they sent before.
  • The Ruida adapter starts from the machine's active WCS when it is one of its reference points, so a rebuilt adapter no longer reverts the selection to MACHINE. A Ruida controller does not store this selection, so the machine model is its only record.

Why did you choose this specific architectural approach?

Driver.select_wcs() already exists as the driver hook for choosing a WCS, and the Ruida adapter already implements it, but the UI path went around it. Routing switch_active_wcs() through select_wcs() lets each driver decide what selecting a WCS means, and giving the base method the old run_raw() behaviour keeps the G-code drivers unchanged without touching them.

Alternatives considered:

  • Special-casing Ruida in the controller. That puts driver knowledge in the core.
  • Making the Ruida run_raw() recognise WCS names. That mixes WCS selection into the raw rpascript path, and read_parser_state() would still be reset on reconnect.

MachineController.select_wcs() also calls driver.select_wcs(); it has no callers today, so the new base behaviour does not change any existing path.

Known limitation, not addressed here: the Ruida frame() sends absolute moves, so framing still ignores the selected origin. That needs its own change.

How did you manually test this locally?

RDLC-V26.60.20 controller over UDP and an RDC8445S over TCP.

  1. In the bottom panel, choose the "Current position" origin. Before: log shows "Device did not confirm WCS switch to CURRENT, got MACHINE". After: no warning, and later syncs log "Synced active WCS from device: 'CURRENT'".
  2. Place a small design at the canvas origin, jog the head with the controller panel to a clear spot, and run a low-power cut. The captured job starts with REF_POINT_CURRENT (D8 12) and the controller cuts at the head position instead of returning to the machine origin.
  3. Switch to another machine and back (reconnect). The origin stays "Current position" instead of reverting to the machine origin.

Tests: new tests check that switch_active_wcs() goes through select_wcs() without run_raw(), that the base select_wcs() sends the name with run_raw(), and that a new Ruida adapter reports the machine's WCS (falling back to MACHINE for G54). The machine and Ruida driver test folders pass apart from test_end_failed_carries_message and test_failed_job_reports_error_message, which fail the same way on unmodified main in my environment.

Checklist

  • I am not an AI. I have manually read the code and understand it.
  • I take full responsibility for the quality and architectural fit of
    this code.
  • I agree to publish this code under the MIT license.

switch_active_wcs() sent the WCS name to the device with run_raw(),
which only works where the name is a command (G54 to G59 on G-code
controllers). The Ruida driver's WCS names (MACHINE, ANCHOR, CURRENT,
SET_POINT) are not rpascript, so selecting "CURRENT" sent an unknown
line, the adapter kept MACHINE, and the switch was reported as not
confirmed. A reconnect then synced MACHINE back into the model.

- switch_active_wcs() now calls driver.select_wcs(). The base
  implementation sends the name with run_raw(), so G-code drivers
  behave as before; the Ruida adapter records the selection.
- A new Ruida adapter starts from the machine's active WCS when it is
  a Ruida reference point, so a rebuilt driver no longer reverts the
  selection to MACHINE. The controller does not store it.
@medoix
medoix force-pushed the fix/ruida-current-wcs branch from 552b458 to 950c995 Compare October 26, 2026 03:17
@medoix
medoix marked this pull request as ready for review October 26, 2026 03:22
@knipknap
knipknap merged commit 8dbd7db into barebaric:main Oct 26, 2026
36 checks passed
@knipknap

Copy link
Copy Markdown
Contributor

Thanks for the fix and the clear description - looks good!

This branch was successfully deployed

1 active deployment
pypi — 950c995c Deployed Oct 26, 2026 by medoix via Build and Publish Wheel #2489
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