basic gcode simulator
|
@ -0,0 +1,94 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from tkinter import Tk, Canvas, Frame, BOTH, EventType, ALL
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
gcode_file_path = " "
|
||||||
|
bedsizex = 0
|
||||||
|
bedsizey = 0
|
||||||
|
scale_factor = 1.0
|
||||||
|
x_offset = 24.0
|
||||||
|
y_offset = 24.0
|
||||||
|
laser_on = False
|
||||||
|
last_position = {"x": x_offset, "y": 720-y_offset} #set to initial start at home pos
|
||||||
|
global canvas
|
||||||
|
debug = True
|
||||||
|
|
||||||
|
def parse_arguments():
|
||||||
|
global gcode_file_path
|
||||||
|
global bedsizex
|
||||||
|
global bedsizey
|
||||||
|
parser = argparse.ArgumentParser(description='Simulate gcode for laser plotter.')
|
||||||
|
parser.add_argument("-i", "--input", dest='inputfile', metavar='data.gcode', help="path to gcode file", required=True)
|
||||||
|
parser.add_argument("-bx", "--bedsizex", dest='bedsizex', default="376", help="x size of bed in mm", required=False)
|
||||||
|
parser.add_argument("-by", "--bedsizey", dest='bedsizey', default="315", help="y size of bed in mm", required=False)
|
||||||
|
args = parser.parse_args()
|
||||||
|
gcode_file_path = args.inputfile
|
||||||
|
bedsizex = int(args.bedsizex)
|
||||||
|
bedsizey = int(args.bedsizey)
|
||||||
|
|
||||||
|
def plot_paths(canvas):
|
||||||
|
gcode_file = open(gcode_file_path, "r")
|
||||||
|
for line in gcode_file.readlines():
|
||||||
|
if(not line.startswith(';')): #filter comments
|
||||||
|
#print(line)
|
||||||
|
if(line.startswith('M5')):
|
||||||
|
if(debug): print("[decoder] laser off")
|
||||||
|
laser_on = False
|
||||||
|
if(line.startswith('M3')):
|
||||||
|
if(debug): print("[decoder] laser on")
|
||||||
|
laser_on = True
|
||||||
|
if(line.startswith('G1')):
|
||||||
|
x = float(line[(int(line.find('X'))+1):(int(line.find('Y')-1))]) * (scale_factor*1) + x_offset
|
||||||
|
y = (720-y_offset) - (float(line[(int(line.find('Y'))+1):(int(line.find(';')-1))])* (scale_factor*1))
|
||||||
|
|
||||||
|
|
||||||
|
if(debug): print("[decoder] movement to " + str(x) + " " + str(y))
|
||||||
|
if(laser_on == True):
|
||||||
|
canvas.create_line(last_position["x"], last_position["y"], x, y, width=5, fill='red')
|
||||||
|
else:
|
||||||
|
canvas.create_line(last_position["x"], last_position["y"], x, y, width=3, fill='green')
|
||||||
|
last_position["x"] = x
|
||||||
|
last_position["y"] = y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SimulatorView(Frame):
|
||||||
|
def __init__(self):
|
||||||
|
global canvas
|
||||||
|
super().__init__()
|
||||||
|
canvas = Canvas(self)
|
||||||
|
#canvas.bind("<B1-Motion>", lambda event: canvas.scan_dragto(event.x, event.y, gain=1))
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
self.master.title("gcode simulator")
|
||||||
|
self.pack(fill=BOTH, expand=1)
|
||||||
|
canvas.create_line(x_offset, y_offset, x_offset, (720-y_offset), width=2, fill='black')
|
||||||
|
canvas.create_line(1280-x_offset, y_offset, 1280-x_offset, (720-y_offset), width=2, fill='black')
|
||||||
|
canvas.create_line(x_offset, y_offset, 1280-x_offset, y_offset, width=2, fill='black')
|
||||||
|
canvas.create_line(x_offset, (720-y_offset), 1280-x_offset, (720-y_offset), width=2, fill='black')
|
||||||
|
plot_paths(canvas)
|
||||||
|
canvas.pack(fill=BOTH, expand=1)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parse_arguments()
|
||||||
|
|
||||||
|
if(bedsizex < bedsizey):
|
||||||
|
scale_factor = float(720/bedsizey)
|
||||||
|
else:
|
||||||
|
scale_factor = float(1280/bedsizex)
|
||||||
|
|
||||||
|
print("scale factor: " + str(scale_factor))
|
||||||
|
|
||||||
|
#plot_paths(0)
|
||||||
|
|
||||||
|
root = Tk()
|
||||||
|
ex = SimulatorView()
|
||||||
|
root.geometry(str(1280+int(x_offset))+"x"+str(720+int(y_offset))+"+300+300")
|
||||||
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -2,66 +2,52 @@
|
||||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
<svg
|
<svg
|
||||||
width="54.875031mm"
|
width="100mm"
|
||||||
height="8.0408278mm"
|
height="100mm"
|
||||||
viewBox="0 0 54.875031 8.0408278"
|
viewBox="0 0 100 100"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="svg5"
|
id="svg5"
|
||||||
|
sodipodi:docname="Test_H.svg"
|
||||||
|
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlns:svg="http://www.w3.org/2000/svg"
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
xmlns:cc="http://creativecommons.org/ns#">
|
xmlns:cc="http://creativecommons.org/ns#">
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview465"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="0.58546011"
|
||||||
|
inkscape:cx="-317.69884"
|
||||||
|
inkscape:cy="177.63806"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1011"
|
||||||
|
inkscape:window-x="1680"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="text638" />
|
||||||
<defs
|
<defs
|
||||||
id="defs2" />
|
id="defs2" />
|
||||||
<g
|
<g
|
||||||
id="layer1"
|
id="layer1"
|
||||||
transform="translate(-42.962838,-5.5320735)">
|
transform="translate(-42.962838,-5.5320735)">
|
||||||
<g
|
<g
|
||||||
aria-label="H"
|
aria-label="L"
|
||||||
id="text115"
|
transform="scale(0.96903939,1.0319498)"
|
||||||
style="font-size:50.8px;line-height:1.25;stroke-width:0.264583">
|
id="text638"
|
||||||
<g
|
style="font-size:90.5838px;line-height:1.25;stroke-width:2.2646">
|
||||||
aria-label="Hallo Jakob!"
|
|
||||||
id="text221"
|
|
||||||
style="font-size:10.5833px;stroke-width:0.0700042"
|
|
||||||
transform="matrix(1,0,0,-1,0,87.650687)">
|
|
||||||
<g
|
|
||||||
aria-label="Hallo Jacob"
|
|
||||||
transform="matrix(1,0,0,-1,2.1478405,-1.3889376)"
|
|
||||||
id="text1639"
|
|
||||||
style="stroke-width:0.0185219">
|
|
||||||
<path
|
<path
|
||||||
d="m 45.605388,-75.570076 v -3.477813 H 41.81235 v 3.477813 h -0.997352 v -7.524065 h 0.997352 v 3.234935 h 3.793038 v -3.234935 h 0.992185 v 7.524065 z"
|
d="m 116.59552,78.34037 v 6.944168 H 77.540103 V 20.885117 h 8.536462 V 78.34037 Z"
|
||||||
id="path794" />
|
id="path703" />
|
||||||
<path
|
|
||||||
d="m 51.672182,-75.570076 q -0.09302,-0.201537 -0.134358,-0.589109 -0.268716,0.284219 -0.671791,0.490924 -0.403075,0.201538 -0.919838,0.201538 -0.857826,0 -1.374589,-0.48059 -0.516762,-0.480589 -0.516762,-1.178219 0,-0.899167 0.682126,-1.364253 0.682127,-0.470254 1.834508,-0.470254 h 0.945676 v -0.444416 q 0,-0.496092 -0.299723,-0.790647 -0.294554,-0.299722 -0.878496,-0.299722 -0.542601,0 -0.878497,0.268716 -0.330728,0.263549 -0.330728,0.614948 h -0.956011 q 0,-0.599445 0.604612,-1.126543 0.604613,-0.527098 1.617468,-0.527098 0.909502,0 1.493444,0.465087 0.583942,0.465086 0.583942,1.405594 v 2.511467 q 0,0.775144 0.196369,1.229895 v 0.08268 z m -1.586461,-0.733803 q 0.516763,0 0.893999,-0.258381 0.382405,-0.258382 0.537434,-0.573607 v -1.152381 h -0.888832 q -1.6123,0.03101 -1.6123,1.033526 0,0.397907 0.268717,0.676959 0.268716,0.273884 0.800982,0.273884 z"
|
|
||||||
id="path796" />
|
|
||||||
<path
|
|
||||||
d="m 55.015637,-83.507551 v 7.937475 h -0.961179 v -7.937475 z"
|
|
||||||
id="path798" />
|
|
||||||
<path
|
|
||||||
d="m 57.589115,-83.507551 v 7.937475 h -0.961178 v -7.937475 z"
|
|
||||||
id="path800" />
|
|
||||||
<path
|
|
||||||
d="m 58.870687,-78.422606 q 0,-1.214392 0.682127,-2.02571 0.682127,-0.816485 1.855178,-0.816485 1.173051,0 1.855178,0.800982 0.682127,0.795815 0.69763,1.989537 v 0.170531 q 0,1.214393 -0.687295,2.02571 -0.682126,0.811318 -1.855178,0.811318 -1.178219,0 -1.865513,-0.811318 -0.682127,-0.811317 -0.682127,-2.02571 z m 0.956011,0.118855 q 0,0.831988 0.39274,1.441768 0.397907,0.60978 1.198889,0.60978 0.780312,0 1.178219,-0.599444 0.397907,-0.604613 0.403075,-1.436601 v -0.134358 q 0,-0.821653 -0.397907,-1.4366 -0.397907,-0.620115 -1.193722,-0.620115 -0.790647,0 -1.188554,0.620115 -0.39274,0.614947 -0.39274,1.4366 z"
|
|
||||||
id="path802" />
|
|
||||||
<path
|
|
||||||
d="m 71.086957,-83.094141 h 0.992184 v 5.327824 q 0,1.116207 -0.671792,1.710484 -0.666623,0.58911 -1.700149,0.58911 -1.038693,0 -1.710484,-0.537434 -0.666624,-0.537433 -0.666624,-1.648473 h 0.997352 q 0,0.713133 0.382404,1.043861 0.387572,0.330728 0.997352,0.330728 0.58911,0 0.981849,-0.377237 0.397908,-0.377236 0.397908,-1.111039 z"
|
|
||||||
id="path804" />
|
|
||||||
<path
|
|
||||||
d="m 77.076236,-75.570076 q -0.09302,-0.201537 -0.134358,-0.589109 -0.268717,0.284219 -0.671792,0.490924 -0.403075,0.201538 -0.919837,0.201538 -0.857826,0 -1.374589,-0.48059 -0.516763,-0.480589 -0.516763,-1.178219 0,-0.899167 0.682127,-1.364253 0.682127,-0.470254 1.834508,-0.470254 h 0.945675 v -0.444416 q 0,-0.496092 -0.299722,-0.790647 -0.294555,-0.299722 -0.878497,-0.299722 -0.5426,0 -0.878496,0.268716 -0.330728,0.263549 -0.330728,0.614948 h -0.956011 q 0,-0.599445 0.604612,-1.126543 0.604612,-0.527098 1.617467,-0.527098 0.909503,0 1.493444,0.465087 0.583942,0.465086 0.583942,1.405594 v 2.511467 q 0,0.775144 0.19637,1.229895 v 0.08268 z m -1.586461,-0.733803 q 0.516762,0 0.893999,-0.258381 0.382405,-0.258382 0.537433,-0.573607 v -1.152381 h -0.888831 q -1.6123,0.03101 -1.6123,1.033526 0,0.397907 0.268717,0.676959 0.268716,0.273884 0.800982,0.273884 z"
|
|
||||||
id="path806" />
|
|
||||||
<path
|
|
||||||
d="m 81.618581,-76.252203 q 0.511595,0 0.893999,-0.30489 0.387572,-0.30489 0.423745,-0.780311 h 0.909503 q -0.03617,0.749306 -0.687295,1.312577 -0.651121,0.558104 -1.539952,0.558104 -1.260901,0 -1.875849,-0.831988 -0.60978,-0.831988 -0.60978,-1.958531 v -0.21704 q 0,-1.126543 0.60978,-1.958531 0.614948,-0.831988 1.875849,-0.831988 0.981849,0 1.586461,0.583942 0.604612,0.578774 0.640786,1.441768 h -0.909503 q -0.03617,-0.516763 -0.392739,-0.878497 -0.351399,-0.361733 -0.925005,-0.361733 -0.58911,0 -0.925006,0.299722 -0.330728,0.299722 -0.470254,0.759641 -0.134358,0.459919 -0.134358,0.945676 v 0.21704 q 0,0.490925 0.134358,0.950843 0.134359,0.459919 0.465087,0.759642 0.335896,0.294554 0.930173,0.294554 z"
|
|
||||||
id="path808" />
|
|
||||||
<path
|
|
||||||
d="m 84.66748,-78.422606 q 0,-1.214392 0.682127,-2.02571 0.682127,-0.816485 1.855178,-0.816485 1.173051,0 1.855178,0.800982 0.682127,0.795815 0.69763,1.989537 v 0.170531 q 0,1.214393 -0.687295,2.02571 -0.682126,0.811318 -1.855178,0.811318 -1.178219,0 -1.865513,-0.811318 -0.682127,-0.811317 -0.682127,-2.02571 z m 0.956011,0.118855 q 0,0.831988 0.39274,1.441768 0.397907,0.60978 1.198889,0.60978 0.780312,0 1.178219,-0.599444 0.397907,-0.604613 0.403075,-1.436601 v -0.134358 q 0,-0.821653 -0.397907,-1.4366 -0.397908,-0.620115 -1.193722,-0.620115 -0.790647,0 -1.188554,0.620115 -0.39274,0.614947 -0.39274,1.4366 z"
|
|
||||||
id="path810" />
|
|
||||||
<path
|
|
||||||
d="m 95.69003,-78.303751 q 0,1.224728 -0.568439,2.030878 -0.568439,0.80615 -1.607132,0.80615 -1.059364,0 -1.63297,-0.749306 l -0.05168,0.645953 h -0.878496 v -7.937475 h 0.961178 v 2.950715 q 0.568439,-0.707965 1.591629,-0.707965 1.054196,0 1.617468,0.78548 0.568439,0.785479 0.568439,2.06705 z m -2.423617,-2.1549 q -0.521931,0 -0.847491,0.253214 -0.325561,0.248046 -0.506428,0.614947 v 2.433953 q 0.186035,0.372069 0.516763,0.625282 0.330728,0.253214 0.847491,0.253214 0.775144,0 1.11104,-0.594277 0.341063,-0.599445 0.341063,-1.431433 v -0.10852 q 0,-0.831988 -0.325561,-1.4366 -0.320392,-0.60978 -1.136877,-0.60978 z"
|
|
||||||
id="path812" />
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
<metadata
|
<metadata
|
||||||
|
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 15 KiB |
|
@ -1,45 +0,0 @@
|
||||||
G90 ;Absolute programming
|
|
||||||
G21 ;Programming in millimeters (mm)
|
|
||||||
M5 ;Disable laser
|
|
||||||
; == Start of circle ==
|
|
||||||
G00 X5 Y5
|
|
||||||
M3 I S150 ;start laser
|
|
||||||
G02 X5 Y5 I5 J0
|
|
||||||
M5 ;stop laser
|
|
||||||
; == End of circle ==
|
|
||||||
G1 X0.0 Y0.0; Display printbed
|
|
||||||
|
|
||||||
; == Start of circle ==
|
|
||||||
G1 X0.4 Y5.0
|
|
||||||
M3 I S150 ;start laser
|
|
||||||
G1 X0.4 Y5.4
|
|
||||||
G1 X0.7 Y6.6
|
|
||||||
G1 X1.2 Y7.6
|
|
||||||
G1 X2.0 Y8.5
|
|
||||||
G1 X3.1 Y9.2
|
|
||||||
G1 X4.2 Y9.5
|
|
||||||
G1 X5.4 Y9.6
|
|
||||||
G1 X6.6 Y9.3
|
|
||||||
G1 X7.6 Y8.8
|
|
||||||
G1 X8.5 Y8.0
|
|
||||||
G1 X9.2 Y7.0
|
|
||||||
G1 X9.5 Y5.8
|
|
||||||
G1 X9.6 Y4.6
|
|
||||||
G1 X9.3 Y3.4
|
|
||||||
G1 X8.8 Y2.4
|
|
||||||
G1 X8.0 Y1.5
|
|
||||||
G1 X6.9 Y0.8
|
|
||||||
G1 X5.8 Y0.5
|
|
||||||
G1 X4.6 Y0.4
|
|
||||||
G1 X3.4 Y0.7
|
|
||||||
G1 X2.4 Y1.2
|
|
||||||
G1 X1.5 Y2.0
|
|
||||||
G1 X0.8 Y3.0
|
|
||||||
G1 X0.5 Y4.2
|
|
||||||
G1 X0.4 Y5.0
|
|
||||||
M5 ;stop laser
|
|
||||||
; == End of circle ==
|
|
||||||
|
|
||||||
M02 ;End of program
|
|
||||||
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
G90 ;Absolute programming
|
|
||||||
G21 ;Programming in millimeters (mm)
|
|
||||||
M5 ;Disable laser
|
|
||||||
G01 F200.0
|
|
||||||
; == Start of circle ==
|
|
||||||
G1 X0.4 Y5.0
|
|
||||||
M3 I S150 ;start laser
|
|
||||||
G1 X0.4 Y5.4
|
|
||||||
G1 X0.7 Y6.6
|
|
||||||
G1 X1.2 Y7.6
|
|
||||||
G1 X2.0 Y8.5
|
|
||||||
G1 X3.1 Y9.2
|
|
||||||
G1 X4.2 Y9.5
|
|
||||||
G1 X5.4 Y9.6
|
|
||||||
G1 X6.6 Y9.3
|
|
||||||
G1 X7.6 Y8.8
|
|
||||||
G1 X8.5 Y8.0
|
|
||||||
G1 X9.2 Y7.0
|
|
||||||
G1 X9.5 Y5.8
|
|
||||||
G1 X9.6 Y4.6
|
|
||||||
G1 X9.3 Y3.4
|
|
||||||
G1 X8.8 Y2.4
|
|
||||||
G1 X8.0 Y1.5
|
|
||||||
G1 X6.9 Y0.8
|
|
||||||
G1 X5.8 Y0.5
|
|
||||||
G1 X4.6 Y0.4
|
|
||||||
G1 X3.4 Y0.7
|
|
||||||
G1 X2.4 Y1.2
|
|
||||||
G1 X1.5 Y2.0
|
|
||||||
G1 X0.8 Y3.0
|
|
||||||
G1 X0.5 Y4.2
|
|
||||||
G1 X0.4 Y5.0
|
|
||||||
M5 ;stop laser
|
|
||||||
; == End of circle ==
|
|
||||||
G1 X0.0 Y0.0; Display printbed
|
|
||||||
M02 ;End of program
|
|
|
@ -1,35 +0,0 @@
|
||||||
G90 ;Absolute programming
|
|
||||||
G21 ;Programming in millimeters (mm)
|
|
||||||
M5 ;Disable laser
|
|
||||||
; == Start of circle ==
|
|
||||||
G1 X0.4 Y5.0
|
|
||||||
M3 I S150 ;start laser
|
|
||||||
G1 X0.4 Y5.4
|
|
||||||
G1 X0.7 Y6.6
|
|
||||||
G1 X1.2 Y7.6
|
|
||||||
G1 X2.0 Y8.5
|
|
||||||
G1 X3.1 Y9.2
|
|
||||||
G1 X4.2 Y9.5
|
|
||||||
G1 X5.4 Y9.6
|
|
||||||
G1 X6.6 Y9.3
|
|
||||||
G1 X7.6 Y8.8
|
|
||||||
G1 X8.5 Y8.0
|
|
||||||
G1 X9.2 Y7.0
|
|
||||||
G1 X9.5 Y5.8
|
|
||||||
G1 X9.6 Y4.6
|
|
||||||
G1 X9.3 Y3.4
|
|
||||||
G1 X8.8 Y2.4
|
|
||||||
G1 X8.0 Y1.5
|
|
||||||
G1 X6.9 Y0.8
|
|
||||||
G1 X5.8 Y0.5
|
|
||||||
G1 X4.6 Y0.4
|
|
||||||
G1 X3.4 Y0.7
|
|
||||||
G1 X2.4 Y1.2
|
|
||||||
G1 X1.5 Y2.0
|
|
||||||
G1 X0.8 Y3.0
|
|
||||||
G1 X0.5 Y4.2
|
|
||||||
G1 X0.4 Y5.0
|
|
||||||
M5 ;stop laser
|
|
||||||
; == End of circle ==
|
|
||||||
G1 X0.0 Y0.0; Display printbed
|
|
||||||
M02 ;End of program
|
|