forked from JakobStaudt/laserPlotter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaserPlotter.py
86 lines (74 loc) · 2.33 KB
/
laserPlotter.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
import turtle
import re
import random
import math
# draw slowly or show image immediately?
drawInstantly = False
# show lines where Laser is off?
drawTravel = True
# Draw Points where Laser is on and not moving?
drawWaitBurn = True
# ceiling of burn dot diameter
maxBurnDia = 2
# coefficient for burn dot diameter calculations
burnTimeCoefficient = 800
# color used for plotting when Laser is enabled
cutColor = "black"
# color used for plotting when Laser is disabled (and drawTravel is True)
travelColor = "red"
# speed for plotting travel Moves (based on G-Code G0, not Laser state)
travelSpeed = 0
# speed for plotting cutting Moves (based on G-Code G1, not Laser state)
cutSpeed = 1
laserEnable = "M106"
laserDisable = "M107"
fileName = "qrCode.nc"
canvasScale = 30
xOffset = canvasScale * -11
yOffset = canvasScale * -11
if drawInstantly:
turtle.tracer(0, 0)
turtle.penup()
laserEnabled = False
turtle.speed(travelSpeed)
turtle.goto(xOffset, yOffset)
with open(fileName) as file:
fileList = file.readlines()
for line in fileList:
line = line.strip("\n")
if line.startswith("G0") or line.startswith("G1"):
travel = False
if line.startswith("G0"):
travel = True
print(travel)
xPos = re.search("X(\d+(\.\d+)?)", line)
if xPos != None:
xPos = float(xPos[0][1:])
yPos = re.search("Y(\d+(\.\d+)?)", line)
if yPos != None:
yPos = float(yPos[0][1:])
if xPos != None and yPos != None:
if travel:
turtle.speed(travelSpeed)
else:
turtle.speed(cutSpeed)
turtle.goto(xPos * canvasScale + xOffset, yPos * canvasScale + yOffset)
elif line.startswith("G4") and laserEnabled and drawWaitBurn:
waitTime = re.search("P\d+", line)
if waitTime != None:
waitTime = int(waitTime[0][1:])
pointDia = maxBurnDia - (maxBurnDia * (math.e ** (waitTime / -burnTimeCoefficient)))
turtle.dot(pointDia * canvasScale)
elif line.startswith(laserEnable):
laserEnabled = True
if drawTravel:
turtle.color("black")
turtle.pendown()
elif line.startswith(laserDisable):
laserEnabled = False
if drawTravel:
turtle.color("red")
else:
turtle.penup()
turtle.update()
_ = input()