Skip to content

homing: joint.N.homing reports only that joint - #4955

Open
grandixximo wants to merge 3 commits into
LinuxCNC:masterfrom
grandixximo:homing-pin-truth
Open

grandixximo wants to merge 3 commits into
LinuxCNC:masterfrom
grandixximo:homing-pin-truth

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

Since #3800 a joint's homing pin and status stay TRUE until the whole homing run ends. In a Home All with several HOME_SEQUENCE groups, joint 0 still reads homing while the next group homes. That broke a config on the forum (https://forum.linuxcnc.org/24-hal-components/59433-joint-x-homing-signal-possible-bug) where one switch input feeds the home and limit pins of joints 0 and 2: the HAL masks the limits of the joints that are not homing, sees joint 0 as still homing, leaves its limit live, and the machine trips when joint 2 presses the shared switch.

The race #3800 fixed is real: after the last joint finished, motion kept homing_active set for two more servo cycles while the sequence machine walked to idle, and a home command sent in that window was refused. This PR removes the hold and fixes the window at its source instead: the sequence moves on in the cycle its last joint finishes, so homing_active drops together with that joint's homing flag. linuxcncrsh JOINT_WAIT_HOMED also waits for homing_active, so a wait on all joints cannot end between two groups.

tests/home-dist now runs a Home All of joint 0 then the synchronized pair and checks that joint 0 no longer reads homing while the pair homes; it fails on master.

Two questions:

  1. Is a motion.is-homing pin wanted? It would give HAL a signal for the whole homing run; the OR of the joint.N.homing pins drops for one servo cycle between HOME_SEQUENCE groups, as it did before homing: Fix race between joint's homing status and state machine done #3800.
  2. Should I add a test for the race itself? It needs that pin to see the window in HAL.

Since 1543217 a joint's homing pin and status stay TRUE until the whole homing run ends. In a Home All with several HOME_SEQUENCE groups, joint 0 still reads homing while the next group homes. A machine with one switch input for home and limits masks the limits of the joints that are not homing, so it leaves joint 0's limit live and trips when the next joint presses the shared switch (forum thread 59433).

The race that hold worked around comes from motion keeping homing_active set for two more servo cycles after the last joint finished, while the sequence machine walked to idle. A home command sent in that window was refused. Now the sequence moves on in the cycle its last joint finishes, so homing_active drops together with that joint's homing flag, and the hold is gone. linuxcncrsh JOINT_WAIT_HOMED also waits for homing_active, so a wait on all joints cannot end between two groups.

tests/home-dist now runs a Home All of joint 0 then the synchronized pair and checks that joint 0 no longer reads homing while the pair homes; it fails with the hold.
@BsAtHome

BsAtHome commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Interesting CI fail on pkg arch amd64 bookworm:
fail-t0-nonrandom.txt

@BsAtHome

BsAtHome commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Sorry, that fail was on ARM64, not x86

@BsAtHome

BsAtHome commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Is a motion.is-homing pin wanted? It would give HAL a signal for the whole homing run; the OR of the joint.N.homing pins drops for one servo cycle between HOME_SEQUENCE groups, as it did before homing: Fix race between joint's homing status and state machine done #3800.

If you are homing from one command, then any output pin to indicate that the homing process is active should be active for the entire procedure and not glitch between joints. Glitching causes races and false operational progressions.

The output pin itself, indicating that the (or a) homing process is currently in progress is probably useful. But, for example, complex homing group operations need to assure that this pin is active while the entire homing procedure is running.
If I am not mistaking, homing is always an operation started from higher up (via a command message). The homing procedure runs, simple as complex ones, as long as that command is being processed, which would mean that the pin is active during that period. Right?

Should I add a test for the race itself? It needs that pin to see the window in HAL.

Testing for the race is a race. A race is indeterministic by its definition. You cannot determine indeterminism...

@grandixximo

Copy link
Copy Markdown
Contributor Author

Interesting CI fail on pkg arch amd64 bookworm:

The rerun passed. I tracked it down: on an estop reset task syncs the parameter file to disk, which took 3.45 s on that runner, and linuxcncrsh gave up waiting for the heartbeat, so the machine never came on. #4957 makes linuxcncrsh wait for task to receive the command first.

If you are homing from one command, then any output pin to indicate that the homing process is active should be active for the entire procedure and not glitch between joints

Right, that is how motion.is-homing would behave: it follows homing_active, which is set from the home command until the last joint of the last group has finished, with no drop between groups. joint.N.homing stays per joint, on only while that joint homes; the one-cycle drop of an or2 over them between groups is how it was before #3800, and anyone who needs one signal for the whole run would use the new pin. Should I add it here?

Testing for the race is a race.

Not quite in this case: with the pin, a xor2 + flipflop in HAL compares motion.is-homing with joint.0.homing every servo cycle while one joint homes alone, so any cycle where they disagree latches. Without the settle step it caught it on every run I made. It needs the pin, so it would come with it.

@grandixximo

Copy link
Copy Markdown
Contributor Author

Rereading your comment: if no output pin should glitch during a homing run, that includes an or2 over the joint.N.homing pins. I can fold that in without holding any joint's pin: when a HOME_SEQUENCE group finishes, the next group's joints start in the same servo cycle, so one of them always reads homing until the last group is done. Each joint.N.homing still drops as soon as its own joint is homed. I had this locally; it costs a loop around the joint state machines in homing.c and the same in homecomp.comp, and the home-dist test then counts exactly one fall of the or2 over a Home All.

@BsAtHome

BsAtHome commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

If you are homing from one command, then any output pin to indicate that the homing process is active should be active for the entire procedure and not glitch between joints

Right, that is how motion.is-homing would behave: it follows homing_active, which is set from the home command until the last joint of the last group has finished, with no drop between groups. joint.N.homing stays per joint, on only while that joint homes; the one-cycle drop of an or2 over them between groups is how it was before #3800, and anyone who needs one signal for the whole run would use the new pin. Should I add it here?

Yes, I think that would be fine.

Testing for the race is a race.

Not quite in this case: with the pin, a xor2 + flipflop in HAL compares motion.is-homing with joint.0.homing every servo cycle while one joint homes alone, so any cycle where they disagree latches. Without the settle step it caught it on every run I made. It needs the pin, so it would come with it.

But if you can catch is consistently in the thread cycle, then it isn't a race but a glitch :-)
Glitches are deterministic (caused by logic), whereas races are indeterministic (concurrency problem).

But, when it is fixed, shouldn't we be able to trust it then? And, just doing it for one scenario may not cover the real problem when complex setups are being homed? You'd need a whole swath of different configurations to be somewhat sure and then, still, you know how users can be inventive to create that scenario you didn't test for. You know, the N scenarios you have but you should have tested N+1 scenarios ;-)

@BsAtHome

BsAtHome commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Rereading your comment: if no output pin should glitch during a homing run, that includes an or2 over the joint.N.homing pins. I can fold that in without holding any joint's pin: when a HOME_SEQUENCE group finishes, the next group's joints start in the same servo cycle, so one of them always reads homing until the last group is done. Each joint.N.homing still drops as soon as its own joint is homed. I had this locally; it costs a loop around the joint state machines in homing.c and the same in homecomp.comp, and the home-dist test then counts exactly one fall of the or2 over a Home All.

In a "Home All" scenario, the joint.N.homing pins indicate what is going on for each joint. But the whole process needs to be guarded against glitches. Just or'ing all joint.N.homing pins may be problematic. You really want to an uninterrupted indication from (factual) start until (really) done.

motion.is-homing is TRUE from the start of a homing command until its last joint has finished, without a break between HOME_SEQUENCE groups. It is the signal HAL needs for "the machine is homing": the joint.N.homing pins report each joint only, and an or2 over them drops for a servo cycle between groups. It shows the homing_active flag motion already keeps for task.
@grandixximo

Copy link
Copy Markdown
Contributor Author

Added motion.is-homing in a second commit. It is TRUE from the home command until the last joint of the last group is done, with no break between groups, so HAL that needs one signal for the whole run uses it instead of an or2 over the joint.N.homing pins. No glitch test, agreed.

Comment thread src/emc/usr_intf/emcrsh.cc Resolved
Comment thread src/emc/usr_intf/emcrsh.cc Resolved
JOINT_WAIT_HOMED ends by waiting one heartbeat for motion to switch to teleop. Wait two, so a whole servo cycle runs after the homed status was seen.
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