Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/src/config/python-interface.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ see <<python:reading-ini-values,ReadingINI file values>> 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.

Expand Down
1 change: 1 addition & 0 deletions include/nml_intf/emc_nml.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/python/qtvcp/widgets/fake_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/emc/nml_intf/emc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ void EMC_TASK_STAT::update(CMS * cms)
cms->update(task_paused);
cms->update(delayLeft);
cms->update(queuedMDIcommands);
cms->update(failedSerial);
}

/*
Expand Down
3 changes: 2 additions & 1 deletion src/emc/nml_intf/emcops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
62 changes: 36 additions & 26 deletions src/emc/task/emctaskmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/emc/usr_intf/axis/extensions/emcmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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},
Expand Down
4 changes: 3 additions & 1 deletion src/emc/usr_intf/emcrsh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 5 additions & 2 deletions src/emc/usr_intf/halui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/emc/usr_intf/shcom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/linuxcncrsh/expected-telnet-output
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/stale-motion-status/README
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 18 additions & 0 deletions tests/stale-motion-status/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down