From 5c8f684dcb93081ec4304557fb6e71f4d68002dd Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Sat, 21 Nov 2026 14:06:08 +1100 Subject: [PATCH] docs: say when on_abort is called and with which reason The example on_abort sub labelled reason 5 "machine on", 6 "machine off" and 7 "estopped". Task sends 5 on E-stop reset, 6 on an E-stop request and 7 when the machine is no longer on. Say that OFF and E-stop requests call on_abort even when the machine is already off or in E-stop, that a machine which was on gets a second call with reason 7, and which reasons an error that stops a program or MDI gives. The example now has a branch per reason saying what it means, and a second example shows a sub that skips the state requests and still cleans up when the machine goes off. Fixes #4874 --- docs/src/remap/remap.adoc | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/src/remap/remap.adoc b/docs/src/remap/remap.adoc index a5b7db8d24a..c1b0c471f1a 100644 --- a/docs/src/remap/remap.adoc +++ b/docs/src/remap/remap.adoc @@ -962,6 +962,14 @@ EMC_ABORT_INTERPRETER_ERROR_MDI = 10, // interpreter failed during MDI execution EMC_ABORT_USER = 100 // user-defined abort codes start here ---- +An OFF request calls `on_abort` once with reason 4 and an E-stop request once with reason 6, even when the machine is already off or in E-stop. +An E-stop reset, from E-stop or from off, calls it once with reason 5. +So when a GUI sends OFF or E-stop as it starts, `on_abort` runs before any program does. +If the machine was on, a second call with reason 7 follows the first, because the machine is no longer on. +Reason 7 also comes alone when motion switches itself off, for example when the `motion.enable` pin goes false. +An error that stops a program or MDI calls `on_abort` with 1, 3, 9 or 10; a G38.2 that ends without contact, for example, gives 3. +If the error leaves the machine on, as a G38.2 without contact does, no call with reason 7 follows; if it turns the machine off, as a joint amplifier fault does, a call with reason 7 follows. + [source,{ini}] ---- [RS274NGC] @@ -984,15 +992,20 @@ M5 (spindle off) G80 (cancel modal motion) M9 (mist and coolant off) -o100 if [#1 eq 5] - (machine on) +o100 if [#1 eq 2] + (the HAL E-stop chain opened while the machine was on: a call with reason 7 follows) +o100 elseif [#1 eq 4] + (OFF requested: if the machine was on, a call with reason 7 follows) +o100 elseif [#1 eq 5] + (E-stop reset: the machine is still off) o100 elseif [#1 eq 6] - (machine off) + (E-stop requested: if the machine was on, a call with reason 7 follows) o100 elseif [#1 eq 7] - (estopped) + (what to run when the machine went off for any reason) o100 elseif [#1 eq 8] (msg, abort pressed) o100 else + (an error stopped a program or MDI: if it also turned the machine off, a call with reason 7 follows) (DEBUG, error parameter is [#1]) o100 endif @@ -1000,6 +1013,23 @@ o endsub m2 ---- +A procedure that only cleans up after a program or MDI was stopped can skip the state requests 4, 5 and 6. +If one of them stops a machine that was on, the call with reason 7 still comes: + +[source,{ngc}] +---- +o sub + +o100 if [[#1 ge 4] and [#1 le 6]] + o return +o100 endif + +G90 (absolute again, for example after a probing routine that used G91) + +o endsub +m2 +---- + CAUTION: Never use an `M2` in a O-word subroutine, including this one. It will cause hard-to-find errors. For instance, using an `M2` in a subroutine will not end the subroutine properly and will leave the subroutine NGC file open,