Skip to content

task: do not take a motion status from before a command as current (#3650) - #4666

Open
grandixximo wants to merge 5 commits into
LinuxCNC:masterfrom
grandixximo:probe-queue-test
Open

grandixximo wants to merge 5 commits into
LinuxCNC:masterfrom
grandixximo:probe-queue-test

Conversation

@grandixximo

@grandixximo grandixximo commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the root cause of #3650; #3971 stays as a backstop.

Motion echoes a command in motion-command-handler, but motion-controller acts on it later: it queues the move, enables the machine, switches mode, then publishes queue depth and state. Task can take a status from before the command as current in two ways:

  • a read between the two functions shows the command taken and motion idle;
  • a failed read (while the controller runs) leaves task with its copy from before the command.

Task then finishes the command too soon. After a G38 move the SYNCH completes at once, and the next line either fails with "Queue is not empty after probing" (what #3971 catches) or silently reads the previous probe's result when the stale window outlasts the synch. wait_complete() also returns before the machine is on or in auto mode.

Fix:

  • Motion records the heartbeat at which it echoes each command; task reports motion busy until the heartbeat has moved past it, i.e. the controller has run once after taking the command. motion-logger has no controller and counts each command as acted on.
  • When a status read fails and the copy predates the last command sent, task reports motion busy instead of done.

Tests:

  • probe-queue-not-empty: 100 G38.2 probes in AUTO with servo_delay, a test-only comp that busy waits between handler and controller. Fails on master before task: tighten AUTO read-ahead wait-clear to match MDI (#3650) #3971, 8 of 8.
  • stale-motion-status/late-controller: controller runs before the handler at a 50 ms period, so a whole period separates them.
  • stale-motion-status/slow-controller: kinematics that busy wait most of the 1 ms period, so task's status reads often fail.
  • Both stale-motion-status tests probe at alternating heights and fail if a probe reads the height of the one before, and check machine on and auto mode after each wait_complete().
late-controller slow-controller
master fails 3/3 fails 3/3
this PR passes 3/3 passes 3/3

Each change is needed: without the heartbeat check late-controller fails, without the guard slow-controller fails (2 of 3 runs).

The tests that compile a comp skip on package builds (SYSTEM_BUILD). runtests -u passes locally except ui-smoke/touchy-fit, which fails the same way on the base commit (#4656, fixed by #4658).

…NC#3650)

Runs 100 G38.2 probes in AUTO mode and fails on "Queue is not empty
after probing". A test-only comp busy waits between
motion-command-handler and motion-controller, so task often sees motion
idle right after the probe was queued. Fails without af6b5b7, passes
with it.
The test sent the home commands right after the machine-on command, all
three at once.  Wait until the machine is on, and home one joint at a
time, since a home command is refused while another joint homes.
@grandixximo grandixximo changed the title tests: add probe-queue-not-empty for the AUTO read-ahead race (#3650) task: do not take a motion status from before a command as current (#3650) Oct 12, 2026
Comment thread src/emc/motion/motion.h Outdated
Comment on lines +590 to +592
uint64_t commandHeartbeat; /* heartbeat when the command was echoed:
the controller has acted on the command
once heartbeat has moved past it */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't motion.h used in RTAPI code (RT)? That means you cannot use uint64_t and need to use rtapi_u64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good morning, you were missed on Sunday's meeting, hope I didn't mess things up too much ;-)
I will change this and heartbeat as well, so we compare with apples with apples.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good morning, you were missed on Sunday's meeting

Life happens once in a while... And, since nobody is paying me for the work, well, I do not have any obligation to attend 8-)

…command

Motion echoes a command in motion-command-handler, but motion-controller
acts on it: it queues the move, enables the machine, switches mode, and
then publishes the queue depth and state.  A status read between the two
shows the command taken and motion idle, so task takes motion as done.
After a G38 move the SYNCH then finishes at once and the next line reads
the result of the probe before, or fails with "Queue is not empty after
probing" (LinuxCNC#3650), and wait_complete() returns before the machine is on
or in auto mode.

Record the heartbeat at which each command is echoed, and report motion
busy until the heartbeat has moved past it, that is until the controller
has run once after taking the command.  motion-logger has no controller
and counts each command as acted on.

Both heartbeat fields are rtapi_u64, the RTAPI type for headers RT code
includes.
emcMotionUpdate() returns early when the status or config read fails,
which happens while motion-controller runs, and leaves the motion status
as it was.  Right after a command that copy predates it, and with a probe
just queued it says motion is done.  Report motion busy until a read that
has seen the command succeeds.
Probe at alternating heights, and check that the machine is on and in
auto mode once wait_complete() returns.  late-controller runs the
controller a 50 ms servo period after the command handler,
slow-controller uses kinematics that make the controller take most of
the servo period, so that status reads fail.  Both fail on master, and
each needs one of the two changes before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants