forked from VolumetricBio/printrun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathburn_in-noProjector.py
executable file
·215 lines (150 loc) · 5.62 KB
/
burn_in-noProjector.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
#!/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(10):
print("\n\n######## CURRENT CYCLE IS #" + str(currentLayer+1))
p.send_now("G90; absolute positioning")
p.send_now("G0 X50; move motor")
p.send_now("G0 X10; move motor")
print ("MOVE TO NEXT CYCLE")
currentLayer += 1
for i in range(10):
print("\n\n######## CURRENT CYCLE IS #" + str(currentLayer+1))
p.send_now("G90; absolute positioning")
p.send_now("G0 X30; move motor")
p.send_now("G0 X20; move motor")
print ("MOVE TO NEXT CYCLE")
currentLayer += 1
p.disconnect() # this is how you disconnect from the printer once you are done. This will also stop running prints.