Skip to content

Commit 1f5771b

Browse files
authored
Merge pull request #4956 from grandixximo/home-shared-limits
motion: a shared home/limit input does not trip a joint that stands still
2 parents 718336d + c12257e commit 1f5771b

9 files changed

Lines changed: 229 additions & 4 deletions

File tree

‎docs/src/config/ini-homing.adoc‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ When a joint of a synchronized sequence (negative HOME_SEQUENCE) runs out of thi
189189
(((HOME IGNORE LIMITS)))
190190
Can hold the values YES / NO. The default value for this parameter is NO.
191191
This flag determines whether LinuxCNC will ignore the limit switch input for this joint while homing.
192-
This setting will not ignore limit inputs for other joints.
193192
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.
194193
LinuxCNC will ignore the limit switch input for this joint while homing.
195-
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.
194+
195+
With HOME_IS_SHARED also set, the joint ignores its limit input while any joint homes, as long as the joint itself stands still.
196+
This lets one input serve as home switch and limit switch for several joints: set both flags on each joint wired to it.
197+
Set HOME apart from HOME_OFFSET so each joint leaves the switch after homing; the limit input is live again once homing ends.
196198

197199
=== HOME_USE_INDEX
198200

‎src/emc/motion/command.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,10 @@ void emcmotCommandHandler_locked(void *arg, long servo_period)
790790
if (joint == 0) {
791791
break;
792792
}
793+
joint->home_shared_limits =
794+
(emcmotCommand->flags & HOME_IGNORE_LIMITS)
795+
&& (emcmotCommand->flags & HOME_IS_SHARED)
796+
&& !(emcmotCommand->flags & HOME_ABSOLUTE_ENCODER);
793797
set_joint_homing_params(joint_num,
794798
emcmotCommand->offset,
795799
emcmotCommand->home,

‎src/emc/motion/control.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,15 @@ static void check_for_faults(void)
906906
/* check for hard limits */
907907
if ((GET_JOINT_PHL_FLAG(joint) && ! pos_limit_override ) ||
908908
(GET_JOINT_NHL_FLAG(joint) && ! neg_limit_override )) {
909-
/* joint is on limit switch, should we trip? */
910-
if (get_homing(joint_num)) {
909+
/* joint is on limit switch, should we trip? Not while it
910+
homes, nor while another joint homes if its limit input is
911+
a shared home switch and it stands still: then only that
912+
switch can be pressed. */
913+
if (get_homing(joint_num)
914+
|| (joint->home_shared_limits
915+
&& get_homing_is_active()
916+
&& emcmotStatus->motion_state == EMCMOT_MOTION_FREE
917+
&& !joint->free_tp.active)) {
911918
/* no, ignore limits */
912919
} else {
913920
/* trip on limits */

‎src/emc/motion/motion.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ Suggestion: Split this in to an Error and a Status flag register..
471471
double max_ferror; /* max speed following error limit */
472472
double backlash; /* amount of backlash */
473473
emcmot_comp_t comp; /* leadscrew correction data */
474+
int home_shared_limits; /* limit input doubles as a shared home switch */
474475

475476
/* status info - changes regularly */
476477
/* many of these need to be made available to higher levels */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# Success or failure of this test is handled in the test.sh script, if we
3+
# get this far it's a success.
4+
exit 0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
loadrt [KINS]KINEMATICS
2+
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
3+
loadrt comp names=cmp_x,cmp_z
4+
loadrt or2 names=shared
5+
addf motion-command-handler servo-thread
6+
addf motion-controller servo-thread
7+
addf cmp_x servo-thread
8+
addf cmp_z servo-thread
9+
addf shared servo-thread
10+
11+
net j0 joint.0.motor-pos-cmd => joint.0.motor-pos-fb cmp_x.in0
12+
net j1 joint.1.motor-pos-cmd => joint.1.motor-pos-fb
13+
net j2 joint.2.motor-pos-cmd => joint.2.motor-pos-fb cmp_z.in1
14+
15+
# X switch on below xswpos, Z switch on above zswpos (motor positions)
16+
net xswpos => cmp_x.in1
17+
net zswpos => cmp_z.in0
18+
sets xswpos -151
19+
sets zswpos 81
20+
21+
# one input: home of X and Z, X min limit, Z max limit
22+
net xsw cmp_x.out => shared.in0
23+
net zsw cmp_z.out => shared.in1
24+
net sw shared.out => joint.0.home-sw-in joint.2.home-sw-in
25+
net sw => joint.0.neg-lim-sw-in joint.2.pos-lim-sw-in
26+
27+
net estop-out iocontrol.0.user-enable-out => iocontrol.0.emc-enable-in
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env python3
2+
# Joints 0 and 2 share one input for home and limit switches. With
3+
# HOME_IGNORE_LIMITS and HOME_IS_SHARED on both, homing one joint must
4+
# not trip the other's limit; once homed the limits are live again.
5+
6+
import linuxcnc
7+
import hal
8+
9+
import subprocess
10+
import sys
11+
import time
12+
13+
failures = []
14+
15+
16+
def fail(msg):
17+
print("FAIL " + msg)
18+
failures.append(msg)
19+
20+
21+
def wait_for(cond, timeout):
22+
t0 = time.time()
23+
while time.time() - t0 < timeout:
24+
s.poll()
25+
if cond():
26+
return True
27+
time.sleep(0.01)
28+
s.poll()
29+
return cond()
30+
31+
32+
def errors():
33+
out = []
34+
while True:
35+
m = e.poll()
36+
if not m:
37+
return out
38+
print("linuxcnc error: %s" % m[1])
39+
out.append(m[1])
40+
41+
42+
def sets(name, value):
43+
subprocess.run(["halcmd", "sets", name, str(value)], check=True)
44+
45+
46+
def home(joint, joints, label):
47+
errors()
48+
c.teleop_enable(0)
49+
c.wait_complete()
50+
c.home(joint)
51+
c.wait_complete()
52+
ok = wait_for(lambda: all(s.homed[j] for j in joints)
53+
and not any(s.joint[j]["homing"] for j in joints)
54+
or s.task_state != linuxcnc.STATE_ON, 30.0)
55+
msgs = errors()
56+
if not ok or s.task_state != linuxcnc.STATE_ON or msgs:
57+
fail("%s: homed=%s on=%s" % (label, s.homed[:3], s.task_state == linuxcnc.STATE_ON))
58+
else:
59+
print("%-24s homed" % label)
60+
61+
62+
h = hal.component("test-ui")
63+
h.ready()
64+
c = linuxcnc.command()
65+
s = linuxcnc.stat()
66+
e = linuxcnc.error_channel()
67+
68+
c.state(linuxcnc.STATE_ESTOP_RESET)
69+
c.wait_complete()
70+
c.state(linuxcnc.STATE_ON)
71+
c.wait_complete()
72+
c.mode(linuxcnc.MODE_MANUAL)
73+
c.wait_complete()
74+
75+
# Home all, joint 2 first then joint 0: each presses the switch while
76+
# the other stands still.
77+
home(-1, [0, 1, 2], "home all")
78+
79+
# Homed: the limit is live again.
80+
errors()
81+
sets("xswpos", 1)
82+
if not wait_for(lambda: s.task_state != linuxcnc.STATE_ON, 5.0):
83+
fail("limit after homing: machine still on")
84+
elif not any("limit switch error" in m for m in errors()):
85+
fail("limit after homing: no limit switch error")
86+
else:
87+
print("%-24s tripped" % "limit after homing")
88+
89+
if failures:
90+
print("%d failure(s):" % len(failures))
91+
for msg in failures:
92+
print(" " + msg)
93+
sys.exit(1)
94+
print("success")
95+
sys.exit(0)

‎tests/home-shared-limits/test.ini‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[EMC]
2+
VERSION = 1.1
3+
MACHINE = home-shared-limits
4+
[DISPLAY]
5+
DISPLAY = ./test-ui.py
6+
[EMCMOT]
7+
EMCMOT = motmod
8+
COMM_TIMEOUT = 4.0
9+
SERVO_PERIOD = 1000000
10+
[TASK]
11+
TASK = milltask
12+
CYCLE_TIME = 0.010
13+
[HAL]
14+
HALFILE = home-shared-limits.hal
15+
[TRAJ]
16+
COORDINATES = XYZ
17+
LINEAR_UNITS = mm
18+
ANGULAR_UNITS = degree
19+
MAX_LINEAR_VELOCITY = 100.0
20+
[KINS]
21+
KINEMATICS = trivkins
22+
JOINTS = 3
23+
[AXIS_X]
24+
MIN_LIMIT = -0.1
25+
MAX_LIMIT = 300
26+
MAX_VELOCITY = 100
27+
MAX_ACCELERATION = 500
28+
[AXIS_Y]
29+
MIN_LIMIT = -300
30+
MAX_LIMIT = 300
31+
MAX_VELOCITY = 100
32+
MAX_ACCELERATION = 500
33+
[AXIS_Z]
34+
MIN_LIMIT = -200
35+
MAX_LIMIT = 0.1
36+
MAX_VELOCITY = 100
37+
MAX_ACCELERATION = 500
38+
# One switch input: X home and min limit, Z home and max limit.
39+
# X homes to the left: switch at -1 => HOME 0
40+
[JOINT_0]
41+
TYPE = LINEAR
42+
HOME = 0
43+
HOME_OFFSET = -1
44+
HOME_SEARCH_VEL = -20
45+
HOME_LATCH_VEL = 2
46+
HOME_SEQUENCE = 1
47+
HOME_IGNORE_LIMITS = YES
48+
HOME_IS_SHARED = 1
49+
FERROR = 1
50+
MIN_FERROR = 1
51+
MAX_VELOCITY = 100
52+
MAX_ACCELERATION = 500
53+
MIN_LIMIT = -0.1
54+
MAX_LIMIT = 300
55+
[JOINT_1]
56+
TYPE = LINEAR
57+
HOME = 0
58+
HOME_OFFSET = 0
59+
HOME_SEARCH_VEL = 0
60+
HOME_LATCH_VEL = 0
61+
HOME_SEQUENCE = 0
62+
FERROR = 1
63+
MIN_FERROR = 1
64+
MAX_VELOCITY = 100
65+
MAX_ACCELERATION = 500
66+
MIN_LIMIT = -300
67+
MAX_LIMIT = 300
68+
# Z homes on top: switch at +1 => HOME 0
69+
[JOINT_2]
70+
TYPE = LINEAR
71+
HOME = 0
72+
HOME_OFFSET = 1
73+
HOME_SEARCH_VEL = 20
74+
HOME_LATCH_VEL = -2
75+
HOME_SEQUENCE = 0
76+
HOME_IGNORE_LIMITS = YES
77+
HOME_IS_SHARED = 1
78+
FERROR = 1
79+
MIN_FERROR = 1
80+
MAX_VELOCITY = 100
81+
MAX_ACCELERATION = 500
82+
MIN_LIMIT = -200
83+
MAX_LIMIT = 0.1

‎tests/home-shared-limits/test.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
linuxcnc -r test.ini

0 commit comments

Comments
 (0)