diff --git a/docs/src/config/ini-homing.adoc b/docs/src/config/ini-homing.adoc index 1ea4daaafa0..78b0a9a0193 100644 --- a/docs/src/config/ini-homing.adoc +++ b/docs/src/config/ini-homing.adoc @@ -189,10 +189,12 @@ When a joint of a synchronized sequence (negative HOME_SEQUENCE) runs out of thi (((HOME IGNORE LIMITS))) Can hold the values YES / NO. The default value for this parameter is NO. This flag determines whether LinuxCNC will ignore the limit switch input for this joint while homing. -This setting will not ignore limit inputs for other joints. If you do not have a separate home switch set this to YES and connect the limit switch signal to the joint home switch input in HAL. LinuxCNC will ignore the limit switch input for this joint while homing. -To use only one input for all homing and limits you will have to block the limit signals of the joints not homing in HAL and home one joint at a time. + +With HOME_IS_SHARED also set, the joint ignores its limit input while any joint homes, as long as the joint itself stands still. +This lets one input serve as home switch and limit switch for several joints: set both flags on each joint wired to it. +Set HOME apart from HOME_OFFSET so each joint leaves the switch after homing; the limit input is live again once homing ends. === HOME_USE_INDEX diff --git a/src/emc/motion/command.c b/src/emc/motion/command.c index c1a9812932b..e026776ca9f 100644 --- a/src/emc/motion/command.c +++ b/src/emc/motion/command.c @@ -790,6 +790,10 @@ void emcmotCommandHandler_locked(void *arg, long servo_period) if (joint == 0) { break; } + joint->home_shared_limits = + (emcmotCommand->flags & HOME_IGNORE_LIMITS) + && (emcmotCommand->flags & HOME_IS_SHARED) + && !(emcmotCommand->flags & HOME_ABSOLUTE_ENCODER); set_joint_homing_params(joint_num, emcmotCommand->offset, emcmotCommand->home, diff --git a/src/emc/motion/control.c b/src/emc/motion/control.c index 4d8585f2638..acb56571155 100644 --- a/src/emc/motion/control.c +++ b/src/emc/motion/control.c @@ -906,8 +906,15 @@ static void check_for_faults(void) /* check for hard limits */ if ((GET_JOINT_PHL_FLAG(joint) && ! pos_limit_override ) || (GET_JOINT_NHL_FLAG(joint) && ! neg_limit_override )) { - /* joint is on limit switch, should we trip? */ - if (get_homing(joint_num)) { + /* joint is on limit switch, should we trip? Not while it + homes, nor while another joint homes if its limit input is + a shared home switch and it stands still: then only that + switch can be pressed. */ + if (get_homing(joint_num) + || (joint->home_shared_limits + && get_homing_is_active() + && emcmotStatus->motion_state == EMCMOT_MOTION_FREE + && !joint->free_tp.active)) { /* no, ignore limits */ } else { /* trip on limits */ diff --git a/src/emc/motion/motion.h b/src/emc/motion/motion.h index 3e6b39e4712..2276bc116cd 100644 --- a/src/emc/motion/motion.h +++ b/src/emc/motion/motion.h @@ -471,6 +471,7 @@ Suggestion: Split this in to an Error and a Status flag register.. double max_ferror; /* max speed following error limit */ double backlash; /* amount of backlash */ emcmot_comp_t comp; /* leadscrew correction data */ + int home_shared_limits; /* limit input doubles as a shared home switch */ /* status info - changes regularly */ /* many of these need to be made available to higher levels */ diff --git a/tests/home-shared-limits/checkresult b/tests/home-shared-limits/checkresult new file mode 100755 index 00000000000..b421a17968b --- /dev/null +++ b/tests/home-shared-limits/checkresult @@ -0,0 +1,4 @@ +#!/bin/sh +# Success or failure of this test is handled in the test.sh script, if we +# get this far it's a success. +exit 0 diff --git a/tests/home-shared-limits/home-shared-limits.hal b/tests/home-shared-limits/home-shared-limits.hal new file mode 100644 index 00000000000..ae56a145c22 --- /dev/null +++ b/tests/home-shared-limits/home-shared-limits.hal @@ -0,0 +1,27 @@ +loadrt [KINS]KINEMATICS +loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS +loadrt comp names=cmp_x,cmp_z +loadrt or2 names=shared +addf motion-command-handler servo-thread +addf motion-controller servo-thread +addf cmp_x servo-thread +addf cmp_z servo-thread +addf shared servo-thread + +net j0 joint.0.motor-pos-cmd => joint.0.motor-pos-fb cmp_x.in0 +net j1 joint.1.motor-pos-cmd => joint.1.motor-pos-fb +net j2 joint.2.motor-pos-cmd => joint.2.motor-pos-fb cmp_z.in1 + +# X switch on below xswpos, Z switch on above zswpos (motor positions) +net xswpos => cmp_x.in1 +net zswpos => cmp_z.in0 +sets xswpos -151 +sets zswpos 81 + +# one input: home of X and Z, X min limit, Z max limit +net xsw cmp_x.out => shared.in0 +net zsw cmp_z.out => shared.in1 +net sw shared.out => joint.0.home-sw-in joint.2.home-sw-in +net sw => joint.0.neg-lim-sw-in joint.2.pos-lim-sw-in + +net estop-out iocontrol.0.user-enable-out => iocontrol.0.emc-enable-in diff --git a/tests/home-shared-limits/test-ui.py b/tests/home-shared-limits/test-ui.py new file mode 100755 index 00000000000..cee48838a67 --- /dev/null +++ b/tests/home-shared-limits/test-ui.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# Joints 0 and 2 share one input for home and limit switches. With +# HOME_IGNORE_LIMITS and HOME_IS_SHARED on both, homing one joint must +# not trip the other's limit; once homed the limits are live again. + +import linuxcnc +import hal + +import subprocess +import sys +import time + +failures = [] + + +def fail(msg): + print("FAIL " + msg) + failures.append(msg) + + +def wait_for(cond, timeout): + t0 = time.time() + while time.time() - t0 < timeout: + s.poll() + if cond(): + return True + time.sleep(0.01) + s.poll() + return cond() + + +def errors(): + out = [] + while True: + m = e.poll() + if not m: + return out + print("linuxcnc error: %s" % m[1]) + out.append(m[1]) + + +def sets(name, value): + subprocess.run(["halcmd", "sets", name, str(value)], check=True) + + +def home(joint, joints, label): + errors() + c.teleop_enable(0) + c.wait_complete() + c.home(joint) + c.wait_complete() + ok = wait_for(lambda: all(s.homed[j] for j in joints) + and not any(s.joint[j]["homing"] for j in joints) + or s.task_state != linuxcnc.STATE_ON, 30.0) + msgs = errors() + if not ok or s.task_state != linuxcnc.STATE_ON or msgs: + fail("%s: homed=%s on=%s" % (label, s.homed[:3], s.task_state == linuxcnc.STATE_ON)) + else: + print("%-24s homed" % label) + + +h = hal.component("test-ui") +h.ready() +c = linuxcnc.command() +s = linuxcnc.stat() +e = linuxcnc.error_channel() + +c.state(linuxcnc.STATE_ESTOP_RESET) +c.wait_complete() +c.state(linuxcnc.STATE_ON) +c.wait_complete() +c.mode(linuxcnc.MODE_MANUAL) +c.wait_complete() + +# Home all, joint 2 first then joint 0: each presses the switch while +# the other stands still. +home(-1, [0, 1, 2], "home all") + +# Homed: the limit is live again. +errors() +sets("xswpos", 1) +if not wait_for(lambda: s.task_state != linuxcnc.STATE_ON, 5.0): + fail("limit after homing: machine still on") +elif not any("limit switch error" in m for m in errors()): + fail("limit after homing: no limit switch error") +else: + print("%-24s tripped" % "limit after homing") + +if failures: + print("%d failure(s):" % len(failures)) + for msg in failures: + print(" " + msg) + sys.exit(1) +print("success") +sys.exit(0) diff --git a/tests/home-shared-limits/test.ini b/tests/home-shared-limits/test.ini new file mode 100644 index 00000000000..6ff4f118d25 --- /dev/null +++ b/tests/home-shared-limits/test.ini @@ -0,0 +1,83 @@ +[EMC] +VERSION = 1.1 +MACHINE = home-shared-limits +[DISPLAY] +DISPLAY = ./test-ui.py +[EMCMOT] +EMCMOT = motmod +COMM_TIMEOUT = 4.0 +SERVO_PERIOD = 1000000 +[TASK] +TASK = milltask +CYCLE_TIME = 0.010 +[HAL] +HALFILE = home-shared-limits.hal +[TRAJ] +COORDINATES = XYZ +LINEAR_UNITS = mm +ANGULAR_UNITS = degree +MAX_LINEAR_VELOCITY = 100.0 +[KINS] +KINEMATICS = trivkins +JOINTS = 3 +[AXIS_X] +MIN_LIMIT = -0.1 +MAX_LIMIT = 300 +MAX_VELOCITY = 100 +MAX_ACCELERATION = 500 +[AXIS_Y] +MIN_LIMIT = -300 +MAX_LIMIT = 300 +MAX_VELOCITY = 100 +MAX_ACCELERATION = 500 +[AXIS_Z] +MIN_LIMIT = -200 +MAX_LIMIT = 0.1 +MAX_VELOCITY = 100 +MAX_ACCELERATION = 500 +# One switch input: X home and min limit, Z home and max limit. +# X homes to the left: switch at -1 => HOME 0 +[JOINT_0] +TYPE = LINEAR +HOME = 0 +HOME_OFFSET = -1 +HOME_SEARCH_VEL = -20 +HOME_LATCH_VEL = 2 +HOME_SEQUENCE = 1 +HOME_IGNORE_LIMITS = YES +HOME_IS_SHARED = 1 +FERROR = 1 +MIN_FERROR = 1 +MAX_VELOCITY = 100 +MAX_ACCELERATION = 500 +MIN_LIMIT = -0.1 +MAX_LIMIT = 300 +[JOINT_1] +TYPE = LINEAR +HOME = 0 +HOME_OFFSET = 0 +HOME_SEARCH_VEL = 0 +HOME_LATCH_VEL = 0 +HOME_SEQUENCE = 0 +FERROR = 1 +MIN_FERROR = 1 +MAX_VELOCITY = 100 +MAX_ACCELERATION = 500 +MIN_LIMIT = -300 +MAX_LIMIT = 300 +# Z homes on top: switch at +1 => HOME 0 +[JOINT_2] +TYPE = LINEAR +HOME = 0 +HOME_OFFSET = 1 +HOME_SEARCH_VEL = 20 +HOME_LATCH_VEL = -2 +HOME_SEQUENCE = 0 +HOME_IGNORE_LIMITS = YES +HOME_IS_SHARED = 1 +FERROR = 1 +MIN_FERROR = 1 +MAX_VELOCITY = 100 +MAX_ACCELERATION = 500 +MIN_LIMIT = -200 +MAX_LIMIT = 0.1 diff --git a/tests/home-shared-limits/test.sh b/tests/home-shared-limits/test.sh new file mode 100755 index 00000000000..f5cfb134143 --- /dev/null +++ b/tests/home-shared-limits/test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +linuxcnc -r test.ini