diff --git a/docs/src/config/python-interface.adoc b/docs/src/config/python-interface.adoc index 7eb85883636..3439410a9a9 100644 --- a/docs/src/config/python-interface.adoc +++ b/docs/src/config/python-interface.adoc @@ -158,6 +158,9 @@ see <> for an example. EXEC_WAITING_FOR_DELAY, EXEC_WAITING_FOR_SYSTEM_CMD, EXEC_WAITING_FOR_SPINDLE_ORIENTED. +*failed_serial*:: '(returns integer)' - + serial number of the last command that failed, -1 if none. + *feed_hold_enabled*:: '(returns boolean)' - enable flag for feed hold. diff --git a/include/nml_intf/emc_nml.hh b/include/nml_intf/emc_nml.hh index f6b2c53c1b6..c786f1a9ed5 100644 --- a/include/nml_intf/emc_nml.hh +++ b/include/nml_intf/emc_nml.hh @@ -1569,6 +1569,7 @@ class EMC_TASK_STAT:public EMC_TASK_STAT_MSG { int task_paused; // non-zero means task is paused double delayLeft; // delay time left of G4, M66.. int queuedMDIcommands; // current length of MDI input queue + int failedSerial; // serial of the last command that ended in an error, -1 for none }; // declarations for EMC_TOOL classes diff --git a/lib/python/qtvcp/widgets/fake_status.py b/lib/python/qtvcp/widgets/fake_status.py index e0bd83e2dbe..a03d785328e 100644 --- a/lib/python/qtvcp/widgets/fake_status.py +++ b/lib/python/qtvcp/widgets/fake_status.py @@ -52,6 +52,7 @@ def __init__(self): self.enabled = False self.estop = 0 self.exec_state = 0 + self.failed_serial = -1 self.feed_hold_enabled = False self.feed_override_enabled = False self.feedrate = 0.0 diff --git a/src/emc/nml_intf/emc.cc b/src/emc/nml_intf/emc.cc index b779e153efa..cdd8b7f7743 100644 --- a/src/emc/nml_intf/emc.cc +++ b/src/emc/nml_intf/emc.cc @@ -1384,6 +1384,7 @@ void EMC_TASK_STAT::update(CMS * cms) cms->update(task_paused); cms->update(delayLeft); cms->update(queuedMDIcommands); + cms->update(failedSerial); } /* diff --git a/src/emc/nml_intf/emcops.cc b/src/emc/nml_intf/emcops.cc index a3cedd4afc1..f4a20821e50 100644 --- a/src/emc/nml_intf/emcops.cc +++ b/src/emc/nml_intf/emcops.cc @@ -162,7 +162,8 @@ EMC_TASK_STAT::EMC_TASK_STAT() interpreter_errcode(0), task_paused(0), delayLeft(0.0), - queuedMDIcommands(0) + queuedMDIcommands(0), + failedSerial(-1) { int t; diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc index d5cbcc5951f..c06204d9f6c 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -3486,6 +3486,9 @@ int main(int argc, char *argv[]) { int taskPlanError = 0; int taskExecuteError = 0; + // the current command has reported DONE (or there is none yet), so a + // later error is not its own + int taskCommandDone = 1; double startTime, endTime, deltaTime; double first_start_time; int num_latency_warnings = 0; @@ -3594,6 +3597,7 @@ int main(int argc, char *argv[]) // got a new command, so clear out errors taskPlanError = 0; taskExecuteError = 0; + taskCommandDone = 0; } // run control cycle if (0 != emcTaskPlan()) { @@ -3750,6 +3754,11 @@ int main(int argc, char *argv[]) emcStatus->io.status == RCS_STATUS::ERROR) { emcStatus->status = RCS_STATUS::ERROR; emcStatus->task.status = RCS_STATUS::ERROR; + // a motion or IO error shows here for one cycle only, as the abort + // above clears it; keep which command failed for a UI that polls later + if (!taskCommandDone) { + emcStatus->task.failedSerial = emcCommand->serial_number; + } } else if (!taskPlanError && !taskExecuteError && emcStatus->task.execState == EMC_TASK_EXEC::DONE && emcStatus->motion.status == RCS_STATUS::DONE && @@ -3760,6 +3769,7 @@ int main(int argc, char *argv[]) emcStatus->task.interpState == EMC_TASK_INTERP::IDLE) { emcStatus->status = RCS_STATUS::DONE; emcStatus->task.status = RCS_STATUS::DONE; + taskCommandDone = 1; } else { emcStatus->status = RCS_STATUS::EXEC; emcStatus->task.status = RCS_STATUS::EXEC; diff --git a/src/emc/usr_intf/axis/extensions/emcmodule.cc b/src/emc/usr_intf/axis/extensions/emcmodule.cc index 15b33eb6bf5..36651d0ef11 100644 --- a/src/emc/usr_intf/axis/extensions/emcmodule.cc +++ b/src/emc/usr_intf/axis/extensions/emcmodule.cc @@ -932,12 +932,14 @@ static RCS_STATUS emcWaitCommandComplete(pyCommandChannel *s, double timeout) { if(s->s->peek() == EMC_STAT_TYPE) { EMC_STAT *stat = (EMC_STAT*)s->s->get_address(); int serial_diff = stat->echo_serial_number - s->serial; + // the status shows a motion or IO error for one cycle only + bool failed = stat->task.failedSerial == s->serial; if (serial_diff > 0) { - return RCS_STATUS::DONE; + return failed ? RCS_STATUS::ERROR : RCS_STATUS::DONE; } if (serial_diff == 0 && ( stat->status == RCS_STATUS::DONE || stat->status == RCS_STATUS::ERROR )) { - return stat->status; + return failed ? RCS_STATUS::ERROR : stat->status; } } esleep(fmin(timeout - (now - start), EMC_COMMAND_DELAY)); @@ -1165,6 +1167,8 @@ static PyMemberDef Stat_members[] = { { "delay_left", T_DOUBLE, O(task.delayLeft), READONLY, NULL}, { "queued_mdi_commands", T_INT, O(task.queuedMDIcommands), READONLY, "Number of MDI commands queued waiting to run." }, + { "failed_serial", T_INT, O(task.failedSerial), READONLY, + "Serial number of the last command that ended in an error, -1 for none." }, // EMC_TRAJ_STAT traj { "linear_units", T_DOUBLE, O(motion.traj.linearUnits), READONLY, NULL}, diff --git a/src/emc/usr_intf/emcrsh.cc b/src/emc/usr_intf/emcrsh.cc index 409c267f0b5..003e2abc333 100644 --- a/src/emc/usr_intf/emcrsh.cc +++ b/src/emc/usr_intf/emcrsh.cc @@ -3690,7 +3690,9 @@ static int sockMain(int svrfd) if (!setterDoneUpdate(*i)) continue; // This client is still waiting // Done, now we know what to reply - if (emcStatus->status == RCS_STATUS::ERROR) { + // the status shows a motion or IO error for one cycle only + if (emcStatus->status == RCS_STATUS::ERROR || + emcStatus->task.failedSerial == i->serial) { replynl(*i, fmt::format("SET {} NAK", activeSetter)); } else if (i->verbose) { replynl(*i, fmt::format("SET {} ACK", activeSetter)); diff --git a/src/emc/usr_intf/halui.cc b/src/emc/usr_intf/halui.cc index 48170250ec5..e2f7cd3fbc5 100644 --- a/src/emc/usr_intf/halui.cc +++ b/src/emc/usr_intf/halui.cc @@ -405,16 +405,19 @@ static int emcCommandWaitDone() updateStatus(); int serial_diff = emcStatus->echo_serial_number - emcCommandSerialNumber; + // the status shows a motion or IO error for one cycle only + bool failed = emcStatus->task.failedSerial == emcCommandSerialNumber; + if (serial_diff < 0) { continue; } if (serial_diff > 0) { - return 0; + return failed ? -1 : 0; } if (emcStatus->status == RCS_STATUS::DONE) { - return 0; + return failed ? -1 : 0; } if (emcStatus->status == RCS_STATUS::ERROR) { diff --git a/src/emc/usr_intf/shcom.cc b/src/emc/usr_intf/shcom.cc index 7dab61010a7..a81eb2787fa 100644 --- a/src/emc/usr_intf/shcom.cc +++ b/src/emc/usr_intf/shcom.cc @@ -272,8 +272,11 @@ int emcCommandWaitDone() updateStatus(); int serial_diff = emcStatus->echo_serial_number - emcCommandSerialNumber; + // the status shows a motion or IO error for one cycle only + bool failed = emcStatus->task.failedSerial == emcCommandSerialNumber; + if (serial_diff > 0) { // We've past beyond our command - return 0; + return failed ? -1 : 0; } if (!serial_diff) { // We're at our command @@ -282,7 +285,7 @@ int emcCommandWaitDone() break; case RCS_STATUS::DONE: - return 0; + return failed ? -1 : 0; case RCS_STATUS::ERROR: // The command failed return -1; diff --git a/tests/linuxcncrsh/expected-telnet-output b/tests/linuxcncrsh/expected-telnet-output index 935b42dc147..d6ee282dd03 100644 --- a/tests/linuxcncrsh/expected-telnet-output +++ b/tests/linuxcncrsh/expected-telnet-output @@ -67,7 +67,7 @@ ERROR Cannot probe with zero feed rate SET MDI ACK SET PROBE NAK ERROR Start point too close to probe point -SET PROBE ACK +SET PROBE NAK ERROR G38.2 move finished without making contact. PROBE_TRIPPED NO SET PROBE_CLEAR ACK @@ -135,7 +135,7 @@ MODE MANUAL SET MODE ACK MODE MDI ERROR OK -SET PROBE ACK +SET PROBE NAK ERROR G38.2 move finished without making contact. PROBE_TRIPPED NO SET PROBE_CLEAR ACK @@ -152,7 +152,7 @@ MODE MANUAL SET MODE ACK MODE MDI ERROR OK -SET PROBE ACK +SET PROBE NAK ERROR G38.2 move finished without making contact. PROBE_TRIPPED NO SET PROBE_CLEAR ACK diff --git a/tests/stale-motion-status/README b/tests/stale-motion-status/README index 993a1643a0d..6d8ed78b377 100644 --- a/tests/stale-motion-status/README +++ b/tests/stale-motion-status/README @@ -21,3 +21,5 @@ slow-controller uses kinematics that busy wait, so motion-controller takes most of the servo period and status reads by task often fail while it runs. The wait starts once task is up: its startup reads the status only once a second and gives up after ten tries. + +In slow-controller, after the program, three G38.2 in MDI end without contact. The abort clears the motion error, so task reports RCS_ERROR for one cycle only; wait_complete() must still return RCS_ERROR, and stat.failed_serial must name the probe. diff --git a/tests/stale-motion-status/test-ui.py b/tests/stale-motion-status/test-ui.py index edd6e09b2d2..5b6f66ff430 100755 --- a/tests/stale-motion-status/test-ui.py +++ b/tests/stale-motion-status/test-ui.py @@ -97,6 +97,38 @@ def error(err): error(err) err = e.poll() +# A probe that ends without contact fails in motion, and the abort clears +# the error: task shows RCS_ERROR for one cycle only. wait_complete() must +# still return it, and failed_serial must name the command. +# late-controller is left out: its 50 ms servo period makes each probe slow. +if hal.component_exists("slowkins"): + c.mode(linuxcnc.MODE_MDI) + c.wait_complete(60) + settle("MDI mode was on", lambda: s.task_mode == linuxcnc.MODE_MDI) + for n in range(3): + c.mdi("G38.2 Z-0.01 F6") + probe = c.serial + if c.wait_complete(60) != linuxcnc.RCS_ERROR: + failures.append("wait_complete() did not report probe %d without contact as failed" % n) + s.poll() + if s.failed_serial != probe: + failures.append("failed_serial %d after probe %d, want %d" % (s.failed_serial, n, probe)) + # wait_complete() can return while task still shows the error; a + # command sent then is aborted with the probe + start = time.time() + while s.state != linuxcnc.RCS_DONE: + if time.time() - start > 60: + sys.stderr.write("timeout waiting for task to settle after probe %d\n" % n) + sys.exit(1) + time.sleep(0.05) + s.poll() + c.mdi("G0 Z0") + if c.wait_complete(60) != linuxcnc.RCS_DONE: + failures.append("wait_complete() did not report the move after probe %d as done" % n) + s.poll() + if s.failed_serial != probe: + failures.append("the move after probe %d changed failed_serial to %d" % (n, s.failed_serial)) + for msg in failures + errors: sys.stderr.write("error: %s\n" % msg) if h["finished"] != 1: