-
Notifications
You must be signed in to change notification settings - Fork 2
/
xyz-zero-finder.sbp
470 lines (346 loc) · 14.4 KB
/
xyz-zero-finder.sbp
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
' ========================================================================================
' X, Y, and Z Zero'ing tool for PS1's Shopbot (www.pumpingstationone.org)
' Version 2.0; 1/13/2020
' ========================================================================================
' Give the user a chance to exit the program if they didn't intend to run it,
' or they're not ready to (e.g. the tool isn't positioned above the plate)
MSGBOX(Is the tool positioned above the upper part of the plate?, YesNo, Ready to Zero?)
IF &msganswer = "No" THEN GOTO EndOfProgram
' We want to make sure the bit is not spinning when running this program...
' Make sure the spindle RPMs are set to zero
TR,0
' And turn off the spindle
C7
' ****************************************************************************************
' Initialization of variables
' (Because it's nice to know what all the variables are ahead of time)
' ****************************************************************************************
' Set the scale we'll use
&SCALE = 1
' Used in calculating where Z should be
&zBottom = 0
' The thickness of the aluminum plate
&PLATE_THICKNESS = .5
' The size of the top part of the plate where Z is found (and then we move off from there)
' heading towards absolute X 0 (i.e. the front of the shopbot as it's positioned at PS1)
&TOP_PLATE_LENGTH = 2.5
' This is the length of the entire plate
&FULL_PLATE_LENGTH = 3.5
'
' A D J U S T M E N T S
' These two variables are for 'tweaking' the X and Y due to irregularities in the
' plate. These are very very piece-specific and if you make your own, it's likely
' you'll end up wanting to use these variables as well.
'
&xAdjustment = 0.044
&yAdjustment = 0.072
&zAdjustment = 0.030
' ****************************************************************************************
' First we need to figure out if we're in preview mode, or in tool
' mode. The program does nothing useful in preview mode
' ****************************************************************************************
¤tMode = %(22)
IF ¤tMode = 1 THEN GOSUB InPreviewMode
' ****************************************************************************************
' Okay, we're not in preview mode, so on with the show...
' ****************************************************************************************
' Load the custom variables file from Custom Cut 90
C#,90
' Get Speed Limits of the machine
' This subroutine sets the following
' variables:
' &TopApproachSpeed = .25
' &TopJogSpeed = 3.5
' &first_move = -2
' &second_move = 2
IF %(25) = 0 THEN GOSUB GetInchSpeedLimits
' TEMPORARY: Haven't figured out the metric values yet
IF %(25) = 1 THEN GOSUB MetricNotYet
'------------------------------------------------------------------------------
' Set up our X and Y speeds
'------------------------------------------------------------------------------
' Okay, now we have to get the current settings of the machine
' The System Variables are documented on page 36 of the
' Part File Programming Handbook for the OpenSBP Language
&start_XYmove_Speed = %(71) ' MoveSpeed X
&start_XYjog_Speed = %(76) ' JogSpeed X
' Now we're going to set up the X and Y speeds and
' if they exceed the max, we'll just set them to the
' max
' XYapproach_Speed is the speed we set the machine to
' use when approaching the plate (i.e. when we want to
' move slowly)
&XYapproach_Speed = &start_XYmove_Speed
IF &XYapproach_Speed > &TopApproachSpeed THEN &XYapproach_Speed = &TopApproachSpeed
' This is the speed we use to move quickly around the
' plate where we're not attempting to take measurements
&XYtempJog_Speed = &start_XYjog_Speed
IF &XYtempJog_Speed > &TopJogSpeed THEN &XYtempJog_Speed = &TopJogSpeed
' Now actually set the speed of the machine
' XY Move Speed, Z Move Speed, A Move Speed, B Move Speed, XY Jog Speed, Z Jog Speed, A Jog Speed, B Jog Speed
VS, &XYapproach_Speed,,,,&XYtempJog_Speed '... and assign slower speeds
'------------------------------------------------------------------------------
' Set up our Z speeds
'------------------------------------------------------------------------------
' Now we're going to do similar stuff for the Z axis
&start_Zmove_Speed = %(73) ' MoveSpeed Z
&new_Zmove_Speed = .25
'Set thickness and pull-up distance
&zBottom = &PLATE_THICKNESS * &SCALE
&zup = &my_ZzeroSafeZ * &SCALE
' ****************************************************************************************
' Okay, here we go....
' ****************************************************************************************
'Save start X and Y positions for use with centering
&start_X_pos = %(1) ' Location X
&start_Y_pos = %(2) ' Location Y
'Set paramaters
SA 'Set tool to Absolute mode
'Limits are deactivated here, automatically reset to original state when file ends
VN, 0 'Deactivate the limit switch functionality on input #3
SF, 0 'Deactivate software limits
' ----------------------------------------------------------------------------------------
' Z - A X I S Z E R O I N G
'
' Note that we're zeroing to the top of the plate, which we'll use as the basis for the
' calculations that will *really* set Z-zero.
' ----------------------------------------------------------------------------------------
GOSUB TEST_CLEAR 'Check for clear
' Set-up the contact switch action ...
ON INP(&my_ZzeroInput,1) GOSUB Zcontact 'this is where we'll go on contact with plate
VS, , &new_Zmove_Speed
&little_plunge = %(3) - 2
' Start continuous plunge ... looking for contact to occur
MZ, &little_plunge
' Contact! Save the position in the save_Z_dist variable
&save_Z_dist = %(3)
' ----------------------------------------------------------------------------------------
' X - A X I S Z E R O I N G
'
' Note that, similar to Z-Axis zeroing above, we are not actually setting the zero here,
' but finding the X-edge of the plate, which we'll use for calculation
' ----------------------------------------------------------------------------------------
'Set tool to Relative Mode because we want to move around based on where we currently are
SR
' Check for clear
GOSUB TEST_CLEAR
' Set the move speed
MS, &start_XYmove_Speed
'
' Do the right side first
'
' First we want to move off a bit in the positive X to clear the plate,
' we assume that the bit was placed somewhere in the middle of the top of
' the plate, so we do not add any additional distance to move in case we are
' close to the edge of the machine, in which case we do not want to trigger
' any limit switches
MX, &TOP_PLATE_LENGTH
' And now go back to being slow
MS, &XYapproach_Speed
' And now we want to go to the Z location and a little lower
&ZLocationForXTest = &zBottom - &zup - .40
VS, , &new_Zmove_Speed
MZ, &ZLocationForXTest
' Now we set up the contact switch action again ...
ON INP(&my_ZzeroInput, 1) GOSUB XContactRight ' this is where we'll go on contact with plate
' Record the position of the bit on the left side of the plate
&right_X_pos = %(1)
' Then we start moving in the positive X ( the * -1 for that)
MX, &TOP_PLATE_LENGTH * -1
'
' Now we move to do the left side
'
' We're still touching the plate, so let's move it back
' a little
MS, &XYapproach_Speed
MX, .25
' Okay, we have the position on the right side of the plate.
' Now we want to find the position on the left side of the plate, so
' we will be able to determine the diameter of the tool for better positioning
' First lift the tool an inch to clear the plate
VS, , &new_Zmove_Speed
MZ, 1
' Set the move speed
MS, &start_XYmove_Speed
' Move past the plate plus 1 inch
MX, (&FULL_PLATE_LENGTH + 1) * -1
' And now go back to being slow
MS, &XYapproach_Speed
' And now we want to go to the Z location and a little lower
&ZLocationForXTest = &zBottom - &zup - .60
VS, , &new_Zmove_Speed
MZ, &ZLocationForXTest
' First set the contact switch action ...
ON INP(&my_ZzeroInput, 1) GOSUB XContactLeft 'this is where we'll go on contact with plate
' Record the position of the bit on the left side of the plate
&left_X_pos = %(1)
' Then we start moving in the positive X until
' we hit the plate in which case we'll go into XContactLeft
MX, &TOP_PLATE_LENGTH
'
' Calculating tool diameter:
' Okay, we have the left and right sides. Now we're going to figure out the
' diameter of the tool by doing:
'
' (right_X_pos - left_X_pos) - FULL_PLATE_LENGTH
'
&toolDiameter = (&right_X_pos - &left_X_pos) - &FULL_PLATE_LENGTH
' And now we want the radius
&toolRadius = &toolDiameter / 2.0
' ----------------------------------------------------------------------------------------
' Y - A X I S Z E R O I N G
'
' Note that, similar to Z-Axis zeroing above, we are not actually setting the zero here,
' but finding the Y-edge of the plate, which we'll use for calculation
'
' ----------------------------------------------------------------------------------------
SR
MS, &start_XYmove_Speed
' Okay, as of right now we're sitting on the right edge of the plate somewhere. First
' we want to back off by an inch...
MX, -1
' Now we want to move in -Y the length of the plate
MY, &FULL_PLATE_LENGTH * -1
' Now put us inside the plate in the X axis
MX, 2.5
' And now go back to being slow
MS, &XYapproach_Speed
GOSUB TEST_CLEAR 'Check for clear
'First set the contact switch action ...
ON INP(&my_ZzeroInput,1) GOSUB Ycontact 'this is where we'll go on contact with plate
'Then start the move in Y
MY, &TOP_PLATE_LENGTH
' ****************************************************************************************
' Okay, we have the X, Y, and Z values as they currently stand; let's move to what
' we think 0,0,0 should be
' ****************************************************************************************
' We're still touching the plate in Y, so let's move back .25
MY, -.25
PAUSE 1
' Next move Z up to a safe spot
MZ, 2
PAUSE 1
' And put us back in absolute mode
SA
' And we need neither dilly nor dally getting there...
MS, &start_XYmove_Speed
' Now let's move to the right Y
' Where are we?
&NowY = %(2)
' Now move back to the edge plus 1 inch (the width of the lower plate)
MY, &NowY + 1 + &yAdjustment
PAUSE 1
' Now move to the X plus 1 inch (the width of the lower plate) + the
' tool radius
&myNewX = &save_X_dist + 1.0 + &xAdjustment + &toolRadius
MX, &myNewX
PAUSE 1
' And then we move the Z to 0
MZ, 0
PAUSE 1
' Now set the X, Y, and Z at this spot
VA, 0, 0, %(3),,,,,,,
PAUSE 1
MSGBOX(All Done. I am now going to move the bit out of the plate. Have a nice day., 48, Finished)
' And lift the tool 2 inches to clear the plate
MZ, 2
' ****************************************************************************************
' This is the end of the program
' ****************************************************************************************
EndOfProgram:
END
' ****************************************************************************************
' C O N T A C T R O U T I N E S
' ****************************************************************************************
' ----------------------------------------------------------------------------------------
' Z Contact
' ----------------------------------------------------------------------------------------
Zcontact:
' This is our subroutine for action on hitting the plate
' VA - Values for Axis Locations
VA, ,, &zBottom + &zAdjustment ,,,,,0 'Set final Z location and Zero Table Base Coordinate
PAUSE 1
VS, ,&start_Zmove_Speed ' Slow it down a bit
JZ, &zup ' Pull-up to safe height
RETURN
' ----------------------------------------------------------------------------------------
' X Contact
' ----------------------------------------------------------------------------------------
' This is our subroutine for action on hitting the plate on the left side
XContactLeft:
ON INP(&my_ZzeroInput, 1) 'Set switch to nothing to turn off
&left_X_pos = %(1)
&save_X_dist = %(1)
PAUSE 1
MX, -1 ' Move back out for another pass
ON INP(&my_ZzeroInput, 1) GOTO Xagain
' Now start moving back to the plate until we touch, in which
' case we'll jump immediately into Xagain
MX, &second_move
END
' This is our subroutine for action on hitting the plate on the right side
XContactRight:
ON INP(&my_ZzeroInput, 1) 'Set switch to nothing to turn off
&right_X_pos = %(1)
PAUSE 1
MX, 1 ' Move back out for another pass
ON INP(&my_ZzeroInput, 1) GOTO Xagain
' Now start moving back to the plate until we touch, in which
' case we'll jump immediately into Xagain
MX, &second_move * -1
END
Xagain:
ON INP(&my_ZzeroInput, 1) 'Set switch to nothing to turn off
PAUSE 1
RETURN
' ----------------------------------------------------------------------------------------
' Y Contact
' ----------------------------------------------------------------------------------------
Ycontact:
'This is our subroutine for action on hitting the plate
ON INP(&my_ZzeroInput,1) 'Set switch to nothing to turn off
&save_Y_dist = %(2)
PAUSE 1
MY, -1 '&start_X_pos 'Move back out for another pass
ON INP(&my_ZzeroInput,1) GOTO Yagain
MY, &second_move
END
Yagain:
ON INP(&my_ZzeroInput,1) 'Set switch to nothing to turn off
PAUSE 1
'msgbox (save_Y_dist is now &save_Y_dist, 48, Debugging)
RETURN
' ****************************************************************************************
' General purpose routines
' ****************************************************************************************
TEST_CLEAR:
&cleared = &my_ZzeroInput + 50
IF %(&cleared) = 1 THEN PAUSE 3
IF %(&cleared) = 1 THEN GOTO NO_CLEAR
RETURN
NO_CLEAR:
'Reset the orginal speeds
VS, ,&start_Zmove_Speed
VS, &start_XYmove_Speed,,,,&start_XYjog_Speed
'Contact did not clear for some reason. Exiting.
PAUSE
END
' Function that sets the speed limits in imperial
GetInchSpeedLimits:
&TopApproachSpeed = .25
&TopJogSpeed = 3.5
&second_move = 2
RETURN
' Function that tells the user the program is not going to work in preview mode
InPreviewMode:
' If we're here, that means we're in preview mode, which is kinda pointless
' for this program
MSGBOX(You are currently in preview mode which won't work with this program. Check that the ShopBot is switched on., 16, Preview Mode Detected)
PAUSE
END
' Function that exposes to the user the fact that I am bad at metric/imperial conversion
' math
MetricNotYet:
MSGBOX(Can't do metric just yet. Sorry about that. :(, 48, Metric...oooh...um...hmmm...)
PAUSE
END