This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
forked from linuxcnc-probe-screen/probe-screen-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
psng_hook.ngc
204 lines (187 loc) · 10.8 KB
/
psng_hook.ngc
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
; End users can copy this file to their macros folder and edit as necessary.
; This is useful to allow machine specific logic, such as checking HAL input
; pins to ensure a probe or toolsetter are connected.
; You should NOT edit this file directly, instead, you should copy this file
; from the psng/macros folder, to the macros folder and edit the copy.
; Alkabal 12/2020 exemple script for PSNG probe screen used with Linuxcnc 2.8/2.9
; This macro check multiple probe status and inhibit one or other if missing and not used for actual job
o<psng_hook> sub
; The #1 variable will be set to the name of the macro being hooked. For
; example, when o<psng_manual_change> is called, #1 will be set to the
; value "psng_manual_change".
#<hooked_macro> = #1
#<error> = 0
M65 P0 ; reset flasg used for clear all notification
o110 if [#<hooked_macro> LT 1 OR #<hooked_macro> GT 10]
; nothing to do here
(MSG,ERROR UNROCONIZED HOOK #<hooked_macro>)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o110 return
;Mode 3 & 5 PROBE IS ALLWAYS NEEDED AND SETTER NEVER NEEDED
o110 elseif [#<hooked_macro> EQ 3 OR #<hooked_macro> EQ 5]
o111 if [#5400 EQ 1 AND #<_hal[and2.combined-probe.in0]> EQ 0]
(MSG,PROBE AS TOOL 1 SEEM TO BE READY)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute ;Keep this for safety is something touch the setter when the job is executed this can stop the job
o112 if [#<_hal[and2.combined-setter.in0]> EQ 1]
(MSG,!!! INHIBIT UNUSED MISSING SETTER)
M64 P2 ; deactivate setter output to motion.probe-inpute
o112 endif
(MSG,NEED TO UNPAUSE) ; with old style prgram exit here https://github.com/linuxcnc-probe-screen/probe-screen-ng/pull/15#issuecomment-745364320
M0
o111 elseif [#5400 GT 1 AND #<_hal[and2.combined-probe.in0]> EQ 0]
(MSG,PROBE WITHOUT TOOL 1 AS PROBE NOT ALLOWED)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o111 elseif [#5400 EQ 0]
(MSG,PROBE WITH TOOL 0 NOT ALLOWED)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o111 else
#<error> = 1
o111 endif
;Mode 6 to 9 PROBE AND SETTER ARE NOT ALLWAYS NEEDED
o110 elseif [#<hooked_macro> GT 5 AND #<hooked_macro> LT 10]
o121 if [#5400 EQ 1 AND #<_hal[and2.combined-probe.in0]> EQ 0]
(MSG,PROBE AS TOOL 1 SEEM TO BE READY)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute ;Keep this for safety is something fail with probe the setter can stop the job this can append using tool diameter measurement with probe
o122 if [#<_hal[and2.combined-setter.in0]> EQ 1]
(MSG,!!! INHIBIT UNUSED MISSING SETTER)
M64 P2 ; deactivate setter output to motion.probe-inpute
o122 endif
(MSG,NEED TO UNPAUSE)
M0
; o121 elseif [#5400 EQ 1 AND #<_hal[and2.combined-probe.in0]> EQ 0 AND #<_hal[and2.combined-setter.in0]> EQ 0 AND #<flagvalue_after_gotots>]
; (MSG,PROBE AS TOOL 1 AND SETTER SEEM TO BE READY FOR DIAMETER MEASUREMENT)
; M64 P1 ; deactivate probe output to motion.probe-inpute for use TOOL SETTER FOR MEASURING PROBE diameter
; M65 P2 ; activate setter output to motion.probe-inpute
; (MSG,NEED TO UNPAUSE)
; M0
o121 elseif [#5400 GT 1 AND #<_hal[and2.combined-setter.in0]> EQ 0]
o123 if [#<_hal[and2.combined-probe.in0]> EQ 0]
(MSG,!!! PLEASE REMOVE TOUCH PROBE AND TRY AGAIN)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o123 else
(MSG,USE REAL TOOL FOR DIAMETER MEASUREMENT)
M64 P1 ; deactivate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
(MSG,NEED TO UNPAUSE)
M0
o123 endif
o121 elseif [#5400 EQ 0]
(MSG,PROBE WITH TOOL 0 NOT ALLOWED)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o121 else
#<error> = 1
o121 endif
;Mode 2 & 4 PROBE IS NOT ALLWAYS NEEDED BUT SETTER IS ALLWAYS NEEDED TOOL ALREADY IN SPINDLE
o110 elseif [#<hooked_macro> EQ 2 OR #<hooked_macro> EQ 4]
o131 if [#5400 EQ 1 AND #<_hal[and2.combined-probe.in0]> EQ 0 AND #<_hal[and2.combined-setter.in0]> EQ 0]
(MSG,SETTER AND PROBE AS TOOL 1 SEEM TO BE READY)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
(MSG,NEED TO UNPAUSE)
M0
o131 elseif [#5400 GT 1 AND #<_hal[and2.combined-setter.in0]> EQ 0]
o132 if [#<_hal[and2.combined-probe.in0]> EQ 0]
(MSG,!!! PLEASE REMOVE TOUCH PROBE AND TRY AGAIN)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o132 else
(MSG,SETTER SEEM TO BE READY FOR TOOL > 2)
M64 P1 ; deactivate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
(MSG,NEED TO UNPAUSE)
M0
o132 endif
o131 elseif [#5400 EQ 0]
(MSG,PROBE WITH TOOL 0 NOT ALLOWED)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o131 else
#<error> = 1
o131 endif
;Mode 1 TOOLCHANGE ONLY
o110 elseif [#<hooked_macro> EQ 1]
o141 if [#<_hal[probe.use_toolmeasurement]> EQ 0]
o141 return [3] ; indicate no tool measurement
o141 elseif [#<_selected_tool> EQ 1 AND #<_hal[and2.combined-probe.in0]> EQ 1 AND #<_hal[and2.combined-setter.in0]> EQ 0]
(MSG,MOUNT AND CONNECT TOUCH PROBE FOR TOOLCHANGE 1)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
MSG,NEED TO UNPAUSE)
M0 ; need to found a way for wait until probe is connected
o141 elseif [#<_selected_tool> EQ 1 AND #<_hal[and2.combined-probe.in0]> EQ 0 AND #<_hal[and2.combined-setter.in0]> EQ 0]
(MSG,SETTER AND TOUCH PROBE FOR TOOLCHANGE 1 SEEM TO BE READY)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
o141 elseif [#<_selected_tool> GT 1 AND #<_hal[and2.combined-setter.in0]> EQ 0 AND #<_hal[and2.combined-probe.in0]> EQ 1]
(MSG,SETTER AND UNCONNECTED TOUCH PROBE FOR TOOLCHANGE > 2 SEEM TO BE READY)
M64 P1 ; deactivate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
o141 elseif [#<_selected_tool> GT 1 AND #<_hal[and2.combined-setter.in0]> EQ 0 AND #<_hal[and2.combined-probe.in0]> EQ 0]
(MSG,!!! REMOVE AND UNCONNECT TOUCH PROBE FOR TOOLCHANGE > 2)
M64 P1 ; deactivate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
(MSG,NEED TO UNPAUSE)
M0 ; need to found a way for wait until probe is unconnected
o141 elseif [#<_selected_tool> EQ 0]
;(MSG,RESET TOOL NUMBER)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
;M2 NO NEED TO CANCEL HERE M6T0 is used for reset actual tool
o141 else
#<error> = 1
o141 endif
;Mode 10 todo drill
o110 elseif [#<hooked_macro> EQ 10]
(MSG,TODO DRILL DOWN TO TOOL SETTER OR NEED TO ADD IN OTHER MODE)
M0
o110 else
; nothing to do here
(MSG,PSNG HOOK NUMBER FAIL : call_hook #<hooked_macro>)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o110 endif
;ERROR CHECKING and return immeditly if this is a know error or goto fail mode because error is a missed possible status
o200 if [#<error> EQ 1]
o201 if [#<_hal[and2.combined-probe.in0]> EQ 1 AND #<_hal[and2.combined-setter.in0]> EQ 1]
(MSG,ERROR PROBE AND TOOL SETTER MISSING)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o201 elseif [#<_hal[and2.combined-probe.in0]> EQ 1]
(MSG,ERROR PROBE MISSING OR TOOL SELECTED IS NOT 1)
M64 P1 ; deactivate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o201 elseif [#<_hal[and2.combined-setter.in0]> EQ 1]
(MSG,ERROR TOOL SETTER MISSING)
M65 P1 ; activate probe output to motion.probe-inpute
M64 P2 ; deactivate setter output to motion.probe-inpute
M2
o201 else
; nothing to do here
(MSG,PSNG HOOK FAIL AND CANCEL THE WHOLE OPERATION)
(MSG,something is wrong regarding function checking)
(MSG,maybe need to add on more check)
(DEBUG,tool #5400, asked_tool #<_selected_tool>, setter_error #<_hal[and2.combined-setter.in0]>, probe_error #<_hal[and2.combined-probe.in0]>, call_hook #<hooked_macro>, error_flag #<error>)
M65 P1 ; activate probe output to motion.probe-inpute
M65 P2 ; activate setter output to motion.probe-inpute
M2
o201 endif
o200 endif
o<psng_hook> endsub
M2