forked from VolumetricBio/printrun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kevin2off.py
executable file
·212 lines (135 loc) · 5.61 KB
/
kevin2off.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
#!/usr/bin/env python3
#to send a file of gcode to the printer
import subprocess
import os
import sys
import threading
import time
sys.path.append( '/home/lumen/Volumetric/printrun' )
from printrun.printcore import printcore
from printrun import gcoder
# https://stackoverflow.com/questions/35685403/python-run-subprocess-for-certain-time
def on_timeout(proc, status_dict):
"""Kill process on timeout and note as status_dict['timeout']=True"""
# a container used to pass status back to calling thread
status_dict['timeout'] = True
print("timed out")
proc.kill()
# test_script = "killall feh; feh -x --geometry 1280x800 /home/lumen/Volumetric/model-library/LUMEN-logo_imgs/01.png"
theCleanPortString = "/dev/lumen-arduino"
print(theCleanPortString)
p=printcore(theCleanPortString,250000) # or p.printcore('COM3',250000) on Windows
# Wait for the printer to connect. Check every 100 ms
while not p.online: time.sleep(0.1)
print(str(p.online) + " that the printer is online now yay!")
# NEVER STOP
currentLayer = 0
# TURN OFF PROJECTOR
command = "setpower 0"
print("command is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
command = "killall feh"
print("command is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
BEDTEMP = 37
p.send_now("M140 S" + str(BEDTEMP))
# HOME THE PRINTER
p.send_now("G28 X")
print ("HOMING")
# print ("pausing 60 sec to allow you to adjust z0")
# time.sleep(60)
z0 = 0
# mm/min
PRINTSPEED = 200
for i in range(80):
if i == 0:
# 50 µm printing FTW
layerHeight = 0.05
burnInFactor = 3
exposureTime = 13*burnInFactor
pauseBeforeLift = 10
pauseToFindZero = 60
pauseBeforeExpose = 4
pauseToLoadResin = 15
liftDistance = 2
# PAUSE BEFORE PROJECT
print ("SET Z0 NOW, MANUALLY, you have " + str(pauseToFindZero) + " seconds. Be precise here!!")
# print ("PAUSE TO SET Z0: " + str(pauseToFindZero) + " seconds")
time.sleep(pauseToFindZero)
# GO TO LAYER POSITION -- LIFT DISTANCE
p.send_now("G91") # RELATIVE POSITIONING
# p.send_now("G92 X0; you are now at z0")
print("YOU ARE NOW AT Z0, ALMOST READY TO BEGIN PRINTING")
p.send_now("G90") # ABSOLUTE POSITIONING
p.send_now("G1 X30 F" + str(PRINTSPEED))
# PAUSE BEFORE PROJECT
print ("PAUSE TO LOAD RESIN: " + str(pauseToLoadResin) + " seconds")
time.sleep(pauseToLoadResin)
p.send_now("G1 X" + str(layerHeight) + " F" + str(PRINTSPEED))
p.send_now("G91") # RELATIVE POSITIONING
print ("PAUSE TO RETURN TO FIRST LAYER POSITION: " + str(pauseToLoadResin) + " seconds")
time.sleep(pauseToLoadResin)
if i == 1:
pauseBeforeLift = 4
if i > 1:
exposureTime = exposureTime/burnInFactor
# pauseBeforeLift = 1
# pauseBeforeExpose = 2
# liftDistance = 2
if (i+1)*layerHeight >= 80:
#DON'T PRINT MORE THAN 80 mm TOTAL
print ("max print distance reached!")
break
print("\n\n######## CURRENT LAYER IS #" + str(currentLayer+1))
if i > 0:
# PAUSE BEFORE LIFT
print ("PAUSE BEFORE LIFT: " + str(pauseBeforeLift) + " seconds")
time.sleep(pauseBeforeLift)
# GO TO LAYER POSITION -- LIFT DISTANCE
p.send_now("G91; relative positioning")
p.send_now("G1 X" + str(liftDistance) + " F" + str(PRINTSPEED))
# GO TO LAYER POSITION -- LIFT DISTANCE
p.send_now("G91; relative positioning")
p.send_now("G1 X-" + str(liftDistance-layerHeight) + " F" + str(PRINTSPEED))
# PROJECT THE IMAGE
# command = "feh -x --geometry 1280x800 /home/lumen/Volumetric/model-library/makerook_imgs/" + '%03d' % (i*6) + ".png &"
command = "feh -x --geometry 1280x800 /home/lumen/Volumetric/working/kevin-50-2off/" + '%06d' % i + ".png &"
print("command #" + str(i+1) + " is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
# PAUSE BEFORE PROJECT
print ("PAUSE BEFORE PROJECTION: " + str(pauseBeforeExpose) + " seconds")
time.sleep(pauseBeforeExpose)
# START PROJECTION
command = "setpower 105"
print("command #" + str(i+1) + " is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
print ("PROJECTION: " + str(exposureTime) + " seconds")
time.sleep(exposureTime)
command = "setpower 0"
print("command #" + str(i+1) + " is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
#KILLALL FEH
command = "killall feh &"
print("command #" + str(i+1) + " is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
print ("MOVE TO NEXT LAYER")
# command = "killall feh"
# print("command #" + str(i+1) + " is " + command)
# return_code = subprocess.call(command, shell=True)
# print(return_code)
currentLayer += 1
p.send_now("G90")
p.send_now("G0 X100 F300")
print ("PRINT HAS COMPLETED YAY!")
# # If you need to interact with the printer:
# # p.send_now("M105") # this will send M105 immediately, ahead of the rest of the print
# # p.pause() # use these to pause/resume the current print
# # p.resume()
# p.disconnect() # this is how you disconnect from the printer once you are done. This will also stop running prints.
p.disconnect() # this is how you disconnect from the printer once you are done. This will also stop running prints.