Skip to content

docs: add Modbus safety considerations for spindle and drive control - #4531

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:modbus-safety-docs
Open

grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:modbus-safety-docs

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

Prompted by #4529: a VFD driven over Modbus holds the last written control word indefinitely, so a LinuxCNC exit, crash or dropped serial link leaves the spindle running and no stop command is ever sent. This was not documented anywhere, and shutdown.hal stop writes only cover the clean-exit case.

This adds a Safety Considerations section to the mb2hal driver doc describing the standard layered practice:

  1. Hardwired enable/STO in the machine estop chain, the only layer that qualifies as safety
  2. VFD communication-loss watchdog (Modbus timeout => fault/coast), which covers crashes and link drops
  3. Splitting VFD command sources: run from a hardwired terminal driven by motion.spindle-on / motion.machine-is-on, Modbus carrying only speed, direction and status. This also avoids read-modify-write on VFDs that multiplex run/stop into one control register

The hm2_modbus man page SEE ALSO points to the new section, since the same considerations apply to every Modbus control path (mb2hal, hm2_modbus, ClassicLadder, custom drivers).

Intentionally does not touch mesa_modbus.adoc to stay conflict-free with #4530, which removes that page.

@rodw-au

rodw-au commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

I've been reviewing this. The concensus is that 1 & 2 is mandatory but 3 is optional. There is nothing wrong or unsafe about using fieldbus for spindle on/off provided the other safety methods are implemented. My VFD has 2 options for estop. A single input and a dual redundant estop1, estop2 for use with safety relays.
LinuxCNC does do the right thing on startup as it turns a running spindle off.

A Modbus slave such as a VFD holds the last written control word indefinitely, so a LinuxCNC exit, crash or dropped serial link leaves the spindle running with no stop command ever sent (issue LinuxCNC#4529). This was not documented anywhere.

Add a Safety Considerations section to the mb2hal driver doc covering the standard layered practice: hardwired enable/STO in the estop chain as the only true safety layer, stopping on communication loss either via the VFD Modbus timeout or via HAL-side detection on the mb2hal num_errors pin (no VFD-specific parameterization, survives VFD replacement), and optionally splitting VFD command sources so run comes from a hardwired terminal driven by motion.spindle-on or motion.machine-is-on while Modbus carries only speed, direction and status. Note that shutdown.hal stop writes cover only the clean-exit case, and that run/stop over Modbus is accepted practice once the hardwired layer is in place.

Point to the new section from the hm2_modbus man page SEE ALSO, since the same considerations apply to every Modbus control path. Also fix the num_errors pin direction in the mb2hal man page (it is HAL_OUT in the source).
@grandixximo

Copy link
Copy Markdown
Contributor Author

Fair point, with a hardwired enable/STO layer in place, run and stop over fieldbus is accepted practice. I reworded the section so it no longer reads as all three items being mandatory:

  • Item 1 stays the safety layer and now mentions dual redundant estop inputs for use with safety relays, and notes that run/stop over Modbus is fine once this layer exists.
  • Item 2 is now "arrange a stop on communication loss" with two implementations: the VFD Modbus timeout parameter, or HAL-side detection. mb2hal has a num_errors pin per transaction (0 means the last transaction succeeded), and feeding it into a machine-off or estop chain stops LinuxCNC when the error count climbs. The HAL-side variant avoids digging through VFD parameterization and needs no rework when the VFD is replaced; the noted tradeoff is that PC-crash coverage then rests on the output hardware watchdog (Mesa watchdog, charge pump).
  • Item 3 is explicitly optional now, keeping the note that it avoids read-modify-write when one control register multiplexes run, stop and other commands.

Also fixed the num_errors pin direction in the mb2hal man page while here: it is documented as "u32 in" but has been HAL_OUT in the source since the pin was introduced in 2012.

@rodw-au

rodw-au commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Thanks, I think its pretty good now. Thanks for doing that. I will review again when build a new control panel in a couple of weeks. Counting the errors is a robust idea. The Comp component could do that easily.

I know its only documentation but it is important to cover it due to safety concerns. I don't think I've ever seen this discussed on any modbus forum post.

@grandixximo

Copy link
Copy Markdown
Contributor Author

It was undocumented tribal knowledge, now written down 😉

@rodw-au

rodw-au commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

It was undocumented tribal knowledge, now written down 😉

It is now real knowledge! :)

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