From 0f353025a4c17dd2411bd35337e149a5d97cd0c0 Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:34:30 +1100 Subject: [PATCH] homing: an abort unhomes only the joints that had not finished homing Since e0c3b39cb6 (#3481) a homing abort stops every joint, which is right, but it also clears homed on every joint. Home X, then Y, then start Z and press Esc: X and Y lose their homed state too, although nothing moved them. The same happens inside a Home All: Z and Y have homed, X is far away, the operator stops, jogs X closer, and then has to home everything again instead of only X. The abort now still stops every joint but clears homed only on the joints that were homing. Joints waiting for a later sequence group were already unhomed when the command started; joints that finished keep their homed state. tests/home-dist homes joint 0 and fails the synchronized pair, once with a home of the pair alone and once with a Home All, and checks that joint 0 stays homed both times. --- src/emc/motion/homing.c | 6 +++++- tests/home-dist/test-ui.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/emc/motion/homing.c b/src/emc/motion/homing.c index a807b63a385..0f179f355e3 100644 --- a/src/emc/motion/homing.c +++ b/src/emc/motion/homing.c @@ -1603,9 +1603,13 @@ static int base_1joint_state_machine(int joint_num) break; case HOME_ABORT: + /* stop every joint; joints that finished homing stay homed, + the others were unhomed when the command started */ for(int i = 0; i < all_joints; i++) { + if (H[i].homing) { + H[i].homed = 0; + } H[i].homing = 0; - H[i].homed = 0; H[i].joint_in_sequence = 0; joints[i].free_tp.enable = 0; H[i].home_state = HOME_IDLE; diff --git a/tests/home-dist/test-ui.py b/tests/home-dist/test-ui.py index 977f66fb5bd..5796423ef1c 100755 --- a/tests/home-dist/test-ui.py +++ b/tests/home-dist/test-ui.py @@ -55,9 +55,10 @@ def pos(j): return hal.get_value("joint.%d.motor-pos-cmd" % j) -def home(joint, label, expect): +def home(joint, label, expect, keep=()): # Home 'joint', wait for the homing to end, check that the expected - # message came and that the machine is still on and unhomed. + # message came, that the machine is still on, and that only the + # joints in 'keep' are homed. start = [pos(j) for j in range(3)] errors() c.teleop_enable(0) @@ -95,8 +96,9 @@ def home(joint, label, expect): sys.stdout.flush() if not any(expect in m for m in msgs): fail("%s: no error containing '%s'" % (label, expect)) - if any(s.homed[:3]): - fail("%s: a joint reports homed" % label) + for j in range(3): + if s.homed[j] != (j in keep): + fail("%s: joint %d homed=%d" % (label, j, s.homed[j])) if s.task_state != linuxcnc.STATE_ON: fail("%s: machine is no longer on" % label) return start, farthest, end @@ -172,6 +174,26 @@ def check_moved(label, j, start, farthest, dist): else: print("%-28s homed" % "working switch") +# A failed home of the pair stops it but leaves joint 0 homed: an abort +# unhomes only the joints that had not finished homing. +start, farthest, end = home(1, "pair fails, joint 0 homed", "did not clear", keep=(0,)) + +# Same in a Home All: joint 0 homes first and stays homed when the pair +# fails after it. +c.teleop_enable(0) +c.wait_complete() +c.home(-1) +c.wait_complete() +if not wait_for(lambda: any(j["homing"] for j in s.joint[1:3]), 20.0): + fail("home all: the pair did not start homing") +if not wait_for(lambda: not any(j["homing"] for j in s.joint[:3]), 20.0): + fail("home all: homing did not end") +elif not s.homed[0] or s.homed[1] or s.homed[2]: + fail("home all, pair fails: homed=%d,%d,%d, expected 1,0,0" % tuple(s.homed[:3])) +else: + print("%-28s joint 0 still homed" % "home all, pair fails") +errors() + c.state(linuxcnc.STATE_ESTOP) c.wait_complete()