From 28326ebd748f53c188eb62d36bc7b91f7d6cc7d2 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:43:03 +1100 Subject: [PATCH] task: MDI is not finished while motion has yet to act on the move mdi_execute_hook() set the interpreter idle once nothing was left to issue and the motion queue read empty. Motion acknowledges a move in its command handler, but the queue depth is published by the controller, which runs later. A status copy read in between, or kept after a failed read, still shows an empty queue, so task reported the MDI command finished one cycle after sending the move. A client waiting for interp_state to go idle then read the position mid-move; seen on CI in tests/interp/g28.2/invalid-pword. Use motion.status instead, which already reads EXEC until the controller has run after the last command. tests/stale-motion-status now sends MDI moves after the program and fails if the interpreter reads idle before a move is done. The late-controller variant fails on every move without the fix. --- src/emc/task/emctaskmain.cc | 4 +++- tests/stale-motion-status/README | 3 ++- tests/stale-motion-status/test-ui.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc index 89d1fbbb5a8..7b800c2afdd 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -739,7 +739,9 @@ static void mdi_execute_hook(void) emcTaskCommand == NULL && emcStatus->task.execState == EMC_TASK_EXEC::DONE && emcStatus->task.interpState != EMC_TASK_INTERP::IDLE && - emcStatus->motion.traj.queue == 0 && + // not traj.queue: a copy read before the controller ran after + // the move was sent still shows an empty queue + emcStatus->motion.status == RCS_STATUS::DONE && emcStatus->io.status == RCS_STATUS::DONE && !mdi_execute_wait && !mdi_execute_next) { diff --git a/tests/stale-motion-status/README b/tests/stale-motion-status/README index 993a1643a0d..f4a1b20fb04 100644 --- a/tests/stale-motion-status/README +++ b/tests/stale-motion-status/README @@ -11,7 +11,8 @@ probing" (#3650). Both tests check that the machine is on and in auto mode once wait_complete() returns, then probe at alternating heights and fail if -a probe reads the height of the one before. +a probe reads the height of the one before. Last they send MDI moves +and fail if the interpreter reads idle before a move is done. late-controller runs motion-controller before motion-command-handler, so a whole servo period passes between the two. The period is 50 ms, diff --git a/tests/stale-motion-status/test-ui.py b/tests/stale-motion-status/test-ui.py index edd6e09b2d2..2916b2e8cae 100755 --- a/tests/stale-motion-status/test-ui.py +++ b/tests/stale-motion-status/test-ui.py @@ -92,6 +92,24 @@ def error(err): sys.exit(1) time.sleep(0.05) +# An MDI move: the interpreter must not read idle before the move is done. +c.mode(linuxcnc.MODE_MDI) +c.wait_complete(60) +for x in (1, 0, 1, 0): + c.mdi("G0 X%d" % x) + start = time.time() + while True: + s.poll() + if s.interp_state == linuxcnc.INTERP_IDLE: + break + if time.time() - start > 60: + sys.stderr.write("timeout waiting for the MDI move to finish\n") + sys.exit(1) + time.sleep(0.001) + if abs(s.position[0] - x) > 1e-6: + failures.append("interpreter idle with G0 X%d at X%.4f" % (x, s.position[0])) + c.wait_complete(60) + err = e.poll() while err: error(err)