manual_change.ngc
Kod: Zaznacz cały
1 ; manual toolchange with automatic tool length probe
2
3 o<manual_change> sub
4
5 (we change feed, metric/in and potentially G90)
6 (so mark as save caller state & auto-restore on return or endsub)
7
8 M73
9
10 G21 (TLO and toolchange position is in mm as per ini)
11 G90 (absolute)
12
13 ; move to toolchange position: z, then xy
14 g53 g0 Z #<_ini[change_position]z>
15 g53 g0 X #<_ini[change_position]x> Y #<_ini[change_position]y>
16
17 ; indicate tool number to be loaded
18 M68 E #<_ini[pins]toolno> Q #<_selected_tool>
19
20 ; enable table
21 M64 P #<_ini[pins]enable>
22
23 ; signal user to change tool
24 M64 P #<_ini[pins]change>
25
26 ; and wait for acknowledgement
27 M66 P #<_ini[pins]changed> L1 Q#<_ini[dwell]ack_secs>
28 M65 P #<_ini[pins]change> ; drop change pin
29
30
31 ;see if we timed out
32 O100 if [#5399 EQ -1]
33 M65 P #<_ini[pins]enable> ; disable table
34 O100 return [-1] ; indicate timeout failure to epilog
35 O100 endif
36
37 O200 if [#<_selected_tool> EQ 0] ; an unload.
38 M65 P #<_ini[pins]enable> ; disable table
39 O200 return [1] ; indicate success
40 O200 endif
41
42 ; tool changed - move to toolensor
43 g53 g0 X #<_ini[toolsensor]x> Y #<_ini[toolsensor]y>
44 g53 g0 Z #<_ini[toolsensor]z>
45
46 ; probe tool length
47 M64 P #<_ini[pins]probing> ; turn on probing led
48
49 F #<_ini[toolsensor]probefeed>
50 G91 (relative mode)
51 G38.3 Z #<_ini[toolsensor]maxprobe>
52
53 ; we must execute this only in the milltask interpreter
54 ; or preview will break, so test for '#<_task>' which is 1 for
55 ; the milltask interpreter and 0 in the UI's
56
57 O300 if [[#<_task> GT 0] and [#5070 EQ 0]]
58 O300 return [-2] ; indicate probe contact failure to epilog
59 O300 endif
60
61
62 ; see wether this was the reference tool:
63 M66 P #<_ini[pins]reftool> L0
64
65 O400 if [#5399 EQ 1]
66 #1000=#5063 (save reference tool length)
67 M68 E #<_ini[pins]reflen> Q #1000
68 (print,reference length is #1000)
69 O400 else
70 g43.1 z[#5063-#1000] (set new tool offset)
71 M68 E #<_ini[pins]currlen> Q [#5063-#1000]
72 (print,new length is #5063)
73 O400 endif
74
75 M65 P #<_ini[pins]probing> ; drop probing led
76 M65 P #<_ini[pins]enable> ; disable table
77
78 G90 (absolute)
79
80
81 ; move back to toolchange position: z, then xy
82 g53 g0 Z #<_ini[change_position]z>
83 g53 g0 X #<_ini[change_position]x> Y #<_ini[change_position]y>
84
85 ; succeed by returning a positive value
86 o<manual_change> endsub [1]
87 m2