summaryrefslogtreecommitdiff
path: root/tests/t0/shared-test.sh
blob: 431adadec645b9333310100fecde4ef5a8481117 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
#!/bin/bash
set -x

rm -f sim.var

# reset the tool table to a known starting configuration
rm -f tool.tbl
cp tool.tbl.original tool.tbl

rm -f gcode-output

linuxcnc -r sim.ini &


# let linuxcnc come up
TOGO=80
while [  $TOGO -gt 0 ]; do
    echo trying to connect to linuxcncrsh TOGO=$TOGO
    if nc -z localhost 5007; then
        break
    fi
    sleep 0.25
    TOGO=$(($TOGO - 1))
done
if [  $TOGO -eq 0 ]; then
    echo connection to linuxcncrsh timed out
    exit 1
fi


(
    function introspect() {
        SEQUENCE_NUMBER=$1
        echo "set mdi m100 P6 Q$SEQUENCE_NUMBER"  # sequence number
        echo "set wait done"
        echo 'set mdi m100 P0 Q#5420'             # X
        echo "set wait done"
        echo 'set mdi m100 P1 Q#5421'             # Y
        echo "set wait done"
        echo 'set mdi m100 P2 Q#5422'             # Z
        echo "set wait done"
        echo 'set mdi m100 P3 Q#5400'             # toolno
        echo "set wait done"
        echo 'set mdi m100 P4 Q#5403'             # TLO z
        echo "set wait done"
        echo 'set mdi m100 P5'                    # blank line
        echo "set wait done"
    }

    echo hello EMC mt 1.0
    echo set enable EMCTOO

    echo set estop off
    echo set machine on
    echo set mode mdi


    #
    # first, a bunch of testing with no tool in the spindle
    #
    # On nonrandom the spindle has T0, which is the nonrandom way to
    # specify the special tool that means "no tool".
    #
    # On random the spindle has T-1, which is the random way to specify the
    # special tool that means "no tool".
    #


    # Both random and nonrandom start this test with no tool in the
    # spindle, but they encode this in different ways.
    introspect 0


    #
    # g43
    #

    # Apply the TLO of the current tool.  On both, the spindle has no tool,
    # which has 0 TLO.
    echo set mdi g43
    introspect 1

    # Apply the TLO of tool T1.  On both, T1 is a valid tool, so we use its
    # TLO.
    echo set mdi g43 h1
    introspect 2

    # Apply the TLO of H0, this one is weird.
    #
    # On nonrandom, this requests the TLO of the tool in the spindle, which
    # is currently T0, which is a special tool with TLO 0.
    #
    # On random, this requests the TLO of T0.  If T0 is not in the tool
    # table, this is an error and the active TLO remains unchanged (so it
    # stays as the TLO of T1 that we just set above).  If T0 is defined, we
    # apply its TLO here.
    echo set mdi g43 h0
    introspect 3


    #
    # g10 l1
    #

    # Try to change TLO of the normal tool T7.  This should work on both,
    # but not change the active TLO.
    echo set mdi g10 l1 p7 z0.1
    introspect 4

    # Apply the TLO of T7, which we just tried to set.  This should work on
    # both.
    echo set mdi g43 h7
    introspect 5

    # Try to change TLO of the strange tool T0.
    #
    # This should fail in every config because you cannot change T0.
    echo set mdi g10 l1 p0 z0.2
    introspect 6

    # Apply the TLO of the special H0.
    #
    # On nonrandom, this requests the TLO of the tool in the spindle, which
    # is currently T0, which is a special tool with TLO 0.
    #
    # On random, this requests the TLO of T0.  If T0 is not in the tool
    # table, this is an error and the active TLO remains unchanged (so it
    # stays as the TLO of T7 that we just set above).  If T0 is defined, we
    # apply its TLO here.
    echo set mdi g43 h0
    introspect 7


    #
    # g10 l10
    #

    # Try to change TLO of the normal tool T7.  This should work on both.
    echo set mdi g10 l10 p7 z0.3
    introspect 8

    # Apply the TLO of T7, which we just tried to set.  This should work on
    # both.
    echo set mdi g43 h7
    introspect 9

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on every config because you cannot change T0.
    echo set mdi g10 l10 p0 z0.4
    introspect 10

    # Apply the TLO of the special H0.
    #
    # On nonrandom, this requests the TLO of the tool in the spindle, which
    # is currently T0, which is a special tool with TLO 0.
    #
    # On random, this requests the TLO of T0.  If T0 is not in the tool
    # table, this is an error and the active TLO remains unchanged (so it
    # stays as the TLO of T7 that we just set above).  If T0 is defined, we
    # apply its TLO here.
    echo set mdi g43 h0
    introspect 11


    #
    # g10 l11
    #

    # First offset the g59.3 coordinate system and make sure that worked,
    # but then switch back to g54.  This sets different g59.3 offsets in
    # different configs, because they have different active Z TLOs at this
    # point.
    #
    # Before this G10 L20, we are at the following Z locations:
    #             nonrandom: 0.0 (T0 TLO active)
    #     random without T0: 0.3 (T7 TLO active)
    #        random with T0: 0.0 (T0 TLO active)
    #
    # Then we set the G59.3 coordinate system offset such that the current
    # Z location is 5, which gives us these G59.3 Z offsets:
    #             nonrandom: -5.0 + 0.0 TLO = -5.0
    #     random without T0: -5.0 + 0.3 TLO = -4.7
    #        random with T0: -5.0 + 0.0 TLO = -5.0
    #
    # All the configs will be at Z=5.0 after switching to G59.3.
    echo set mdi g10 l20 p9 z5

    echo set mdi g59.3
    introspect 12

    echo set mdi g54
    introspect 13

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs.
    #
    # We should end up with the following Z coordinates:
    #             Nonrandom: -5.0 + 0.5 = -4.5
    #     Random without T0: -4.7 + 0.5 = -4.2
    #        Random with T0: -5.0 + 0.5 = -4.5
    #
    # But these offsets are not active until the G43 below.
    echo set mdi g10 l11 p7 z0.5
    introspect 14

    # Apply the TLO of T7, which we just tried to set.  This should
    # work on all configs.
    echo set mdi g43 h7
    introspect 15

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on every config because you cannot change T0.
    echo set mdi g10 l11 p0 z0.6
    introspect 16

    # Apply the TLO of the special H0.
    #
    # On nonrandom, this requests the TLO of the tool in the spindle, which
    # is currently T0, which is a special tool with TLO 0.
    #
    # On random, this requests the TLO of T0.  If T0 is not in the tool
    # table, this is an error and the active TLO remains unchanged (so it
    # stays as the TLO of T7 that we just set above).  If T0 is defined, we
    # apply its TLO here.
    echo set mdi g43 h0
    introspect 17


    #
    # That's all the testing we can do of the condition that there's
    # nothing in the spindle.  G41/G42 would be nice to test, but the
    # numbered parameters we use for introspection aren't accessible to
    # gcode while cutter comp is enabled.  :-(
    #
    # So we move on!  Put a valid tool in the spindle and test everything
    # again!
    #


    # Switch to the valid tool T50 but don't apply its TLO yet.
    # This should work on all configs.
    echo set mdi t50 m6
    introspect 100


    #
    # g43
    #

    # Apply the TLO of the current tool.  On all configs, the spindle has
    # T50.  This should work on all configs.
    echo set mdi g43
    introspect 101

    # change the TLO of the normal tool T7
    # this should work on both, but not change the active TLO
    echo set mdi g10 l10 p7 z1.1
    introspect 102

    # apply the TLO of the normal tool T7 (TLO of 0.5 set above)
    # this should work on both
    echo set mdi g43 h7
    introspect 103

    # try to change the TLO of T0
    #
    # On nonrandom this should fail because you can't change T0.
    #
    # On random without T0 this should fail because there is no T0.
    #
    # On random with T0 this should fail because you can't change T0.
    echo set mdi g10 l10 p0 z1.2
    introspect 104

    # Apply the TLO of the special H0.
    #
    # On nonrandom, this requests the TLO of the tool in the spindle, which
    # is currently T50.
    #
    # On random, this requests the TLO of T0.  If T0 is not in the tool
    # table, this is an error and the active TLO remains unchanged (so it
    # stays as the TLO of T7 that we just set above).  If T0 is defined, we
    # apply its TLO here.
    echo set mdi g43 h0
    introspect 105


    #
    # g10 l1
    #

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs, but not change the active TLO.
    echo set mdi g10 l1 p7 z1.3
    introspect 106

    # Apply the TLO of T7, which we just tried to set.  This should work on
    # all configs.
    echo set mdi g43 h7
    introspect 107

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on nonrandom because you cannot change T0.
    #
    # It should fail on random without T0 because it has no T0.
    #
    # It should fail on random with T0 because you cannot change T0.
    echo set mdi g10 l1 p0 z1.4
    introspect 108

    # Apply the TLO of the special H0.
    #
    # It should work on nonrandom and give us the TLO of the tool in the
    # spindle, T50 (in this config, G43 H0 means "use current tool").
    #
    # It should fail on random without T0 and leave the TLO at the value
    # from T7 above.
    #
    # It should work on random with T0 and give us the TLO of T0 (0.0).
    echo set mdi g43 h0
    introspect 109


    #
    # g10 l10
    #

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs.
    echo set mdi g10 l10 p7 z1.5
    introspect 110

    # Apply the TLO of T7, which we just tried to set.  This should work on
    # all configs.
    echo set mdi g43 h7
    introspect 111

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on nonrandom because you cannot change T0
    #
    # It should fail on random without T0 because it has no T0.
    #
    # It should fail on random with T0 because you cannot change T0
    echo set mdi g10 l10 p0 z1.6
    introspect 112

    # Apply the TLO of the special H0.
    #
    # It should work on nonrandom and give us the TLO of the tool in the
    # spindle, T50 (in this config, G43 H0 means "use current tool").
    #
    # It should fail on random without T0 and leave the TLO at the value
    # from T7 above.
    #
    # It should work on random with T0 and give us the TLO of T0 (0.0).
    echo set mdi g43 h0
    introspect 113

    # Try to change TLO of the currently loaded tool, T50.
    # This should work on all configs but not change the active TLO
    echo set mdi g10 l10 p50 z1.7
    introspect 114

    # Apply the TLO of the special H0.
    #
    # It should work on nonrandom and give us the TLO of the tool in the
    # spindle, T50 (in this config, G43 H0 means "use current tool").
    #
    # It should fail on random without T0 and leave the TLO at the value
    # from T7 above.
    #
    # It should work on random with T0 and give us the TLO of T0 (0.0).
    echo set mdi g43 h0
    introspect 115

    # Apply the TLO of T7.
    # This should work on all configs.
    echo set mdi g43 h7
    introspect 116

    # Apply the TLO of the current tool
    # This should work on all configs.
    echo set mdi g43
    introspect 117


    #
    # g10 l11
    #

    # First offset the G59.3 coordinate system and make sure that worked,
    # but then switch back to G54.  All configs are using the TLO of T50
    # at this point, so they all set the same G59.3 coordinate system
    # offset.
    #
    # Before this G10 L20, all configs are at Z=1.7 (T50 TLO active)
    #
    # Then we set the G59.3 coordinate system offset such that the current
    # Z location is 6, which gives us a G59.3 Z offset of:
    #     -6.0 + 1.7 TLO = -4.3
    #
    # All the configs will be at Z = 6.0 after switching to G59.3.
    echo set mdi g10 l20 p9 z6

    echo set mdi g59.3
    introspect 118

    echo set mdi g54
    introspect 119

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs.
    echo set mdi g10 l11 p7 z1.8
    introspect 120

    # Apply the TLO of T7, which we just tried to set.  This should
    # work on all configs.
    echo set mdi g43 h7
    introspect 121

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on nonrandom because you cannot change T0.
    #
    # It should fail on random without T0 because it has no T0.
    #
    # This should fail on random with T0 because you cannot change T0.
    echo set mdi g10 l11 p0 z1.3
    introspect 122

    # Apply the TLO of T0, which we just tried to set.
    #
    # It should work on nonrandom and give us a TLO of the tool in the
    # spindle, T50.
    #
    # It should fail on random and leave the TLO at the value from T7
    # above.
    #
    # It should work on random with T0 and give us the TLO of T0: 0.0
    echo set mdi g43 h0
    introspect 123


    #
    # Now load T0 into the spindle and retest everything again.
    #


    # Switch to the special tool T0 but don't apply its TLO yet.
    #
    # On nonrandom, this should unload the spindle.
    #
    # On random without T0 this should fail (there is no T0) and leave
    # T50 in the spindle.
    #
    # On random with T0 this should work and put T0 in the spindle.

    echo set mdi t0 m6
    introspect 200


    #
    # g43
    #

    # Apply the TLO of the current tool.
    #
    # On nonrandom the spindle has the special tool T0, which has a 0 TLO.
    #
    # On random without T0 the spindle has T50, which has a TLO of -1.15,
    # set above.
    #
    # On random with T0 the spindle has tool T0, which has a 0 TLO.
    echo set mdi g43
    introspect 201

    # change the TLO of the normal tool T7
    # this should work on all configs, but not change the active TLO
    echo set mdi g10 l10 p7 z2.0
    introspect 202

    # apply the TLO of the normal tool T7 (TLO set above)
    # this should work on all configs
    echo set mdi g43 h7
    introspect 203

    # try to change the TLO of T0
    #
    # On nonrandom this should fail because you can't change T0.
    #
    # On random without T0 this should fail because there is no T0.
    #
    # On random with T0 this should fail because you can't change T0.
    echo set mdi g10 l10 p0 z2.1
    introspect 204

    # try to apply the TLO of H0
    #
    # On nonrandom, this should apply the TLO of the current tool (special
    # handling of G43 H0).  The current tool is T0, which has 0 TLO.
    #
    # On random without T0 this should be an error (G43 H0 is nothing
    # special, but there is no T0) and the active TLO should remain
    # unchanged.
    #
    # On random with T0 this should apply the TLO of T0 (0.0).
    echo set mdi g43 h0
    introspect 205


    #
    # g10 l1
    #

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs, but not change the active TLO.
    echo set mdi g10 l1 p7 z2.2
    introspect 206

    # Apply the TLO of T7, which we just tried to set.  This should work on
    # all configs.
    echo set mdi g43 h7
    introspect 207

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on nonrandom because you cannot change T0.
    #
    # It should fail on random without T0 because it has no T0.
    #
    # This should fail on random with T0 because you cannot change T0.
    echo set mdi g10 l1 p0 z2.3
    introspect 208

    # Apply the TLO of H0.
    #
    # It should work on nonrandom and give us the TLO of the tool in the
    # spindle, T50.
    #
    # It should fail on random without T0 and leave the TLO at the value
    # from T7 above.
    #
    # It should work on random with TLO and give us the TLO of T0.
    echo set mdi g43 h0
    introspect 209


    #
    # g10 l10
    #

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs.
    echo set mdi g10 l10 p7 z2.4
    introspect 210

    # Apply the TLO of T7, which we just tried to set.  This should work on
    # all configs.
    echo set mdi g43 h7
    introspect 211

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on nonrandom because you cannot change T0
    #
    # It should fail on random without T0 because it has no T0.
    #
    # It should fail on random with T0 because you cannot change T0
    echo set mdi g10 l10 p0 z2.5
    introspect 212

    # Apply the TLO of the special H0.
    #
    # It should work on nonrandom and give us the TLO of the tool in the
    # spindle, T0 (in this config, G43 H0 means "use current tool").
    #
    # It should fail on random without T0 and leave the TLO at the value
    # from T7 above.
    #
    # It should work on random with T0 and give us the TLO of T0 (0.0).
    echo set mdi g43 h0
    introspect 213


    #
    # g10 l11
    #

    # First offset the G59.3 coordinate system and make sure that worked,
    # but then switch back to G54.  This sets different G59.3 offsets in
    # different configs, because they have different active Z TLOs at
    # this point.
    #
    # Before this G10 L20, we are at the following Z locations:
    #             nonrandom: 0.0 (T0 TLO active)
    #     random without T0: 2.4 (T7 TLO active)
    #        random with T0: 0.0 (T0 TLO active)
    #
    # Then we set the G59.3 coordinate system offset such that the current
    # Z location is 7, which gives us these G59.3 Z offsets:
    #             nonrandom: -7.0 + 0.0 TLO = -7.0
    #     random without T0: -7.0 + 2.4 TLO = -4.6
    #        random with T0: -7.0 + 0.0 TLO = -7.0
    #
    # All the configs will be at Z=7.0 after switching to G59.3.
    echo set mdi g10 l20 p9 z7

    echo set mdi g59.3
    introspect 214

    echo set mdi g54
    introspect 215

    # Try to change TLO of the normal tool T7.  This should work on all
    # configs.
    #
    # We should end up with the following Z coordinates:
    #             Nonrandom: -7.0 + 2.6 = -4.4
    #     Random without T0: -4.6 + 2.6 = -2.0
    #        Random with T0: -7.0 + 2.6 = -4.4
    #
    # But these offsets are not active until the G43 below.
    echo set mdi g10 l11 p7 z2.6
    introspect 216

    # Apply the TLO of T7, which we just tried to set.  This should
    # work on all configs.
    echo set mdi g43 h7
    introspect 217

    # Try to change TLO of the strange tool T0.
    #
    # This should fail on nonrandom because you cannot change T0.
    #
    # It should fail on random without T0 because it has no T0.
    #
    # It should work on random with T0 because you cannot change T0.
    echo set mdi g10 l11 p0 z2.7
    introspect 218

    # Apply the TLO of H0.
    #
    # It should work on nonrandom and give us a TLO of the tool in the
    # spindle, T0
    #
    # It should fail on random without T0 and leave the TLO at the value
    # from T7 above.
    #
    # It should work on random with T0 and give us a TLO of the tool in the
    # spindle, T0
    echo set mdi g43 h0
    introspect 219


    # give linuxcnc a second to finish
    sleep 1.0

    echo shutdown
) | nc localhost 5007


# wait for linuxcnc to finish
wait

exit 0