forked from vlachoudis/bCNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProbePage.py
1657 lines (1451 loc) · 55.4 KB
/
ProbePage.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
# -*- coding: ascii -*-
# $Id$
#
# Author: [email protected]
# Date: 18-Jun-2015
__author__ = "Vasilis Vlachoudis"
__email__ = "[email protected]"
import sys
import time
import math
try:
from Tkinter import *
import tkMessageBox
except ImportError:
from tkinter import *
import tkinter.messagebox as tkMessageBox
from CNC import WCS,CNC
import Utils
import Camera
import Ribbon
import tkExtra
import CNCRibbon
PROBE_CMD = [ _("G38.2 stop on contact else error"),
_("G38.3 stop on contact"),
_("G38.4 stop on loss contact else error"),
_("G38.5 stop on loss contact")
]
TOOL_POLICY = [ _("Send M6 commands"), # 0
_("Ignore M6 commands"), # 1
_("Manual Tool Change (WCS)"), # 2
_("Manual Tool Change (TLO)"), # 3
_("Manual Tool Change (NoProbe)")# 4
]
TOOL_WAIT = [ _("ONLY before probing"),
_("BEFORE & AFTER probing")
]
CAMERA_LOCATION = { "Gantry" : NONE,
"Top-Left" : NW,
"Top" : N,
"Top-Right" : NE,
"Left" : W,
"Center" : CENTER,
"Right" : E,
"Bottom-Left" : SW,
"Bottom" : S,
"Bottom-Right" : SE,
}
CAMERA_LOCATION_ORDER = [
"Gantry",
"Top-Left",
"Top",
"Top-Right",
"Left",
"Center",
"Right",
"Bottom-Left",
"Bottom",
"Bottom-Right"]
#===============================================================================
# Probe Tab Group
#===============================================================================
class ProbeTabGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, N_("Probe"), app)
self.tab = StringVar()
# ---
col,row=0,0
b = Ribbon.LabelRadiobutton(self.frame,
image=Utils.icons["probe32"],
text=_("Probe"),
compound=TOP,
variable=self.tab,
value="Probe",
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=5, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Simple probing along a direction"))
# ---
col += 1
b = Ribbon.LabelRadiobutton(self.frame,
image=Utils.icons["level32"],
text=_("Autolevel"),
compound=TOP,
variable=self.tab,
value="Autolevel",
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=5, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Autolevel Z surface"))
# ---
col += 1
b = Ribbon.LabelRadiobutton(self.frame,
image=Utils.icons["camera32"],
text=_("Camera"),
compound=TOP,
variable=self.tab,
value="Camera",
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=5, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Work surface camera view and alignment"))
if Camera.cv is None: b.config(state=DISABLED)
# ---
col += 1
b = Ribbon.LabelRadiobutton(self.frame,
image=Utils.icons["endmill32"],
text=_("Tool"),
compound=TOP,
variable=self.tab,
value="Tool",
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=5, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Setup probing for manual tool change"))
self.frame.grid_rowconfigure(0, weight=1)
#===============================================================================
# Autolevel Group
#===============================================================================
class AutolevelGroup(CNCRibbon.ButtonGroup):
def __init__(self, master, app):
CNCRibbon.ButtonGroup.__init__(self, master, "Probe:Autolevel", app)
self.label["background"] = Ribbon._BACKGROUND_GROUP2
self.grid3rows()
# ---
col,row=0,0
b = Ribbon.LabelButton(self.frame, self, "<<AutolevelMargins>>",
image=Utils.icons["margins"],
text=_("Margins"),
compound=LEFT,
anchor=W,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Get margins from gcode file"))
self.addWidget(b)
# ---
row += 1
b = Ribbon.LabelButton(self.frame, self, "<<AutolevelZero>>",
image=Utils.icons["origin"],
text=_("Zero"),
compound=LEFT,
anchor=W,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Set current location as Z-zero for leveling"))
self.addWidget(b)
# ---
row += 1
b = Ribbon.LabelButton(self.frame, self, "<<AutolevelClear>>",
image=Utils.icons["clear"],
text=_("Clear"),
compound=LEFT,
anchor=W,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, padx=0, pady=0, sticky=NSEW)
tkExtra.Balloon.set(b, _("Clear probe data"))
self.addWidget(b)
# ---
col,row=1,0
b = Ribbon.LabelButton(self.frame, self, "<<AutolevelScan>>",
image=Utils.icons["gear32"],
text=_("Scan"),
compound=TOP,
justify=CENTER,
width=48,
background=Ribbon._BACKGROUND)
b.grid(row=row, column=col, rowspan=3, padx=0, pady=0, sticky=NSEW)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Scan probed area for level information on Z plane"))
#===============================================================================
# Probe Common Offset
#===============================================================================
class ProbeCommonFrame(CNCRibbon.PageFrame):
probeFeed = None
tlo = None
probeCmd = None
def __init__(self, master, app):
CNCRibbon.PageFrame.__init__(self, master, "ProbeCommon", app)
lframe = tkExtra.ExLabelFrame(self, text=_("Common"), foreground="DarkBlue")
lframe.pack(side=TOP, fill=X)
frame = lframe.frame
# ----
row = 0
col = 0
Label(frame, text=_("Probe Feed:")).grid(row=row, column=col, sticky=E)
col += 1
ProbeCommonFrame.probeFeed = tkExtra.FloatEntry(frame, background="White", width=5)
ProbeCommonFrame.probeFeed.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(ProbeCommonFrame.probeFeed, _("Set probe feed rate"))
self.addWidget(ProbeCommonFrame.probeFeed)
# ----
# Tool offset
row += 1
col = 0
Label(frame, text=_("TLO")).grid(row=row, column=col, sticky=E)
col += 1
ProbeCommonFrame.tlo = tkExtra.FloatEntry(frame, background="White")
ProbeCommonFrame.tlo.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(ProbeCommonFrame.tlo, _("Set tool offset for probing"))
self.addWidget(ProbeCommonFrame.tlo)
self.tlo.bind("<Return>", self.tloSet)
self.tlo.bind("<KP_Enter>", self.tloSet)
col += 1
b = Button(frame, text=_("set"),
command=self.tloSet,
padx=2, pady=1)
b.grid(row=row, column=col, sticky=EW)
self.addWidget(b)
# ---
# feed command
row += 1
col = 0
Label(frame, text=_("Probe Command")).grid(row=row, column=col, sticky=E)
col += 1
ProbeCommonFrame.probeCmd = tkExtra.Combobox(frame, True,
background="White",
width=16)
ProbeCommonFrame.probeCmd.grid(row=row, column=col, sticky=EW)
ProbeCommonFrame.probeCmd.fill(PROBE_CMD)
self.addWidget(ProbeCommonFrame.probeCmd)
frame.grid_columnconfigure(1,weight=1)
self.loadConfig()
#------------------------------------------------------------------------
def tloSet(self, event=None):
try:
CNC.vars["TLO"] = float(ProbeCommonFrame.tlo.get())
cmd = "G43.1Z"+str(ProbeCommonFrame.tlo.get())
self.sendGCode(cmd+"\n")
except:
pass
#------------------------------------------------------------------------
@staticmethod
def probeUpdate():
try:
CNC.vars["prbfeed"] = float(ProbeCommonFrame.probeFeed.get())
CNC.vars["prbcmd"] = str(ProbeCommonFrame.probeCmd.get().split()[0])
return False
except:
return True
#------------------------------------------------------------------------
def updateTlo(self):
try:
if self.focus_get() is not ProbeCommonFrame.tlo:
state = ProbeCommonFrame.tlo.cget("state")
state = ProbeCommonFrame.tlo["state"] = NORMAL
ProbeCommonFrame.tlo.set(str(CNC.vars.get("TLO","")))
state = ProbeCommonFrame.tlo["state"] = state
except:
pass
#-----------------------------------------------------------------------
def saveConfig(self):
Utils.setFloat("Probe", "feed", ProbeCommonFrame.probeFeed.get())
Utils.setFloat("Probe", "tlo", ProbeCommonFrame.tlo.get())
Utils.setFloat("Probe", "cmd", ProbeCommonFrame.probeCmd.get().split()[0])
#-----------------------------------------------------------------------
def loadConfig(self):
ProbeCommonFrame.probeFeed.set(Utils.getFloat("Probe","feed"))
ProbeCommonFrame.tlo.set( Utils.getFloat("Probe","tlo"))
cmd = Utils.getStr("Probe","cmd")
for p in PROBE_CMD:
if p.split()[0] == cmd:
ProbeCommonFrame.probeCmd.set(p)
break
#===============================================================================
# Probe Frame
#===============================================================================
class ProbeFrame(CNCRibbon.PageFrame):
def __init__(self, master, app):
CNCRibbon.PageFrame.__init__(self, master, "Probe:Probe", app)
#----------------------------------------------------------------
# Single probe
#----------------------------------------------------------------
lframe = tkExtra.ExLabelFrame(self, text=_("Probe"), foreground="DarkBlue")
lframe.pack(side=TOP, fill=X)
row,col = 0,0
Label(lframe(), text=_("Probe:")).grid(row=row, column=col, sticky=E)
col += 1
self._probeX = Label(lframe(), foreground="DarkBlue", background="gray90")
self._probeX.grid(row=row, column=col, padx=1, sticky=EW+S)
col += 1
self._probeY = Label(lframe(), foreground="DarkBlue", background="gray90")
self._probeY.grid(row=row, column=col, padx=1, sticky=EW+S)
col += 1
self._probeZ = Label(lframe(), foreground="DarkBlue", background="gray90")
self._probeZ.grid(row=row, column=col, padx=1, sticky=EW+S)
# ---
col += 1
b = Button(lframe(), #"<<Probe>>",
image=Utils.icons["probe32"],
text=_("Probe"),
compound=TOP,
command=self.probe,
width=48,
padx=5, pady=0)
b.grid(row=row, column=col, rowspan=2, padx=1, sticky=EW+S)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Perform a single probe cycle"))
# ---
row,col = row+1,0
Label(lframe(), text=_("Pos:")).grid(row=row, column=col, sticky=E)
col += 1
self.probeXdir = tkExtra.FloatEntry(lframe(), background="White")
self.probeXdir.grid(row=row, column=col, sticky=EW+S)
tkExtra.Balloon.set(self.probeXdir, _("Probe along X direction"))
self.addWidget(self.probeXdir)
col += 1
self.probeYdir = tkExtra.FloatEntry(lframe(), background="White")
self.probeYdir.grid(row=row, column=col, sticky=EW+S)
tkExtra.Balloon.set(self.probeYdir, _("Probe along Y direction"))
self.addWidget(self.probeYdir)
col += 1
self.probeZdir = tkExtra.FloatEntry(lframe(), background="White")
self.probeZdir.grid(row=row, column=col, sticky=EW+S)
tkExtra.Balloon.set(self.probeZdir, _("Probe along Z direction"))
self.addWidget(self.probeZdir)
lframe().grid_columnconfigure(1,weight=1)
lframe().grid_columnconfigure(2,weight=1)
lframe().grid_columnconfigure(3,weight=1)
#----------------------------------------------------------------
# Center probing
#----------------------------------------------------------------
lframe = tkExtra.ExLabelFrame(self, text=_("Center"), foreground="DarkBlue")
lframe.pack(side=TOP, expand=YES, fill=X)
Label(lframe(), text=_("Diameter:")).pack(side=LEFT)
self.diameter = tkExtra.FloatEntry(lframe(), background="White")
self.diameter.pack(side=LEFT, expand=YES, fill=X)
tkExtra.Balloon.set(self.diameter, _("Probing ring internal diameter"))
self.addWidget(self.diameter)
# ---
b = Button(lframe(),
image=Utils.icons["target32"],
text=_("Center"),
compound=TOP,
command=self.probeCenter,
width=48,
padx=5, pady=0)
b.pack(side=RIGHT)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Center probing using a ring"))
#----------------------------------------------------------------
# Align / Orient / Square ?
#----------------------------------------------------------------
lframe = tkExtra.ExLabelFrame(self, text=_("Orient"), foreground="DarkBlue")
lframe.pack(side=TOP, expand=YES, fill=X)
# ---
row, col = 0,0
Label(lframe(), text=_("Markers:")).grid(row=row, column=col, sticky=E)
col += 1
self.scale_orient = Scale(lframe(),
from_=0, to_=0,
orient=HORIZONTAL,
showvalue=1,
state=DISABLED,
command=self.changeMarker)
self.scale_orient.grid(row=row, column=col, columnspan=2, sticky=EW)
tkExtra.Balloon.set(self.scale_orient, _("Select orientation marker"))
# Add new point
col += 2
b = Button(lframe(), text=_("Add"),
image=Utils.icons["add"],
compound=LEFT,
command=lambda s=self: s.event_generate("<<AddMarker>>"),
padx = 1,
pady = 1)
b.grid(row=row, column=col, sticky=NSEW)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Add an orientation marker. " \
"Jog first the machine to the marker position " \
"and then click on canvas to add the marker."))
# ----
row += 1
col = 0
Label(lframe(), text=_("Gcode:")).grid(row=row, column=col, sticky=E)
col += 1
self.x_orient = tkExtra.FloatEntry(lframe(), background="White")
self.x_orient.grid(row=row, column=col, sticky=EW)
self.x_orient.bind("<FocusOut>", self.orientUpdate)
self.x_orient.bind("<Return>", self.orientUpdate)
self.x_orient.bind("<KP_Enter>", self.orientUpdate)
tkExtra.Balloon.set(self.x_orient, _("GCode X coordinate of orientation point"))
col += 1
self.y_orient = tkExtra.FloatEntry(lframe(), background="White")
self.y_orient.grid(row=row, column=col, sticky=EW)
self.y_orient.bind("<FocusOut>", self.orientUpdate)
self.y_orient.bind("<Return>", self.orientUpdate)
self.y_orient.bind("<KP_Enter>", self.orientUpdate)
tkExtra.Balloon.set(self.y_orient, _("GCode Y coordinate of orientation point"))
# Buttons
col += 1
b = Button(lframe(), text=_("Delete"),
image=Utils.icons["x"],
compound=LEFT,
command = self.orientDelete,
padx = 1,
pady = 1)
b.grid(row=row, column=col, sticky=EW)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Delete current marker"))
# ---
row += 1
col = 0
Label(lframe(), text="WPos:").grid(row=row, column=col, sticky=E)
col += 1
self.xm_orient = tkExtra.FloatEntry(lframe(), background="White")
self.xm_orient.grid(row=row, column=col, sticky=EW)
self.xm_orient.bind("<FocusOut>", self.orientUpdate)
self.xm_orient.bind("<Return>", self.orientUpdate)
self.xm_orient.bind("<KP_Enter>", self.orientUpdate)
tkExtra.Balloon.set(self.xm_orient, _("Machine X coordinate of orientation point"))
col += 1
self.ym_orient = tkExtra.FloatEntry(lframe(), background="White")
self.ym_orient.grid(row=row, column=col, sticky=EW)
self.ym_orient.bind("<FocusOut>", self.orientUpdate)
self.ym_orient.bind("<Return>", self.orientUpdate)
self.ym_orient.bind("<KP_Enter>", self.orientUpdate)
tkExtra.Balloon.set(self.ym_orient, _("Machine Y coordinate of orientation point"))
# Buttons
col += 1
b = Button(lframe(), text=_("Clear"),
image=Utils.icons["clear"],
compound=LEFT,
command = self.orientClear,
padx = 1,
pady = 1)
b.grid(row=row, column=col, sticky=EW)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Delete all markers"))
# ---
row += 1
col = 0
Label(lframe(), text=_("Angle:")).grid(row=row, column=col, sticky=E)
col += 1
self.angle_orient = Label(lframe(), foreground="DarkBlue", background="gray90", anchor=W)
self.angle_orient.grid(row=row, column=col, columnspan=2, sticky=EW, padx=1, pady=1)
# Buttons
col += 2
b = Button(lframe(), text=_("Orient"),
image=Utils.icons["setsquare32"],
compound=TOP,
command = lambda a=app:a.insertCommand("ORIENT",True),
padx = 1,
pady = 1)
b.grid(row=row, rowspan=3, column=col, sticky=EW)
self.addWidget(b)
tkExtra.Balloon.set(b, _("Align GCode with the machine markers"))
# ---
row += 1
col = 0
Label(lframe(), text=_("Offset:")).grid(row=row, column=col, sticky=E)
col += 1
self.xo_orient = Label(lframe(), foreground="DarkBlue", background="gray90", anchor=W)
self.xo_orient.grid(row=row, column=col, sticky=EW, padx=1)
col += 1
self.yo_orient = Label(lframe(), foreground="DarkBlue", background="gray90", anchor=W)
self.yo_orient.grid(row=row, column=col, sticky=EW, padx=1)
# ---
row += 1
col = 0
Label(lframe(), text=_("Error:")).grid(row=row, column=col, sticky=E)
col += 1
self.err_orient = Label(lframe(), foreground="DarkBlue", background="gray90", anchor=W)
self.err_orient.grid(row=row, column=col, columnspan=2, sticky=EW, padx=1, pady=1)
lframe().grid_columnconfigure(1, weight=1)
lframe().grid_columnconfigure(2, weight=1)
#----------------------------------------------------------------
self.warn = True
self.loadConfig()
#-----------------------------------------------------------------------
def loadConfig(self):
self.probeXdir.set(Utils.getStr("Probe","x"))
self.probeYdir.set(Utils.getStr("Probe","y"))
self.probeZdir.set(Utils.getStr("Probe","z"))
self.diameter.set(Utils.getStr("Probe", "center"))
self.warn = Utils.getBool("Warning","probe",self.warn)
#-----------------------------------------------------------------------
def saveConfig(self):
Utils.setFloat("Probe", "x", self.probeXdir.get())
Utils.setFloat("Probe", "y", self.probeYdir.get())
Utils.setFloat("Probe", "z", self.probeZdir.get())
Utils.setFloat("Probe", "center", self.diameter.get())
Utils.setBool("Warning", "probe", self.warn)
#-----------------------------------------------------------------------
def updateProbe(self):
try:
self._probeX["text"] = CNC.vars.get("prbx")
self._probeY["text"] = CNC.vars.get("prby")
self._probeZ["text"] = CNC.vars.get("prbz")
except:
pass
#-----------------------------------------------------------------------
def warnMessage(self):
if self.warn:
ans = tkMessageBox.askquestion(_("Probe connected?"),
_("Please verify that the probe is connected.\n\nShow this message again?"),
icon='warning',
parent=self.winfo_toplevel())
if ans != YES:
self.warn = False
#-----------------------------------------------------------------------
# Probe one Point
#-----------------------------------------------------------------------
def probe(self, event=None):
if ProbeCommonFrame.probeUpdate():
tkMessageBox.showerror(_("Probe Error"),
_("Invalid probe feed rate"),
parent=self.winfo_toplevel())
return
self.warnMessage()
cmd = str(CNC.vars["prbcmd"])
ok = False
v = self.probeXdir.get()
if v != "":
cmd += "X"+str(v)
ok = True
v = self.probeYdir.get()
if v != "":
cmd += "Y"+str(v)
ok = True
v = self.probeZdir.get()
if v != "":
cmd += "Z"+str(v)
ok = True
v = ProbeCommonFrame.probeFeed.get()
if v != "":
cmd += "F"+str(v)
if ok:
self.sendGCode(cmd+"\n")
else:
tkMessageBox.showerror(_("Probe Error"),
_("At least one probe direction should be specified"))
#-----------------------------------------------------------------------
# Probe Center
#-----------------------------------------------------------------------
def probeCenter(self, event=None):
self.warnMessage()
cmd = "G91 %s F%s"%(CNC.vars["prbcmd"], CNC.vars["prbfeed"])
try:
diameter = abs(float(self.diameter.get()))
except:
diameter = 0.0
if diameter < 0.001:
tkMessageBox.showerror(_("Probe Center Error"),
_("Invalid diameter entered"),
parent=self.winfo_toplevel())
return
lines = []
lines.append("%s x-%s"%(cmd,diameter))
lines.append("%wait")
lines.append("tmp=prbx")
lines.append("%s x%s"%(cmd,diameter))
lines.append("%wait")
lines.append("g53 g0 x[0.5*(tmp+prbx)]")
lines.append("%s y-%s"%(cmd,diameter))
lines.append("%wait")
lines.append("tmp=prby")
lines.append("%s y%s"%(cmd,diameter))
lines.append("%wait")
lines.append("g53 g0 y[0.5*(tmp+prby)]")
lines.append("g90")
self.app.run(lines=lines)
#-----------------------------------------------------------------------
# Solve the system and update fields
#-----------------------------------------------------------------------
def orientSolve(self, event=None):
try:
phi, xo, yo = self.app.gcode.orient.solve()
self.angle_orient["text"]="%*f"%(CNC.digits, math.degrees(phi))
self.xo_orient["text"]="%*f"%(CNC.digits, xo)
self.yo_orient["text"]="%*f"%(CNC.digits, yo)
minerr, meanerr, maxerr = self.app.gcode.orient.error()
self.err_orient["text"] = "Avg:%*f Max:%*f Min:%*f"%\
(CNC.digits, meanerr, CNC.digits, maxerr, CNC.digits, minerr)
except:
self.angle_orient["text"] = sys.exc_info()[1]
self.xo_orient["text"] = ""
self.yo_orient["text"] = ""
self.err_orient["text"] = ""
#-----------------------------------------------------------------------
# Delete current orientation point
#-----------------------------------------------------------------------
def orientDelete(self, event=None):
marker = self.scale_orient.get()-1
if marker<0 or marker >= len(self.app.gcode.orient): return
self.app.gcode.orient.clear(marker)
self.orientUpdateScale()
self.changeMarker(marker+1)
self.orientSolve()
self.event_generate("<<DrawOrient>>")
#-----------------------------------------------------------------------
# Clear all markers
#-----------------------------------------------------------------------
def orientClear(self, event=None):
if self.scale_orient.cget("to") == 0: return
ans = tkMessageBox.askquestion(_("Delete all markers"),
_("Do you want to delete all orientation markers?"),
parent=self.winfo_toplevel())
if ans!=tkMessageBox.YES: return
self.app.gcode.orient.clear()
self.orientUpdateScale()
self.event_generate("<<DrawOrient>>")
#-----------------------------------------------------------------------
# Update orientation scale
#-----------------------------------------------------------------------
def orientUpdateScale(self):
n = len(self.app.gcode.orient)
if n:
self.scale_orient.config(state=NORMAL, from_=1, to_=n)
else:
self.scale_orient.config(state=DISABLED, from_=0, to_=0)
#-----------------------------------------------------------------------
def orientClearFields(self):
self.x_orient.delete(0,END)
self.y_orient.delete(0,END)
self.xm_orient.delete(0,END)
self.ym_orient.delete(0,END)
self.angle_orient["text"] = ""
self.xo_orient["text"] = ""
self.yo_orient["text"] = ""
self.err_orient["text"] = ""
#-----------------------------------------------------------------------
# Update orient with the current marker
#-----------------------------------------------------------------------
def orientUpdate(self, event=None):
marker = self.scale_orient.get()-1
if marker<0 or marker >= len(self.app.gcode.orient):
self.orientClearFields()
return
xm,ym,x,y = self.app.gcode.orient[marker]
try: x = float(self.x_orient.get())
except: pass
try: y = float(self.y_orient.get())
except: pass
try: xm = float(self.xm_orient.get())
except: pass
try: ym = float(self.ym_orient.get())
except: pass
self.app.gcode.orient.markers[marker] = xm,ym,x,y
self.orientUpdateScale()
self.changeMarker(marker+1)
self.orientSolve()
self.event_generate("<<DrawOrient>>")
#-----------------------------------------------------------------------
# The index will be +1 to appear more human starting from 1
#-----------------------------------------------------------------------
def changeMarker(self, marker):
marker = int(marker)-1
if marker<0 or marker >= len(self.app.gcode.orient):
self.orientClearFields()
self.event_generate("<<OrientChange>>", data=-1)
return
xm,ym,x,y = self.app.gcode.orient[marker]
d = CNC.digits
self.x_orient.set("%*f"%(d,x))
self.y_orient.set("%*f"%(d,y))
self.xm_orient.set("%*f"%(d,xm))
self.ym_orient.set("%*f"%(d,ym))
self.orientSolve()
self.event_generate("<<OrientChange>>", data=marker)
#-----------------------------------------------------------------------
# Select marker
#-----------------------------------------------------------------------
def selectMarker(self, marker):
self.orientUpdateScale()
self.scale_orient.set(marker+1)
#===============================================================================
# Autolevel Frame
#===============================================================================
class AutolevelFrame(CNCRibbon.PageFrame):
def __init__(self, master, app):
CNCRibbon.PageFrame.__init__(self, master, "Probe:Autolevel", app)
lframe = LabelFrame(self, text=_("Autolevel"), foreground="DarkBlue")
lframe.pack(side=TOP, fill=X)
row,col = 0,0
# Empty
col += 1
Label(lframe, text=_("Min")).grid(row=row, column=col, sticky=EW)
col += 1
Label(lframe, text=_("Max")).grid(row=row, column=col, sticky=EW)
col += 1
Label(lframe, text=_("Step")).grid(row=row, column=col, sticky=EW)
col += 1
Label(lframe, text="N").grid(row=row, column=col, sticky=EW)
# --- X ---
row += 1
col = 0
Label(lframe, text="X:").grid(row=row, column=col, sticky=E)
col += 1
self.probeXmin = tkExtra.FloatEntry(lframe, background="White", width=5)
self.probeXmin.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeXmin, _("X minimum"))
self.addWidget(self.probeXmin)
col += 1
self.probeXmax = tkExtra.FloatEntry(lframe, background="White", width=5)
self.probeXmax.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeXmax, _("X maximum"))
self.addWidget(self.probeXmax)
col += 1
self.probeXstep = Label(lframe, foreground="DarkBlue",
background="gray90", width=5)
self.probeXstep.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeXstep, _("X step"))
col += 1
self.probeXbins = Spinbox(lframe,
from_=2, to_=1000,
command=self.draw,
background="White",
width=3)
self.probeXbins.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeXbins, _("X bins"))
self.addWidget(self.probeXbins)
# --- Y ---
row += 1
col = 0
Label(lframe, text="Y:").grid(row=row, column=col, sticky=E)
col += 1
self.probeYmin = tkExtra.FloatEntry(lframe, background="White", width=5)
self.probeYmin.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeYmin, _("Y minimum"))
self.addWidget(self.probeYmin)
col += 1
self.probeYmax = tkExtra.FloatEntry(lframe, background="White", width=5)
self.probeYmax.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeYmax, _("Y maximum"))
self.addWidget(self.probeYmax)
col += 1
self.probeYstep = Label(lframe, foreground="DarkBlue",
background="gray90", width=5)
self.probeYstep.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeYstep, _("Y step"))
col += 1
self.probeYbins = Spinbox(lframe,
from_=2, to_=1000,
command=self.draw,
background="White",
width=3)
self.probeYbins.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeYbins, _("Y bins"))
self.addWidget(self.probeYbins)
# Max Z
row += 1
col = 0
Label(lframe, text="Z:").grid(row=row, column=col, sticky=E)
col += 1
self.probeZmin = tkExtra.FloatEntry(lframe, background="White", width=5)
self.probeZmin.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeZmin, _("Z Minimum depth to scan"))
self.addWidget(self.probeZmin)
col += 1
self.probeZmax = tkExtra.FloatEntry(lframe, background="White", width=5)
self.probeZmax.grid(row=row, column=col, sticky=EW)
tkExtra.Balloon.set(self.probeZmax, _("Z safe to move"))
self.addWidget(self.probeZmax)
lframe.grid_columnconfigure(1,weight=2)
lframe.grid_columnconfigure(2,weight=2)
lframe.grid_columnconfigure(3,weight=1)
self.loadConfig()
#-----------------------------------------------------------------------
def setValues(self):
probe = self.app.gcode.probe
self.probeXmin.set(str(probe.xmin))
self.probeXmax.set(str(probe.xmax))
self.probeXbins.delete(0,END)
self.probeXbins.insert(0,probe.xn)
self.probeXstep["text"] = str(probe.xstep())
self.probeYmin.set(str(probe.ymin))
self.probeYmax.set(str(probe.ymax))
self.probeYbins.delete(0,END)
self.probeYbins.insert(0,probe.yn)
self.probeYstep["text"] = str(probe.ystep())
self.probeZmin.set(str(probe.zmin))
self.probeZmax.set(str(probe.zmax))
#-----------------------------------------------------------------------
def saveConfig(self):
Utils.setFloat("Probe", "xmin", self.probeXmin.get())
Utils.setFloat("Probe", "xmax", self.probeXmax.get())
Utils.setInt( "Probe", "xn", self.probeXbins.get())
Utils.setFloat("Probe", "ymin", self.probeYmin.get())
Utils.setFloat("Probe", "ymax", self.probeYmax.get())
Utils.setInt( "Probe", "yn", self.probeYbins.get())
Utils.setFloat("Probe", "zmin", self.probeZmin.get())
Utils.setFloat("Probe", "zmax", self.probeZmax.get())
#-----------------------------------------------------------------------
def loadConfig(self):
self.probeXmin.set(Utils.getFloat("Probe","xmin"))
self.probeXmax.set(Utils.getFloat("Probe","xmax"))
self.probeYmin.set(Utils.getFloat("Probe","ymin"))
self.probeYmax.set(Utils.getFloat("Probe","ymax"))
self.probeZmin.set(Utils.getFloat("Probe","zmin"))
self.probeZmax.set(Utils.getFloat("Probe","zmax"))
self.probeXbins.delete(0,END)
self.probeXbins.insert(0,max(2,Utils.getInt("Probe","xn",5)))
self.probeYbins.delete(0,END)
self.probeYbins.insert(0,max(2,Utils.getInt("Probe","yn",5)))
self.change(False)
#-----------------------------------------------------------------------
def getMargins(self, event=None):
self.probeXmin.set(str(CNC.vars["xmin"]))
self.probeXmax.set(str(CNC.vars["xmax"]))
self.probeYmin.set(str(CNC.vars["ymin"]))
self.probeYmax.set(str(CNC.vars["ymax"]))
self.draw()
#-----------------------------------------------------------------------
def change(self, verbose=True):
probe = self.app.gcode.probe
error = False
try:
probe.xmin = float(self.probeXmin.get())
probe.xmax = float(self.probeXmax.get())
probe.xn = max(2,int(self.probeXbins.get()))
self.probeXstep["text"] = "%.5g"%(probe.xstep())
except ValueError:
self.probeXstep["text"] = ""
if verbose:
tkMessageBox.showerror(_("Probe Error"),
_("Invalid X probing region"),
parent=self.winfo_toplevel())
error = True
try:
probe.ymin = float(self.probeYmin.get())
probe.ymax = float(self.probeYmax.get())
probe.yn = max(2,int(self.probeYbins.get()))
self.probeYstep["text"] = "%.5g"%(probe.ystep())
except ValueError:
self.probeYstep["text"] = ""
if verbose:
tkMessageBox.showerror(_("Probe Error"),
_("Invalid Y probing region"),
parent=self.winfo_toplevel())
error = True
try:
probe.zmin = float(self.probeZmin.get())
probe.zmax = float(self.probeZmax.get())
except ValueError:
if verbose:
tkMessageBox.showerror(_("Probe Error"),
_("Invalid Z probing region"),
parent=self.winfo_toplevel())
error = True
if ProbeCommonFrame.probeUpdate():
if verbose:
tkMessageBox.showerror(_("Probe Error"),
_("Invalid probe feed rate"),
parent=self.winfo_toplevel())
error = True
return error
#-----------------------------------------------------------------------
def draw(self):
if not self.change():
self.event_generate("<<DrawProbe>>")
#-----------------------------------------------------------------------
def setZero(self, event=None):
x = CNC.vars["wx"]
y = CNC.vars["wy"]
self.app.gcode.probe.setZero(x,y)
self.draw()
#-----------------------------------------------------------------------
def clear(self, event=None):
ans = tkMessageBox.askquestion(_("Delete autolevel information"),
_("Do you want to delete all autolevel in formation?"),
parent=self.winfo_toplevel())
if ans!=tkMessageBox.YES: return
self.app.gcode.probe.clear()
self.draw()
#-----------------------------------------------------------------------
# Probe an X-Y area
#-----------------------------------------------------------------------
def scan(self, event=None):
if self.change(): return
self.event_generate("<<DrawProbe>>")
# absolute
self.app.run(lines=self.app.gcode.probe.scan())
#===============================================================================
# Camera Group
#===============================================================================
class CameraGroup(CNCRibbon.ButtonGroup):