forked from VolumetricBio/printrun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makerook-print.py
executable file
·303 lines (205 loc) · 8.13 KB
/
makerook-print.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/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/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; setpower 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 = "setpower 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 = 1
# exposureTime = 1
# pauseBeforeLift = 1
# pauseBeforeProject = 2
# liftDistance = 2
# 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)
# HOME THE PRINTER
p.send_now("G28 X")
print ("HOMING")
z0 = 3
for i in range(238):
if i == 0:
# layerHeight = 0.1
layerHeight = 0.1
exposureTime = 10
pauseBeforeLift = 10
pauseBeforeExpose = 4
pauseToLoadResin = 15
liftDistance = 2
# GO TO LAYER POSITION -- LIFT DISTANCE
p.send_now("G91") # RELATIVE POSITIONING
p.send_now("G1 X" + str(z0))
p.send_now("G92 X0; you are now at z0")
print("YOU ARE NOW AT Z0, READY TO BEGIN PRINTING FTW")
# PAUSE BEFORE PROJECT
print ("PAUSE TO SET Z0: " + str(pauseBeforeLift) + " seconds")
time.sleep(pauseBeforeLift)
p.send_now("G90") # ABSOLUTE POSITIONING
p.send_now("G1 X30")
# PAUSE BEFORE PROJECT
print ("PAUSE TO LOAD RESIN: " + str(pauseToLoadResin) + " seconds")
time.sleep(pauseToLoadResin)
p.send_now("G1 X" + str(layerHeight))
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 = 2
# 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))
# 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/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(pauseBeforeExpose) + " seconds")
time.sleep(pauseBeforeExpose)
# START PROJECTION
command = "setpower 126"
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
# # 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.