Added Gcode PReview

This commit is contained in:
Thomas Herrmann 2021-10-16 23:12:35 +02:00
parent 347e5a64c1
commit 71db9d2e4a

82
cnc.py
View File

@ -15,6 +15,14 @@ writebuffer = []
readbuffer = [] readbuffer = []
AXIS = 'X' AXIS = 'X'
states = {'M3':'0', 'M8':'0', 'M6':'0', 'G10': '0'} #Spindle, Coolant, Toolchange states = {'M3':'0', 'M8':'0', 'M6':'0', 'G10': '0'} #Spindle, Coolant, Toolchange
dict_GCODE = {'G':'0',
'X':'0',
'Y':'0',
'Z':'0',
'I':'0',
'J':'0',
'F':'0'
}
#GUI Main #GUI Main
buttonsize_x = 5 buttonsize_x = 5
@ -157,7 +165,7 @@ def infoScreen(data): #Anzeigecanvas für GRBL Rückmeldungen
i=10 i=10
terminal_recv.delete("all") terminal_recv.delete("all")
def openGCODE(): #Dialog zur Gcode AUswahl und öffnen der Datei als GCODE Objekt def openGCODE(): #Dialog zur Gcode Auswahl und öffnen der Datei als GCODE Objekt
global GCODE global GCODE
filetypes = (('GCODE', '*.nc'),('All files', '*.*')) filetypes = (('GCODE', '*.nc'),('All files', '*.*'))
@ -165,42 +173,50 @@ def openGCODE(): #Dialog zur Gcode AUswahl und öffnen der Datei als GCODE Objek
if GCODE != 0: if GCODE != 0:
fopen.config(bg= loaded) fopen.config(bg= loaded)
draw_GCODE(extract_GCODE())
else: else:
fopen.config(bg = 'grey') fopen.config(bg = 'grey')
build_xy = findEnvelope() #Aufruf PLatz im Bauraum
mill_table.create_rectangle(build_xy[0],build_xy[1], fill = 'blue', stipple = 'gray75') # Zeichnen des Objekts im Bauraum
def findEnvelope(): #get the max used Buildspace and position of the job #build_xy = findEnvelope() #Aufruf PLatz im Bauraum
x_coords = [] #mill_table.create_rectangle(build_xy[0],build_xy[1], fill = 'blue', stipple = 'gray75') # Zeichnen des Objekts im Bauraum
y_coords = []
coord_max = [0,1]
coord_min = [0,1]
def extract_GCODE(): #Aufschlüsseln der enthaltenen Koordinaten in ein per Schlüssel zugängiges Dictionary
global dict_GCODE
list_dict_GCODE = []
for line in GCODE: for line in GCODE:
l = line.strip(line) # Strip all EOL characters l = line.split() #Elemente trennen und in Liste konvertieren
l = line.replace('X', '') for i in range(0,len(l)):
l2 = l.replace('Y', '') #print (l)
l2 = l2.split() if 'G' in l[i]:
dict_GCODE['G'] = l[i].replace('G','') #Wert einfügen und gleichzeitig G CODE befehl entfernen
if 'X' in l[i]:
dict_GCODE['X'] = l[i].replace('X','')
if 'Y' in l[i]:
dict_GCODE['Y'] = l[i] .replace('Y','')
if 'Z' in l[i]:
dict_GCODE['Z'] = l[i].replace('Z','')
if 'I' in l[i] and not 'ZMIN':
dict_GCODE['I'] = l[i].replace('I','')
if 'J' in l[i]:
dict_GCODE['J'] = l[i].replace('J','')
if 'F' in l[i] and not 'Fusion':
dict_GCODE['F'] = l[i].replace('F','')
if len(l2) == 3: #print(dict_GCODE)
#print(l2) list_dict_GCODE.append(dict_GCODE.copy()) #Copy notwendig da es sich nur um einen "Pointer" handelt der immer auf die zuletzt aktualisierte dict Zeile zeigt.
x = l2[0] print(list_dict_GCODE)
if 'Z' not in x and 'X' in line and 'G0' not in x and 'G1' not in x:
x_coords.append(float(x))
y = l2[1]
if 'Z' not in y and 'Y' in line and 'G0' not in x and 'G1' not in x:
y_coords.append(float(y))
x_coords.sort() return list_dict_GCODE
y_coords.sort()
coord_max[0] = max(x_coords) +50 def draw_GCODE(glist): #Zeichnen des GCodes zur Beurteilung des Bauraums
coord_max[1] = 350 - max(y_coords) #invertierte Buildplattform mit 0 unten links statt oben links
coord_min[0] = min(x_coords) +50
coord_min[1] = 350 - min(y_coords)
return coord_min, coord_max for i in range(0,len(glist)-1):
x_y_current = 50 + float(glist[i]['X']), 350 - float(glist[i]['Y'])
x_y_next = 50 + float(glist[i+1]['X']), 350 - float(glist[i+1]['Y'])
mill_table.create_line(x_y_current, x_y_next)
def grblWrite(): def grblWrite():
#print("write1") #print("write1")
@ -211,17 +227,16 @@ def grblWrite():
for line in GCODE: for line in GCODE:
#print("write") #print("write")
l = line.strip() # Strip all EOL characters for streaming l = line.strip() # Strip all EOL characters for streaming
grbl_command = l grbl_command = l
#print("GCODE",grbl_command) #print("GCODE",grbl_command)
bufferGRBL(grbl_command + '\n') bufferGRBL(grbl_command + '\n')
sendGRBL() sendGRBL()
GCODE.close() GCODE.close()
for button in blkbuttons: for button in blkbuttons: #Ausgrauen blockierter Knöpfe während Fräsen. "Umschalter"
switchButtonState(button) switchButtonState(button)
fopen.config(bg = 'grey') fopen.config(bg = 'grey')
def timedPositionRequest(): def timedPositionRequest():# >Im Falle das kein GCODE gestremed wird< Abfragen der Momentanen Position nach 1000ms sendet über den "byPass" channel der den GCode Stream nicht beeinflusst
if grbl != 0 and freetosend == 1: if grbl != 0 and freetosend == 1:
grbl_command = '?' grbl_command = '?'
byPass(grbl_command) byPass(grbl_command)
@ -301,6 +316,8 @@ def displayPosition_request(grbl_pos):
show_ctrl_y.config(text = coordinates_list[2]) show_ctrl_y.config(text = coordinates_list[2])
show_ctrl_z.config(text = coordinates_list[3]) show_ctrl_z.config(text = coordinates_list[3])
mill_table.create_line(coordinates_list[1],coordinates_list[2],coordinates_list[1],coordinates_list[2]+50, arrow = FIRST )
#show_ctrl_x_w.config(text = coordinates_list[4]) #show_ctrl_x_w.config(text = coordinates_list[4])
#show_ctrl_y_w.config(text = coordinates_list[5]) #show_ctrl_y_w.config(text = coordinates_list[5])
#show_ctrl_z_w.config(text = coordinates_list[6]) #show_ctrl_z_w.config(text = coordinates_list[6])
@ -334,6 +351,9 @@ def displayPosition():
show_ctrl_y.config(text = coordinates_list[2]) show_ctrl_y.config(text = coordinates_list[2])
show_ctrl_z.config(text = coordinates_list[3]) show_ctrl_z.config(text = coordinates_list[3])
mill_table.create_line(coordinates_list[1],coordinates_list[2],coordinates_list[1]+10,coordinates_list[2]+20 )
mill_table.create_line(coordinates_list[1],coordinates_list[2],coordinates_list[1]-10,coordinates_list[2]+20 )
mill_table.create_line(coordinates_list[1]-10,coordinates_list[2]+20,coordinates_list[1]+10,coordinates_list[2]+20 )
#show_ctrl_x_w.config(text = coordinates_list[4]) #show_ctrl_x_w.config(text = coordinates_list[4])
#show_ctrl_y_w.config(text = coordinates_list[5]) #show_ctrl_y_w.config(text = coordinates_list[5])
#show_ctrl_z_w.config(text = coordinates_list[6]) #show_ctrl_z_w.config(text = coordinates_list[6])
@ -425,8 +445,6 @@ show_ctrl_x_w =Label(root, text = "X_POS_W", width = 8, height = 2, bg ='white',
show_ctrl_y_w =Label(root, text = "Y_POS_W", width = 8, height = 2, bg ='white', relief = SUNKEN, fg= 'black') show_ctrl_y_w =Label(root, text = "Y_POS_W", width = 8, height = 2, bg ='white', relief = SUNKEN, fg= 'black')
show_ctrl_z_w =Label(root, text = "Z_POS_W", width = 8, height = 2, bg ='white', relief = SUNKEN, fg= 'black') show_ctrl_z_w =Label(root, text = "Z_POS_W", width = 8, height = 2, bg ='white', relief = SUNKEN, fg= 'black')
#feed_control = Scale(root, orient = HORIZONTAL, length = 400, label = "Feedrate",tickinterval = 20) #feed_control = Scale(root, orient = HORIZONTAL, length = 400, label = "Feedrate",tickinterval = 20)
#Milling Area and Gcode preview with grid generation #Milling Area and Gcode preview with grid generation