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 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 @@ -1382,6 +1382,7 @@ void EMC_TASK_STAT::update(CMS * cms)
cms->update(task_paused);
cms->update(delayLeft);
cms->update(queuedMDIcommands);
cms->update(failedSerial);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/emc/nml_intf/emc_nml.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,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
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
10 changes: 10 additions & 0 deletions src/emc/task/emctaskmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,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 @@ -3595,6 +3598,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()) {
Expand Down Expand Up @@ -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 &&
Expand All @@ -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;
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 @@ -930,12 +930,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 @@ -1162,6 +1164,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 @@ -406,16 +406,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 @@ -271,8 +271,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 @@ -281,7 +284,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
2 changes: 2 additions & 0 deletions tests/stale-motion-status/README
Original file line number Diff line number Diff line change
Expand Up @@ -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.
32 changes: 32 additions & 0 deletions tests/stale-motion-status/test-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading