mirror of
https://github.com/BKLronin/touchCNC.git
synced 2024-11-13 20:54:02 +01:00
- Fixed pause and resume in gui
- changed color states - Fixed stop job in gui
This commit is contained in:
parent
9328d5b9e0
commit
cdf067c125
118
cnc_gerbil.py
118
cnc_gerbil.py
@ -34,8 +34,9 @@ class touchCNC:
|
|||||||
self.loaded = 'green'
|
self.loaded = 'green'
|
||||||
self.cooling = 'blue'
|
self.cooling = 'blue'
|
||||||
self.toolchange = 'yellow'
|
self.toolchange = 'yellow'
|
||||||
self.standard = '#17223B'
|
self.standard = '#254164'
|
||||||
self.feed = '#283B67'
|
self.feed = self.standard
|
||||||
|
self.transport = '#3A5F8B'
|
||||||
|
|
||||||
self.increments = IntVar()
|
self.increments = IntVar()
|
||||||
self.movement = Frame(root, relief='ridge', bd=self.BORDER)
|
self.movement = Frame(root, relief='ridge', bd=self.BORDER)
|
||||||
@ -64,32 +65,32 @@ class touchCNC:
|
|||||||
self.setzero = Button(root, text="SetPOS", width=self.buttonsize_x, height=self.buttonsize_y,
|
self.setzero = Button(root, text="SetPOS", width=self.buttonsize_x, height=self.buttonsize_y,
|
||||||
command=lambda: self.directWrite('G28.1'), bd=self.BORDER)
|
command=lambda: self.directWrite('G28.1'), bd=self.BORDER)
|
||||||
self.gozero = Button(root, text="GoPOS", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('G28'),
|
self.gozero = Button(root, text="GoPOS", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('G28'),
|
||||||
bd=self.BORDER)
|
bd=self.BORDER , bg= self.attention)
|
||||||
|
|
||||||
self.connect_ser = Button(root, text="Cnnct", width=self.buttonsize_x, height=self.buttonsize_y,
|
self.connect_ser = Button(root, text="Cnnct", width=self.buttonsize_x, height=self.buttonsize_y,
|
||||||
command=self.grblConnect2, bg='grey', bd=self.BORDER)
|
command=self.grblConnect2, bg='grey', bd=self.BORDER)
|
||||||
self.discon_ser = Button(root, text="Dsconct", width=self.buttonsize_x, height=self.buttonsize_y, command= self.grblClose,
|
self.discon_ser = Button(root, text="Dsconct", width=self.buttonsize_x, height=self.buttonsize_y, command= self.grblClose,
|
||||||
bd=self.BORDER)
|
bd=self.BORDER)
|
||||||
self.unlock = Button(root, text="Unlock", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('$X'),
|
self.unlock = Button(root, text="Unlock", width=self.buttonsize_x, height=self.buttonsize_y, command=self.grblUnlock,
|
||||||
bd=self.BORDER)
|
bd=self.BORDER)
|
||||||
self.start = Button(root, text="START", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.attention,
|
self.start = Button(root, text="START", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.attention,
|
||||||
command=self.grblWrite, bd=self.BORDER)
|
command=self.grblWrite, bd=self.BORDER)
|
||||||
self.stop = Button(root, text="STOP", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER,
|
self.stop = Button(root, text="STOP", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER, bg=self.transport,
|
||||||
command=self.grblStop)
|
command=self.grblStop)
|
||||||
self.pause = Button(root, text="PAUSE", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.cooling, bd=self.BORDER,
|
self.pause = Button(root, text="PAUSE", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER, bg=self.transport,
|
||||||
command=self.grblPause)
|
command=self.grblPause)
|
||||||
self.resume = Button(root, text="RESUME", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER,
|
self.resume = Button(root, text="RESUME", width=self.buttonsize_x, height=self.buttonsize_y, bd=self.BORDER, bg=self.transport,
|
||||||
command=lambda: self.directWrite('~'))
|
command=self.grblResume)
|
||||||
|
|
||||||
self.fopen = Button(root, text="GCODE", width=self.buttonsize_x, height=self.buttonsize_y, bg='grey', fg='black',
|
self.fopen = Button(root, text="GCODE", width=self.buttonsize_x, height=self.buttonsize_y, bg='grey', fg='black',
|
||||||
command=self.openGCODE, bd=self.BORDER)
|
command=self.openGCODE, bd=self.BORDER)
|
||||||
|
|
||||||
self.spindle = Button(root, text="Spindle", width=self.buttonsize_x, height=self.buttonsize_y,
|
self.spindle = Button(root, text="Spindle", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.standard,
|
||||||
command=lambda: self.latchWrite('M3'))
|
command=lambda: self.latchWrite('M3'))
|
||||||
self.coolant = Button(root, text="Coolant", width=self.buttonsize_x, height=self.buttonsize_y,
|
self.coolant = Button(root, text="Coolant", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.standard,
|
||||||
command=lambda: self.latchWrite('M8'))
|
command=lambda: self.latchWrite('M8'))
|
||||||
self.tool = Button(root, text="Tool", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.latchWrite('M6'))
|
self.tool = Button(root, text="Tool", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.standard, command=lambda: self.latchWrite('M6'))
|
||||||
self.macro = Button(root, text="Macro1", width=self.buttonsize_x, height=self.buttonsize_y,
|
self.macro = Button(root, text="Macro1", width=self.buttonsize_x, height=self.buttonsize_y, bg=self.standard,
|
||||||
command=lambda: self.directWrite(' G91 G0 X10 Y10 Z50 F1000'))
|
command=lambda: self.directWrite(' G91 G0 X10 Y10 Z50 F1000'))
|
||||||
|
|
||||||
self.inc1 = Button(root, text="Inc 1%", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('‘'),
|
self.inc1 = Button(root, text="Inc 1%", width=self.buttonsize_x, height=self.buttonsize_y, command=lambda: self.directWrite('‘'),
|
||||||
@ -225,7 +226,7 @@ class touchCNC:
|
|||||||
self.blkbuttons = (self.up, self.down, self.left, self.right, self.z_up, self.z_down, self.zero_x, self.zero_y,
|
self.blkbuttons = (self.up, self.down, self.left, self.right, self.z_up, self.z_down, self.zero_x, self.zero_y,
|
||||||
self.zero_z, self.zero_all, self.setzero, self.gozero, self.spindle)
|
self.zero_z, self.zero_all, self.setzero, self.gozero, self.spindle)
|
||||||
# Initialize the counter
|
# Initialize the counter
|
||||||
self.table = DrawWorkingtable(self.mill_table)
|
self.table = DrawonTable(self.mill_table)
|
||||||
|
|
||||||
def on_zero_position(self, label, pos):
|
def on_zero_position(self, label, pos):
|
||||||
print("Updated", pos)
|
print("Updated", pos)
|
||||||
@ -262,11 +263,13 @@ class touchCNC:
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
if grbl.connected:
|
if grbl.connected:
|
||||||
grbl.poll_start()
|
grbl.poll_start()
|
||||||
|
self.connect_ser.config(bg = self.loaded)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("wtf -couldnt start thread")
|
print("wtf -couldnt start thread")
|
||||||
|
|
||||||
def displayWorkPosition(self, pos: list):
|
def displayWorkPosition(self, pos: list):
|
||||||
print("update", pos)
|
#print("update", pos)
|
||||||
self.show_ctrl_x_w.config(text = pos[0])
|
self.show_ctrl_x_w.config(text = pos[0])
|
||||||
self.show_ctrl_y_w.config(text = pos[1])
|
self.show_ctrl_y_w.config(text = pos[1])
|
||||||
self.show_ctrl_z_w.config(text = pos[2])
|
self.show_ctrl_z_w.config(text = pos[2])
|
||||||
@ -285,52 +288,37 @@ class touchCNC:
|
|||||||
grbl.send_immediately(cmd)
|
grbl.send_immediately(cmd)
|
||||||
|
|
||||||
def latchWrite(self, CMD):
|
def latchWrite(self, CMD):
|
||||||
|
|
||||||
if self.states[CMD] == '0':
|
if self.states[CMD] == '0':
|
||||||
self.states[CMD] = '1'
|
self.states[CMD] = '1'
|
||||||
if CMD == 'M3':
|
self.update_button_color(CMD, True)
|
||||||
self.spindle.config(bg=self.attention) # A31621
|
|
||||||
if CMD == 'M6':
|
|
||||||
self.tool.config(bg=self.toolchange) # E0CA3C
|
|
||||||
if CMD == 'G10':
|
|
||||||
self.zero_all.config(bg=self.loaded)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.states[CMD] = '0'
|
self.states[CMD] = '0'
|
||||||
if CMD == 'M3':
|
self.update_button_color(CMD, False)
|
||||||
self.spindle.config(bg=self.loaded) # A2D729
|
|
||||||
if CMD == 'M6':
|
|
||||||
self.tool.config(bg='grey')
|
|
||||||
# if CMD == 'G10':
|
|
||||||
# zero_all.config(bg= attention)
|
|
||||||
|
|
||||||
if CMD == 'M3':
|
|
||||||
if self.states['M3'] == '1':
|
|
||||||
grbl_command = 'M3 S1000'
|
|
||||||
else:
|
|
||||||
grbl_command = 'M3 S0'
|
|
||||||
|
|
||||||
elif CMD == 'M8':
|
|
||||||
if self.states['M8'] == '1':
|
|
||||||
grbl_command = (CMD)
|
|
||||||
self.coolant.config(bg=self.cooling) # 1F7A8C
|
|
||||||
else:
|
|
||||||
grbl_command = 'M9'
|
|
||||||
self.coolant.config(bg='grey')
|
|
||||||
|
|
||||||
elif CMD == 'G10':
|
|
||||||
grbl_command = 'G10 P0 L20 X0 Y0 Z0'
|
|
||||||
|
|
||||||
else:
|
|
||||||
grbl_command = (CMD)
|
|
||||||
|
|
||||||
# grbl_command = (CMD * int(self.[CMD]) )
|
|
||||||
# print(grbl_command)
|
|
||||||
# print(self.)
|
|
||||||
|
|
||||||
|
grbl_command = self.get_grbl_command(CMD)
|
||||||
grbl.send_immediately(grbl_command)
|
grbl.send_immediately(grbl_command)
|
||||||
|
|
||||||
def overrideCMD(self,cmd):
|
def update_button_color(self, CMD, is_active):
|
||||||
|
if CMD == 'M3':
|
||||||
|
self.spindle.config(bg=self.attention if is_active else self.loaded)
|
||||||
|
elif CMD == 'M6':
|
||||||
|
self.tool.config(bg=self.toolchange if is_active else self.standard)
|
||||||
|
elif CMD == 'G10':
|
||||||
|
self.zero_all.config(bg=self.loaded if is_active else self.attention)
|
||||||
|
|
||||||
|
if CMD == 'M8':
|
||||||
|
self.coolant.config(bg=self.cooling if is_active else self.standard)
|
||||||
|
|
||||||
|
def get_grbl_command(self, CMD):
|
||||||
|
if CMD == 'M3':
|
||||||
|
return 'M3 S1000' if self.states['M3'] == '1' else 'M3 S0'
|
||||||
|
elif CMD == 'M8':
|
||||||
|
return CMD if self.states[CMD] == '1' else 'M9'
|
||||||
|
elif CMD == 'G10':
|
||||||
|
return 'G10 P0 L20 X0 Y0 Z0'
|
||||||
|
else:
|
||||||
|
return CMD
|
||||||
|
def overrideCMD(self, cmd):
|
||||||
pass
|
pass
|
||||||
#grbl.
|
#grbl.
|
||||||
|
|
||||||
@ -341,12 +329,11 @@ class touchCNC:
|
|||||||
if GCODE != 0:
|
if GCODE != 0:
|
||||||
self.fopen.config(bg=self.loaded)
|
self.fopen.config(bg=self.loaded)
|
||||||
extracted = self.extract_GCODE(GCODE)
|
extracted = self.extract_GCODE(GCODE)
|
||||||
draw = DrawWorkingtable(self.mill_table)
|
draw = DrawonTable(self.mill_table)
|
||||||
draw.drawgridTable()
|
draw.drawgridTable()
|
||||||
draw.setGCODE(extracted)
|
draw.setGCODE(extracted)
|
||||||
draw.draw_GCODE()
|
draw.draw_GCODE()
|
||||||
|
|
||||||
|
|
||||||
grbl.load_file(GCODE)
|
grbl.load_file(GCODE)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -354,11 +341,19 @@ class touchCNC:
|
|||||||
|
|
||||||
def grblWrite(self):
|
def grblWrite(self):
|
||||||
grbl.job_run()
|
grbl.job_run()
|
||||||
|
|
||||||
def grblStop(self):
|
def grblStop(self):
|
||||||
grbl.abort()
|
grbl.job_halt()
|
||||||
|
|
||||||
def grblPause(self):
|
def grblPause(self):
|
||||||
grbl.hold()
|
grbl.hold()
|
||||||
|
self.pause.config(bg='red')
|
||||||
|
def grblResume(self):
|
||||||
|
grbl.resume()
|
||||||
|
self.pause.config(bg=self.transport)
|
||||||
|
def grblUnlock(self):
|
||||||
|
grbl.killalarm()
|
||||||
|
|
||||||
|
|
||||||
def extract_GCODE(self, gcode_path: str): # Aufschlüsseln der enthaltenen Koordinaten in ein per Schlüssel zugängiges Dictionary
|
def extract_GCODE(self, gcode_path: str): # Aufschlüsseln der enthaltenen Koordinaten in ein per Schlüssel zugängiges Dictionary
|
||||||
with open(gcode_path, 'r') as gcode:
|
with open(gcode_path, 'r') as gcode:
|
||||||
@ -386,14 +381,15 @@ class touchCNC:
|
|||||||
# print(dict_GCODE)
|
# print(dict_GCODE)
|
||||||
list_dict_GCODE.append(
|
list_dict_GCODE.append(
|
||||||
self.dict_GCODE.copy()) # Copy notwendig da es sich nur um einen "Pointer" handelt der immer auf die zuletzt aktualisierte dict Zeile zeigt.
|
self.dict_GCODE.copy()) # Copy notwendig da es sich nur um einen "Pointer" handelt der immer auf die zuletzt aktualisierte dict Zeile zeigt.
|
||||||
print(list_dict_GCODE)
|
#print(list_dict_GCODE)
|
||||||
|
|
||||||
return list_dict_GCODE
|
return list_dict_GCODE
|
||||||
|
|
||||||
def grblClose(self):
|
def grblClose(self):
|
||||||
grbl.disconnect()
|
grbl.disconnect()
|
||||||
|
self.connect_ser.config(bg='grey')
|
||||||
|
|
||||||
class DrawWorkingtable:
|
class DrawonTable:
|
||||||
def __init__(self, mill_table: object):
|
def __init__(self, mill_table: object):
|
||||||
self.mill_table = mill_table
|
self.mill_table = mill_table
|
||||||
self.gcode: list = None
|
self.gcode: list = None
|
||||||
@ -411,13 +407,13 @@ class DrawWorkingtable:
|
|||||||
self.mill_table.delete('all')
|
self.mill_table.delete('all')
|
||||||
|
|
||||||
def drawToolCursor(self):
|
def drawToolCursor(self):
|
||||||
id = self.mill_table.create_text(50 + float(self.cursor_pos[0]), 350 - float(self.cursor_pos[1]), text='V', fill = 'red')
|
id = self.mill_table.create_text(50 + float(self.cursor_pos[0]), 345 - float(self.cursor_pos[1]), text='V', fill = 'red')
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
def deleteCursor(self, id):
|
def deleteCursor(self, id):
|
||||||
if id != None:
|
if id != None:
|
||||||
print("deleted")
|
#print("deleted")
|
||||||
self.mill_table.delete(id)
|
self.mill_table.delete(id)
|
||||||
|
|
||||||
def draw_GCODE(self): # Zeichnen des GCodes zur Beurteilung des Bauraums
|
def draw_GCODE(self): # Zeichnen des GCodes zur Beurteilung des Bauraums
|
||||||
@ -445,8 +441,6 @@ class DrawWorkingtable:
|
|||||||
gitter_y = self.mill_table.create_line(0, y, 400, y)
|
gitter_y = self.mill_table.create_line(0, y, 400, y)
|
||||||
|
|
||||||
|
|
||||||
print("test")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title('touchCNC')
|
root.title('touchCNC')
|
||||||
|
Loading…
Reference in New Issue
Block a user