forked from VolumetricBio/printrun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathburn_in.py
executable file
·274 lines (187 loc) · 7.62 KB
/
burn_in.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/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()
# runs = 1000 # Default run is 1000
# if len(sys.argv)>1: # If I want to change the num of runs
# runs = int(sys.argv[1])
# FNULL = open(os.devnull, 'w')
# logfile = open('logfile', 'w')
# replacing example with a running program. This is a simple python
# we can call from the command line.
# args = "exe" # Exe to test
# test_script = "import time;import sys;time.sleep(%d);sys.exit(100)"
test_script = "killall feh; feh -x --geometry 1280x800 /home/lumen/Volumetric/LightField/model-library/LUMEN-logo_imgs/01.png"
# REPRAP GCODES:
# https://reprap.org/wiki/G-code
# jmil says FIND THE CORRECT PORT FIRST WITH "ls /dev/ | grep ttyACM*"
# import subprocess
# batcmd="ls /dev/|grep ttyACM*"
# allPorts = subprocess.check_output(batcmd, shell=True)
# # this could contain multiple lines. Get only the first line
# thePortsArray = allPorts.splitlines()
# print(thePortsArray)
# theFirstPort = thePortsArray[0]
# theCleanPortString = "/dev/" + theFirstPort.decode("utf-8").strip()
theCleanPortString = "/dev/lumen-arduino"
print(theCleanPortString)
p=printcore(theCleanPortString,250000) # or p.printcore('COM3',250000) on Windows
# e.g.: p=printcore("/dev/tty.usbmodem144241",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!")
# gcode=[i.strip() for i in open('test.gcode')] # or pass in your own array of gcode lines instead of reading from a file
# print(gcode)
# gcode = gcoder.LightGCode(gcode)
# print(gcode)
# p.startprint(gcode) # this will start a print
# def projectLayer():
# test_script = "killall feh; set-projector-power 255; feh -x --geometry 1280x800 /home/lumen/Volumetric/model-library/LUMEN-logo_imgs/01.png"
# succ = 0
# fail = 0
# # set by timer
# status_dict = {'timeout':False}
# # test prog sleeps i seconds
# args = ["bash", "-c", test_script]
# proc = subprocess.Popen(args,
# stdout = logfile, stderr = FNULL)
# # trigger timout and kill process in 5 seconds
# timer = threading.Timer(5, on_timeout, (proc, status_dict))
# timer.start()
# proc.wait()
# # in case we didn't hit timeout
# timer.cancel()
# print (status_dict)
# if not status_dict['timeout'] and proc.returncode == 100:
# succ += 1 # If returned 100 then success
# else:
# fail += 1 # Else Failed
# open('logfile', 'w').close() # Empties the file
# print ("Succ: %d , Fail: %d" % (succ, fail))
#
#
# def powerOff():
# test_script = "set-projector-power 0"
# succ = 0
# fail = 0
# # set by timer
# status_dict = {'timeout':False}
# # test prog sleeps i seconds
# args = ["bash", "-c", test_script]
# proc = subprocess.Popen(args,
# stdout = logfile, stderr = FNULL)
# # trigger timout and kill process in 5 seconds
# timer = threading.Timer(5, on_timeout, (proc, status_dict))
# timer.start()
# proc.wait()
# # in case we didn't hit timeout
# timer.cancel()
# print (status_dict)
# if not status_dict['timeout'] and proc.returncode == 100:
# succ += 1 # If returned 100 then success
# else:
# fail += 1 # Else Failed
# open('logfile', 'w').close() # Empties the file
# print ("Succ: %d , Fail: %d" % (succ, fail))
# NEVER STOP
currentLayer = 0
# while True:
# layerHeight = 0.1
layerHeight = 0.5
layerTime = 0.5
pauseBeforeLift = 0.5
pauseForSetpower = 0.5
pauseBeforeProject = 2
liftDistance = 2
# TURN OFF PROJECTOR
command = "set-projector-power 0"
print("command is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
# TURN OFF FAN
print("TURN OFF FAN WITH M107")
p.send_now("M107; turn off fan")
# TURN OFF HEATER
print("TURN OFF BED HEATER WITH M140 S0")
p.send_now("M140 S0; turn off bed")
command = "killall feh"
print("command is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
# SET FAN AT FULL SPEED
print("Set Fan at FULLSPEED with M106")
p.send_now("M106; set fan at full speed")
# SET BED TEMP TO 60 C
print("Set BED TEMP TO 60 C with M140 S60")
p.send_now("M140 S60; set bed temp to 60 C")
while True:
# HOME THE PRINTER
p.send_now("G28 X")
print ("HOMING")
time.sleep(20)
print ("HOMING COMPLETED!!")
for i in range(100):
#DON'T PRINT MORE THAN THIS HEIGHT, TOTAL
if (i+1)*layerHeight >= 39:
print ("max print distance reached!")
break
print("\n\n######## CURRENT LAYER IS #" + str(currentLayer+1))
# GO TO LAYER POSITION -- LIFT DISTANCE
p.send_now("G91; relative positioning")
p.send_now("G1 X" + str(liftDistance))
# GO TO LAYER POSITION -- LIFT DISTANCE
p.send_now("G91; relative positioning")
p.send_now("G1 X-" + str(liftDistance-layerHeight))
# 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/LightField/model-library/makerook_imgs/" + '%03d' % 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(pauseBeforeProject) + " seconds")
time.sleep(pauseBeforeProject)
# START PROJECTION
command = "set-projector-power 126"
print("command #" + str(i+1) + " is '" + command + "'")
return_code = subprocess.call(command, shell=True)
print(return_code)
print ("PROJECTION: " + str(layerTime) + " seconds")
time.sleep(layerTime)
command = "set-projector-power 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)
# PAUSE BEFORE LIFT
print ("PAUSE BEFORE LIFT: " + str(pauseBeforeLift) + " seconds")
time.sleep(pauseBeforeLift)
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
# # 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.