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 80bfbc368c9..23c6f7119c5 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -3495,6 +3495,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; @@ -3599,12 +3602,13 @@ int main(int argc, char *argv[]) check_ini_hal_items(emcStatus->motion.traj.joints); // read command - if (0 != emcCommandBuffer->read()) { - // got a new command, so clear out errors - taskPlanError = 0; - taskExecuteError = 0; - } - // run control cycle + if (0 != emcCommandBuffer->read()) { + // got a new command, so clear out errors + taskPlanError = 0; + taskExecuteError = 0; + taskCommandDone = 0; + } + // run control cycle if (0 != emcTaskPlan()) { taskPlanError = 1; } @@ -3753,26 +3757,32 @@ int main(int argc, char *argv[]) emcStatus->command_type = emcCommand->_type; emcStatus->echo_serial_number = emcCommand->serial_number; - if (taskPlanError || taskExecuteError || - emcStatus->task.execState == EMC_TASK_EXEC::ERROR || - emcStatus->motion.status == RCS_STATUS::ERROR || - emcStatus->io.status == RCS_STATUS::ERROR) { - emcStatus->status = RCS_STATUS::ERROR; - emcStatus->task.status = RCS_STATUS::ERROR; - } else if (!taskPlanError && !taskExecuteError && - emcStatus->task.execState == EMC_TASK_EXEC::DONE && - emcStatus->motion.status == RCS_STATUS::DONE && - emcStatus->io.status == RCS_STATUS::DONE && - mdi_execute_queue.len() == 0 && - interp_list.len() == 0 && - emcTaskCommand == NULL && - emcStatus->task.interpState == EMC_TASK_INTERP::IDLE) { - emcStatus->status = RCS_STATUS::DONE; - emcStatus->task.status = RCS_STATUS::DONE; - } else { - emcStatus->status = RCS_STATUS::EXEC; - emcStatus->task.status = RCS_STATUS::EXEC; - } + if (taskPlanError || taskExecuteError || + emcStatus->task.execState == EMC_TASK_EXEC::ERROR || + emcStatus->motion.status == RCS_STATUS::ERROR || + 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 && + emcStatus->io.status == RCS_STATUS::DONE && + mdi_execute_queue.len() == 0 && + interp_list.len() == 0 && + emcTaskCommand == NULL && + 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; + } // write it // since emcStatus was passed to the WM init functions, it 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 9cacfa31c58..db99295be39 100644 --- a/tests/stale-motion-status/README +++ b/tests/stale-motion-status/README @@ -23,4 +23,6 @@ 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. -After the program, slow-controller runs five G38.2 in MDI that end without contact. A little after each probe move ends, slowkins busy waits nearly all of each servo period for a while, so that status reads by task fail but the command echoes it waits for get through. Task keeps its copy from before its abort, still in error; it must not abort again on it, which on_abort.ngc counts, nor drop the move sent as soon as wait_complete() returns. +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. + +Then slow-controller runs five more G38.2 in MDI that end without contact. A little after each probe move ends, slowkins busy waits nearly all of each servo period for a while, so that status reads by task fail but the command echoes it waits for get through. Task keeps its copy from before its abort, still in error; it must not abort again on it, which on_abort.ngc counts, nor drop the move sent as soon as wait_complete() returns. diff --git a/tests/stale-motion-status/test-ui.py b/tests/stale-motion-status/test-ui.py index b50374ca1f3..47fe0b1c139 100755 --- a/tests/stale-motion-status/test-ui.py +++ b/tests/stale-motion-status/test-ui.py @@ -138,6 +138,24 @@ def aborts(): c.mode(linuxcnc.MODE_MDI) c.wait_complete(60) settle("MDI mode was on", lambda: s.task_mode == linuxcnc.MODE_MDI) + # The abort clears the motion error, so task shows RCS_ERROR for one + # cycle only. wait_complete() must still return it, and failed_serial + # must name the command. + 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)) + 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)) + before = aborts() hal.set_p("slowkins.burst-ns", "995000") hal.set_p("slowkins.burst-delay", "20")