/
probe_routines.py
1994 lines (1821 loc) · 72.9 KB
/
probe_routines.py
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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Qtvcp - common probe routines
# This class is used by both VersaProbe and BasicProbe
import sys
import time
import select
import math
import linuxcnc
from qtvcp.core import Status, Action, Info
from qtvcp import logger
LOG = logger.getLogger(__name__)
# Force the log level for this module
#LOG.setLevel(logger.ERROR) # One of DEBUG, INFO, WARNING, ERROR, CRITICAL
ACTION = Action()
STATUS = Status()
INFO = Info()
class ProbeRoutines():
def __init__(self):
self.timeout = 30
##################
# Helper Functions
##################
# mdi timeout setting
def set_timeout(self, time):
self.timeout = time
def z_clearance_up(self):
# move Z+ z_clearance
s = """G91
G1 F{} Z{}
G90""".format(self.data_rapid_vel, self.data_z_clearance + self.data_extra_depth)
return self.CALL_MDI_WAIT(s, self.timeout)
def z_clearance_down(self):
# move Z- z_clearance
s = """G91
G1 F{} Z-{}
G90""".format(self.data_rapid_vel, self.data_z_clearance + self.data_extra_depth)
return self.CALL_MDI_WAIT(s, self.timeout)
def length_x(self):
if self.status_xp is None: self.status_xp = 0
if self.status_xm is None: self.status_xm = 0
if self.status_xp == 0 or self.status_xm == 0: return 0
self.status_lx = abs(self.status_xp - self.status_xm)
return self.status_lx
def length_y(self):
if self.status_yp is None: self.status_yp = 0
if self.status_ym is None: self.status_ym = 0
if self.status_yp == 0 or self.status_ym == 0: return 0
self.status_ly = abs(self.status_yp - self.status_ym)
return self.status_ly
def set_zero(self, s):
if self.allow_auto_zero is True:
c = "G10 L20 P0"
if "X" in s:
c += " X{}".format(self.data_adj_x)
if "Y" in s:
c += " Y{}".format(self.data_adj_y)
if "Z" in s:
c += " Z{}".format(self.data_adj_z)
ACTION.CALL_MDI(c)
ACTION.RELOAD_DISPLAY()
def rotate_coord_system(self, a=0.):
self.status_a = a
if self.allow_auto_skew is True:
s = "G10 L2 P0"
if self.allow_auto_zero is True:
s += " X{}".format(self.data_adj_x)
s += " Y{}".format(self.data_adj_y)
else:
STATUS.stat.poll()
x = STATUS.stat.position[0]
y = STATUS.stat.position[1]
s += " X{}".format(x)
s += " Y{}".format(y)
s += " R{}".format(a)
self.CALL_MDI_WAIT(s, self.timeout)
ACTION.RELOAD_DISPLAY()
def add_history(self, text, s="",xm=0.,xc=0.,xp=0.,lx=0.,ym=0.,yc=0.,yp=0.,ly=0.,z=0.,d=0.,a=0.):
tpl = '%.3f' if STATUS.is_metric_mode() else '%.4f'
c = text
list = ['Xm', 'Xc', 'Xp', 'Lx', 'Ym', 'Yc', 'Yp', 'Ly', 'Z', 'D', 'A']
arg = (xm, xc, xp, lx, ym, yc, yp, ly, z, d, a)
for i in range(len(list)):
if list[i] in s:
c += ' ' + list[i] + "[" + tpl%(arg[i]) + ']'
self.history_log = c
def probe(self, name):
if name == "xminus" or name == "yminus" :
travel = 0 - self.data_max_travel
latch = 0 - self.data_latch_return_dist
elif name == "xplus" or name == "yplus":
travel = self.data_max_travel
latch = self.data_latch_return_dist
else:
return -1
axis = name[0].upper()
laxis = name[0].lower()
# save current position so we can return to it
rtn = self.CALL_MDI_WAIT('#<{}>=#<_{}>'.format(laxis,laxis), self.timeout)
# probe toward target
s = """G91
G38.2 {}{} F{}""".format(axis, travel, self.data_search_vel)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe {} failed: {}'.format(name, rtn)
# retract
s = "G1 {}{} F{}".format(axis, -latch, self.data_rapid_vel)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe {} failed: {}'.format(name, rtn)
# wait and probe toward target
s = """G4 P0.5
G38.2 {}{} F{}""".format(axis, 1.2*latch, self.data_probe_vel)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe {} failed: {}'.format(name, rtn)
# retract to original position
s = "G90 G1 {}#<{}> F{}".format(axis, laxis, self.data_rapid_vel)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe {} failed: {}'.format(name, rtn)
# return all good
return 1
def CALL_MDI_LIST(self, codeList):
for s in codeList:
# call the gcode in MDI
if type(s) is str:
rtn = self.CALL_MDI_WAIT(s, self.timeout)
# call the function directly
else:
rtn = s()
if rtn != 1:
return 'failed: {} cmd: {}'.format(rtn, s)
return 1
def CALL_MDI_WAIT(self, code, timeout = 5):
LOG.debug('MDI_WAIT_COMMAND= {}, maxt = {}'.format(code, timeout))
for l in code.split("\n"):
ACTION.CALL_MDI( l )
result = ACTION.cmd.wait_complete(timeout)
try:
# give a chance for the error message to get to stdin
time.sleep(.01)
error = STATUS.ERROR.poll()
if not error is None:
ACTION.ABORT()
return error[1]
except Exception as e:
ACTION.ABORT()
return '{}'.format(e)
if result == -1:
ACTION.ABORT()
return 'Command timed out: ({} second)'.format(timeout)
elif result == linuxcnc.RCS_ERROR:
ACTION.ABORT()
return 'MDI_COMMAND_WAIT RCS error'
return 1
#########################
# toolsetter
#########################
def goto_toolsetter(self):
try:
# basic sanity check
for test in('z_max_clear','ts_x','ts_y','ts_z','ts_max'):
if self['data_{}'.format(test)] is None:
return'Missing toolsetter setting: {}'.format(test)
# raise to safe Z height
# move to tool setter (XY then Z)
# offset X by tool radius (from toolfile)
cmdList = []
cmdList.append('F{}'.format(self.data_rapid_vel))
cmdList.append('G53 G1 Z{}'.format(self.data_z_max_clear))
cmdList.append('G53 G1 X{} Y{}'.format(self.data_ts_x, self.data_ts_y))
cmdList.append('G53 G1 Z{}'.format(self.data_ts_z))
# call each command - if fail report the error and gcode command
rtn = self.CALL_MDI_LIST(cmdList)
if rtn != 1:
return rtn
# report success
return 1
except Exception as e:
return '{}'.format(e)
def wait(self):
rtn = self.CALL_MDI_WAIT('G4 p 5', self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
return 1
def probe_tool_z(self):
return self.probe_tool_with_toolsetter()
def probe_tool_with_toolsetter(self):
try:
# basic sanity checks
for test in('ts_x','ts_y','ts_z','ts_max','ts_diam','tool_probe_height', 'tool_block_height'):
if self['data_{}'.format(test)] is None:
return'Missing toolsetter setting: {}'.format(test)
if self.data_tool_diameter is None or self.data_tool_number is None:
return 'No tool diameter found'
# see if we need to offset for tool diameter
# if so see if there is enough room in X axis limits
if self.data_tool_diameter > self.data_ts_diam:
# if close to edge of machine X, offset in the opposite direction
xplimit = float(INFO.INI.find('AXIS_X','MAX_LIMIT'))
xmlimit = float(INFO.INI.find('AXIS_X','MIN_LIMIT'))
if not (self.data_tool_diameter/2+self.data_ts_x) > xplimit:
Xoffset = self.data_tool_diameter/2
elif not (self.data_ts_x -(self.data_tool_diameter/2)) < xmlimit:
Xoffset = 0-self.data_tool_diameter/2
else:
return 'cannot offset enough in X for tool diameter'
else: Xoffset = 0
# offset X by tool radius (from toolfile) if required
# probe Z
# raise Z clear
# move back X by tool radius if required
cmdList = []
cmdList.append('F{}'.format(self.data_rapid_vel))
cmdList.append('G91 ')
# should start spindle in proper direction/speed here..
cmdList.append('G1 X{}'.format(Xoffset))
cmdList.append('G38.2 Z-{} F{}'.format(self.data_ts_max,self.data_search_vel))
cmdList.append('G1 Z{} F{}'.format(self.data_latch_return_dist, self.data_rapid_vel))
cmdList.append('F{}'.format(self.data_probe_vel))
cmdList.append('G38.2 Z-{}'.format(self.data_latch_return_dist*1.2))
cmdList.append('G1 Z{} F{}'.format(self.data_z_clearance, self.data_rapid_vel))
cmdList.append('G1 X{}'.format(-Xoffset))
cmdList.append('G90')
cmdList.append('#<touch_result> = #5063')
cmdList.append('G10 L1 P{} Z[#<touch_result> -{}]'.format(
self.data_tool_number,self.data_tool_probe_height+self.data_tool_block_height))
cmdList.append('G43')
# call each command - if fail report the error and gcode command
rtn = self.CALL_MDI_LIST(cmdList)
if rtn != 1:
return rtn
h = STATUS.get_probed_position()[2]
self.status_z = h
self.add_history('Probed Tool height',"Z",0,0,0,0,0,0,0,0,h,0,0)
# report success
return 1
except Exception as e:
return '{}'.format(e)
def probe_ts_z(self):
try:
# basic sanity checks
if self.data_ts_max is None:
return'Missing toolsetter setting: data_ts_max'
# probe Z
# raise z clear
cmdList = []
cmdList.append('G49')
cmdList.append('G91')
cmdList.append('G38.2 Z-{} F{}'.format(self.data_ts_max,self.data_search_vel))
cmdList.append('G1 Z{} F{}'.format(self.data_latch_return_dist, self.data_rapid_vel))
cmdList.append('F{}'.format(self.data_probe_vel))
cmdList.append('G38.2 Z-{}'.format(self.data_latch_return_dist*1.2))
cmdList.append('G1 Z{} F{}'.format(self.data_z_clearance, self.data_rapid_vel))
cmdList.append('G90')
# call each command - if fail report the error and gcode command
rtn = self.CALL_MDI_LIST(cmdList)
if rtn != 1:
return rtn
h=STATUS.get_probed_position()[2]
self.status_th = h
self.add_history('Tool Setter height',"Z",0,0,0,0,0,0,0,0,h,0,0)
# report success
return 1
except Exception as e:
return '{}'.format(e)
# TOOL setter Diameter/height
# returns 1 for success or a string error message for failure
def probe_tool_z_diam(self):
try:
# probe tool height
rtn = self.probe_tool_with_toolsetter()
if rtn != 1:
return 'failed: {}'.format(rtn)
# confirm there is enough axis room to offset for diameters of tool and toolsetter
xplimit = float(INFO.INI.find('AXIS_X','MAX_LIMIT'))
xmlimit = float(INFO.INI.find('AXIS_X','MIN_LIMIT'))
offset = (self.data_tool_diameter+self.data_ts_diam)*.5
if (offset+self.data_ts_x) > xplimit:
return 'cannot offset enough in + X for tool radius + toolsetter radius'
elif (self.data_ts_x -(offset)) < xmlimit:
return 'cannot offset enough in - X for tool radius + toolsetter radius'
yplimit = float(INFO.INI.find('AXIS_Y','MAX_LIMIT'))
ymlimit = float(INFO.INI.find('AXIS_Y','MIN_LIMIT'))
if (offset+self.data_ts_y) > yplimit:
return 'cannot offset enough in + Y for tool radius offset + toolsetter radius'
elif (self.data_ts_y -(offset)) < ymlimit:
return 'cannot offset enough in - Y for tool radius offset + toolsetter radius'
# move X - edge_length- xy_clearance
s="""G91
G1 F%s X-%f
G90""" % (self.data_rapid_vel, 0.5 * self.data_ts_diam + self.data_xy_clearance)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
# Start xplus
rtn = self.probe('xplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xpres=float(a[0])+0.5*self.data_probe_diam
# move Z to start point up
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
# move to found point X
s = "G1 F%s X%f" % (self.data_rapid_vel, xpres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
# move X + data_ts_diam + xy_clearance
aa=self.data_ts_diam+self.data_xy_clearance
s="""G91
G1 X%f
G90""" % (aa)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
# Start xminus
rtn = self.probe('xminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xmres=float(a[0])-0.5*self.data_probe_diam
self.length_x()
xcres=0.5*(xpres+xmres)
self.status_xc = xcres
# move Z to start point up
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
# go to the new center of X
s = "G1 F%s X%f" % (self.data_rapid_vel, xcres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
# move Y - data_ts_diam/2 - xy_clearance
a=0.5*self.data_ts_diam+self.data_xy_clearance
s="""G91
G1 Y-%f
G90""" % a
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
# Start yplus
rtn = self.probe('yplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
ypres=float(a[1])+0.5*self.data_probe_diam
# move Z to start point up
if self.z_clearance_up() == -1:
return
# move to found point Y
s = "G1 Y%f" % ypres
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
# move Y + data_ts_diam + xy_clearance
aa=self.data_ts_diam+self.data_xy_clearance
s="""G91
G1 Y%f
G90""" % (aa)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
# Start yminus
rtn = self.probe('yminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
ymres=float(a[1])-0.5*self.data_probe_diam
self.length_y()
# find, show and move to found point
ycres=0.5*(ypres+ymres)
self.status_yc = ycres
diam=self.data_probe_diam + (ymres-ypres-self.data_ts_diam)
self.status_d = diam
# move Z to start point up
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
tmpz=STATUS.stat.position[2] - self.data_z_clearance
self.status_z=tmpz
self.add_history('Tool diameter',"XcYcZD",0,xcres,0,0,0,ycres,0,0,tmpz,diam,0)
# move to found point
s = "G1 Y%f" % ycres
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
# success
return 1
except Exception as e:
return '{}'.format(e)
########################
# material
########################
def probe_material_z(self):
try:
# basic sanity checks
if self.data_ts_max is None:
return'Missing toolsetter setting: data_ts_max'
cmdList = []
cmdList.append('G49')
cmdList.append('G92.1')
cmdList.append('G10 L20 P0 Z[#<_abs_z>]')
cmdList.append('G91')
cmdList.append('F {}'.format(self.data_search_vel))
cmdList.append('G38.2 Z-{}'.format(self.data_ts_max))
cmdList.append('G1 Z{} F{}'.format(self.data_latch_return_dist, self.data_rapid_vel))
cmdList.append('F{}'.format(self.data_probe_vel))
cmdList.append('G38.2 Z-{}'.format(self.data_latch_return_dist*1.2))
cmdList.append('G1 Z{} F{}'.format(self.data_z_clearance, self.data_rapid_vel))
cmdList.append('G90')
# call each command - if fail report the error and gcode command
rtn = self.CALL_MDI_LIST(cmdList)
if rtn != 1:
return rtn
h=STATUS.get_probed_position()[2]
self.status_bh = h
self.add_history('Probe Material Top',"Z",0,0,0,0,0,0,0,0,h,0,0)
# report success
return 1
except Exception as e:
return '{}'.format(e)
####################
# Z rotation probing
####################
# Front left corner
def probe_angle_yp(self):
# move Y- xy_clearance
s = """G91
G1 F%s Y-%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('yplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
ycres = float(a[1]) + 0.5 * self.data_probe_diam
self.status_yc = ycres
# move X+ edge_length
s = """G91
G1 F%s X%f
G90""" % (self.data_rapid_vel, self.data_side_edge_length)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('yplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
ypres = float(a[1])+0.5*self.data_probe_diam
self.status_yp = ypres
alfa = math.degrees(math.atan2(ypres - ycres, self.data_side_edge_length))
self.add_history('Rotation YP ', "YcYpA", 0, 0, 0, 0, 0, ycres, ypres, 0, 0, 0, alfa)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
self.rotate_coord_system(alfa)
return 1
# Back right corner
def probe_angle_ym(self):
# move Y+ xy_clearance
s = """G91
G1 F%s Y%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
if self.probe('yminus') == -1: return
# show Y result
a = STATUS.get_probed_position_with_offsets()
ycres = float(a[1]) -0.5 * self.data_probe_diam
self.status_yc = ycres
# move X- edge_length
s = """G91
G1 F%s X-%f
G90""" % (self.data_rapid_vel, self.data_side_edge_length)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
if self.probe('yminus') == -1: return
# show Y result
a = STATUS.get_probed_position_with_offsets()
ymres = float(a[1])-0.5*self.data_probe_diam
self.status_ym = ymres
alfa = math.degrees(math.atan2(ycres-ymres,self.data_side_edge_length))
self.add_history('Rotation YM ', "YmYcA", 0, 0, 0, 0, ymres, ycres, 0, 0, 0, 0, alfa)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
self.rotate_coord_system(alfa)
return 1
# Back left corner
def probe_angle_xp(self):
# move X- xy_clearance
s = """G91
G1 F%s X-%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xcres = float(a[0]) + 0.5 * self.data_probe_diam
self.status_xc = xcres
# move Y- edge_length
s = """G91
G1 F%s Y-%f
G90""" % (self.data_rapid_vel, self.data_side_edge_length)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xpres = float(a[0]) + 0.5 * self.data_probe_diam
self.status_xp = xpres
alfa = math.degrees(math.atan2(xcres - xpres, self.data_side_edge_length))
self.add_history('Rotation XP', "XcXpA", 0, xcres, xpres, 0, 0, 0, 0, 0, 0, 0, alfa)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
self.rotate_coord_system(alfa)
return 1
# Front right corner
def probe_angle_xm(self):
# move X+ xy_clearance
s = """G91
G1 F%s X%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xcres = float(a[0]) - 0.5 * self.data_probe_diam
self.status_xc = xcres
# move Y+ edge_length
s = """G91
G1 F%s Y%f
G90""" % (self.data_rapid_vel, self.data_side_edge_length)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xmres = float(a[0]) - 0.5 * self.data_probe_diam
self.status_xm = xmres
alfa = math.degrees(math.atan2(xcres - xmres, self.data_side_edge_length))
self.add_history('Rotation XM ', "XmXcA", xmres, xcres, 0, 0, 0, 0, 0, 0, 0, 0, alfa)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
self.rotate_coord_system(alfa)
return 1
###################
# Inside probing
###################
def probe_xy_hole(self):
self.history_log = 'Probe_xy_hole did not finish'
rtn = self.z_clearance_down()
if rtn != 1:
return 'Probe_xy_hole failed: clearance up: {}'.format(rtn)
# move X- edge_length - xy_clearance if needed
tmpx = self.data_side_edge_length - self.data_xy_clearance
if tmpx > 0:
s = """G91
G1 F%s X-%f
G90""" % (self.data_rapid_vel, tmpx)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe_xy_hole failed: X minus rapid positioning {}'.format(rtn)
elif self.data_max_travel < self.data_side_edge_length:
return 'Probe_xy_hole failed: Max travel is less then hole radius while xy_clearance is too large for rapid positioning'
elif self.data_max_travel < (2 * self.data_side_edge_length - self.data_latch_return_dist):
return 'Probe_xy_hole failed: Max travel is less then hole diameter while xy_clearance is too large for rapid positioning'
# rough probe
rtn = self.probe('xminus')
if rtn != 1:
return 'Probe_xy_hole failed: X minus probe: {}'.format(rtn)
# show -X result
a = STATUS.get_probed_position_with_offsets()
xmres = float(a[0])-0.5*self.data_probe_diam
self.status_xm = xmres
# move X+ 2 * (edge_length) - latch_return - xy_clearance
tmpx = 2 * (self.data_side_edge_length) - self.data_latch_return_dist - self.data_xy_clearance
if tmpx > 0:
s = """G91
G1 F%s X%f
G90""" % (self.data_rapid_vel, tmpx)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe_xy_hole failed: X plus rapid positioning: {}'.format(rtn)
# probe
rtn = self.probe('xplus')
if rtn != 1:
return 'Probe_xy_hole failed: X plus probe: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xpres = float(a[0]) + 0.5 * self.data_probe_diam
self.status_xp = xpres
len_x = self.length_x()
xcres = 0.5 * (xmres + xpres)
self.status_xc = xcres
# move X to new center
s = """G90
G1 F%s X%f""" % (self.data_rapid_vel, xcres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe_xy_hole failed: X return to center: {}'.format(rtn)
# move Y- edge_length + xy_clearance
tmpy = self.data_side_edge_length - self.data_xy_clearance
if tmpy > 0:
s = """G91
G1 F%s Y-%f
G90""" % (self.data_rapid_vel, tmpy)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe_xy_hole failed: Y minus rapid positioning: {}'.format(rtn)
rtn = self.probe('yminus')
if rtn == -1: return 'Probe_xy_hole failed: Y minus probe: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
ymres = float(a[1]) - 0.5 * self.data_probe_diam
self.status_ym = ymres
# move Y+ 2 * (edge_length) - latch_return - xy_clearance)
tmpy = 2 * (self.data_side_edge_length) - self.data_latch_return_dist - self.data_xy_clearance
if tmpy > 0:
s = """G91
G1 F%s Y%f
G90""" % (self.data_rapid_vel, tmpy)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe_xy_hole failed: Y minus rapid positioning {}'.format(rtn)
rtn = self.probe('yplus')
if rtn != 1:
return 'Probe_xy_hole failed: Y plus probe: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
ypres = float(a[1]) + 0.5 * self.data_probe_diam
self.status_yp = ypres
len_y = self.length_y()
# find, show and move to found point
ycres = 0.5 * (ymres + ypres)
self.status_yc = ycres
diam = 0.5 * ((xpres - xmres) + (ypres - ymres))
self.status_d = diam
self.add_history('Inside Hole ', "XmXcXpLxYmYcYpLyD", xmres, xcres, xpres, len_x, ymres, ycres, ypres, len_y, 0, diam, 0)
rtn = self.z_clearance_up()
if rtn != 1:
return 'Probe_xy_hole failed: clearance up: {}'.format(rtn)
# move to center
s = "G1 F%s Y%f" % (self.data_rapid_vel, ycres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'Probe_xy_hole failed: Y return to center: {}'.format(rtn)
self.set_zero("XY")
return 1
# Corners
# Move Probe manual under corner 2-3 mm
# Back left inside corner
def probe_inside_xpyp(self):
# move X- xy_clearance Y- edge_length
s = """G91
G1 F%s X-%f Y-%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance,self.data_side_edge_length )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xres = float(a[0]) + 0.5 * self.data_probe_diam
self.status_xp = xres
len_x = self.length_x()
# move X- edge_length Y- xy_clearance
tmpxy = self.data_side_edge_length - self.data_xy_clearance
s = """G91
G1 F%s X-%f Y%f
G90""" % (self.data_rapid_vel, tmpxy,tmpxy)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('yplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
yres = float(a[1]) + 0.5 * self.data_probe_diam
self.status_yp = yres
len_y = self.length_y()
self.add_history('Inside XPYP ', "XpLxYpLy", 0, 0, xres, len_x, 0, 0, yres, len_y, 0, 0, 0)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
# move to found point
s = "G1 F%s X%f Y%f" % (self.data_rapid_vel, xres,yres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
self.set_zero("XY")
return 1
# Front right inside corner
def probe_inside_xpym(self):
# move X- xy_clearance Y+ edge_length
s = """G91
G1 F%s X-%f Y%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance,self.data_side_edge_length )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xres = float(a[0]) + 0.5 * self.data_probe_diam
self.status_xp = xres
len_x = self.length_x()
# move X- edge_length Y+ xy_clearance
tmpxy=self.data_side_edge_length-self.data_xy_clearance
s = """G91
G1 F%s X-%f Y-%f
G90""" % (self.data_rapid_vel, tmpxy,tmpxy)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('yminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
yres = float(a[1]) - 0.5 * self.data_probe_diam
self.status_ym = yres
len_y = self.length_y()
self.add_history('Inside XPYM ', "XpLxYmLy", 0, 0, xres, len_x, yres, 0, 0, len_y, 0, 0, 0)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
# move to found point
s = "G1 F%s X%f Y%f" % (self.data_rapid_vel, xres,yres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
self.set_zero("XY")
return 1
# Back left inside corner
def probe_inside_xmyp(self):
# move X+ xy_clearance Y- edge_length
s = """G91
G1 F%s X%f Y-%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance,self.data_side_edge_length )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xres = float(a[0]) - 0.5 * self.data_probe_diam
self.status_xm = xres
len_x = self.length_x()
# move X+ edge_length Y- xy_clearance
tmpxy = self.data_side_edge_length - self.data_xy_clearance
s = """G91
G1 F%s X%f Y%f
G90""" % (self.data_rapid_vel, tmpxy,tmpxy)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('yplus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
yres = float(a[1]) + 0.5 * self.data_probe_diam
self.status_yp = yres
len_y = self.length_y()
self.add_history('Inside XMYP', "XmLxYpLy", xres, 0, 0, len_x, 0, 0, yres, len_y, 0, 0, 0)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
# move to found point
s = "G1 F%s X%f Y%f" % (self.data_rapid_vel, xres,yres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
self.set_zero("XY")
return 1
# Front left inside corner
def probe_inside_xmym(self):
# move Y+ edge_length X+ xy_clearance
s = """G91
G1 F%s X%f Y%f
G90""" % (self.data_rapid_vel, self.data_xy_clearance,self.data_side_edge_length )
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.z_clearance_down()
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('xminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show X result
a = STATUS.get_probed_position_with_offsets()
xres = float(a[0]) - 0.5 * self.data_probe_diam
self.status_xm = xres
len_x = self.length_x()
# move X+ edge_length Y- xy_clearance
tmpxy = self.data_side_edge_length - self.data_xy_clearance
s = """G91
G1 F%s X%f Y-%f
G90""" % (self.data_rapid_vel, tmpxy,tmpxy)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
rtn = self.probe('yminus')
if rtn != 1:
return 'failed: {}'.format(rtn)
# show Y result
a = STATUS.get_probed_position_with_offsets()
yres = float(a[1]) - 0.5 * self.data_probe_diam
self.status_ym = yres
len_y = self.length_y()
self.add_history('Inside XMYM', "XmLxYmLy", xres, 0, 0, len_x, yres, 0, 0, len_y, 0, 0, 0)
# move Z to start point
rtn = self.z_clearance_up()
if rtn != 1:
return 'failed: {}'.format(rtn)
# move to found point
s = "G1 F%s X%f Y%f" % (self.data_rapid_vel, xres,yres)
rtn = self.CALL_MDI_WAIT(s, self.timeout)
if rtn != 1:
return 'failed: {}'.format(rtn)
self.set_zero("XY")
return 1
#################
# Outside probing
#################
def probe_outside_xy_boss(self):