Skip to content

Commit 2cdad46

Browse files
Made tests/motion/g0 more robust and got rid of race condition
Adjusted test.sh to make sure halsampler run until all instructions are sent via port 5007 to linuxcncrsh. Now wait for explicite process IDs of halsampler and linuxcnc to make sure neither terminated before test is over. Added more checks in checkresults, and made sure it give more sensible error messages if no acceleration is detected (instead of raising out of bound exceptions. Replaced random sleep periods with code to wait for pins to signal startup, homing and move is completed.
1 parent 55b163c commit 2cdad46

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

tests/motion/g0/checkresult

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,13 @@ print("line 0: X starts at 0.000000")
8686

8787

8888
# find where X starts moving (X is the second column, column 1)
89-
i = 0
90-
while samples[i][1] == samples[i+1][1]:
91-
i += 1
89+
for i in range(0, len(samples) - 1):
90+
if samples[i][1] != samples[i+1][1]:
91+
break
92+
93+
if len(samples) == i+2:
94+
print("error: no acceleration detected, did linuxcnc take too long to start moving?")
95+
sys.exit(1)
9296

9397
print("line %d: accel phase starts" % i)
9498

@@ -100,7 +104,7 @@ print("line %d: accel phase starts" % i)
100104
highest_seen_accel_ipc2 = 0
101105
old_accel_ipc2 = 0
102106
old_v_ipc = 0
103-
for i in range(i, len(samples)):
107+
for i in range(i, len(samples) - 1):
104108

105109
new_v_ipc = samples[i+1][1] - samples[i][1]
106110
accel_ipc2 = new_v_ipc - old_v_ipc
@@ -141,7 +145,7 @@ print("line %d: entering cruise phase, vel=%.6f i/s, max_accel = %.6f i/s^2" % (
141145

142146
# now i is the first sample of the cruise phase
143147
# wait for vel to drop again
144-
for i in range(i, len(samples)):
148+
for i in range(i, len(samples) - 1):
145149
new_v_ipc = samples[i+1][1] - samples[i][1]
146150

147151
if abs(new_v_ipc - old_v_ipc) > 0.0000001:
@@ -158,7 +162,7 @@ print("line %d: decel phase starting, old_v=%.6f i/s, new_v=%.6f i/s" % (i, old_
158162
# verify decel phase stops when vel == 0
159163
highest_seen_accel_ipc2 = 0
160164
old_accel_ipc2 = 0
161-
for i in range(i, len(samples)):
165+
for i in range(i, len(samples) - 1):
162166

163167
new_v_ipc = samples[i+1][1] - samples[i][1]
164168
accel_ipc2 = new_v_ipc - old_v_ipc

tests/motion/g0/test.sh

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@
33
#export PATH=$PATH:$EMC2_HOME/tests/helpers
44
#source $EMC2_HOME/tests/helpers/test-functions.sh
55

6+
wait_for_pin() {
7+
pin="$1"
8+
value="$2"
9+
maxwait=10 # seconds
10+
while [ 0 -lt $maxwait ] \
11+
&& [ "$value" != "$(halcmd -s show pin $pin | awk '{print $4}')" ]; do
12+
sleep 1
13+
maxwait=$(($maxwait -1))
14+
done
15+
if [ 0 -eq $maxwait ] ; then
16+
echo "error: waiting for pin $pin timed out"
17+
kill $linuxcncpid
18+
kill $samplerpid
19+
exit 1
20+
fi
21+
}
22+
623
linuxcnc motion-test.ini &
24+
linuxcncpid=$!
725

8-
# let linuxcnc come up
9-
sleep 4
26+
wait_for_pin motion.in-position TRUE
1027

11-
(
12-
echo starting to capture data
13-
halsampler -t -n 20000 >| result.halsamples
14-
echo finished capturing data
15-
) &
28+
echo starting to capture data
29+
halsampler -t >| result.halsamples &
30+
samplerpid=$!
1631

1732
(
1833
echo hello EMC mt 1.0
@@ -26,21 +41,27 @@ sleep 4
2641
echo set home 1
2742
echo set home 2
2843

29-
# give linuxcnc a second to home
30-
sleep 1.0
44+
# Wait for homing to complete
45+
wait_for_pin motion.is-all-homed TRUE
3146

3247
echo set mode mdi
33-
echo set mdi g0x1
48+
dist=1
49+
echo set mdi g0x$dist
3450

35-
# give linuxcnc a half second to move
36-
sleep 0.5
51+
# Wait for movement to complete
52+
wait_for_pin joint.0.pos-fb $dist
53+
wait_for_pin joint.0.in-position TRUE
54+
wait_for_pin joint.1.in-position TRUE
3755

3856
echo shutdown
3957
) | nc localhost 5007
4058

59+
kill $samplerpid
60+
wait $samplerpid
61+
echo finished capturing data
4162

4263
# wait for linuxcnc to finish
43-
wait
64+
wait $linuxcncpid
4465

4566
exit 0
4667

0 commit comments

Comments
 (0)