Commit 43e87ad1 authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

bulk run decmcts, only slice if not already sliced (#64)

parent 91f924bf
import sys
import subprocess as sp
import os
import decmcts
import gcode2contour as gc
import utils as tu
from math import pi
default_config = '../config/Slic3rConfig.ini'
def slice_stls(filenames, out_address, config=default_config, overwrite=False):
"""
Slice a list of STLs, construct gcode files with same name
"""
gcodes = []
for f in filenames:
# create gcode file
object_name = f.split('/')[-1].split('.')[0]
out_fname = out_address + object_name + '.gcode'
# if file already exist and not overwriting
if not overwrite and os.path.exists(out_fname):
gcodes.append(out_fname)
continue
# if file already exists, and we want to overwrite
elif overwrite and os.path.exists(out_fname):
os.remove(out_fname)
# run slicer
command = 'slic3r ' + f + \
' --load ' + config + \
' -o ' + out_fname
sp.run(command.split())
gcodes.append(out_fname)
return gcodes
def batch_decmcts(gcode_files, n_layers, mcts_nodes_per_layer):
"""
runs decmcts on multiple gcode files
"""
# create one env for all runs
home = [0, -pi/2, pi/4, -pi/4, -pi/2, -pi/4]
env_desc2 = tu.read_env('calibrations/r1_tforms.yaml',
'calibrations/r2_tforms.yaml')
env = tu.SimEnv(env_desc=env_desc2, gui=False, home=home)
for f in gcode_files:
model = f.split('/')[-1].split('.')[0]
tracker = tu.get_tracker(model)
print("\n####################################")
print("Runnning for model {}".format(model))
print("####################################")
try:
cs, plan = decmcts.decmcts(tracker,
env,
n_layers=n_layers,
mcts_nodes=mcts_nodes_per_layer
)
plan.visualise()
except:
print("FAILED TO COMPLETE ON MODEL {}".format(model))
if __name__ == '__main__':
# read stl files to slice
stl_add = '../stls/'
filenames = [stl_add + 'cylinder.stl', stl_add + 'flexirex.stl']
out = './gcode/'
# slice
gcode_files = slice_stls(filenames, out)
batch_decmcts(gcode_files, 2, 500)
...@@ -232,9 +232,8 @@ def reward(data, states): ...@@ -232,9 +232,8 @@ def reward(data, states):
def decmcts(contour_tracker, def decmcts(contour_tracker,
env_desc, env,
n_layers=None, n_layers=None,
gui=False,
mcts_nodes=100, # no. of nodes to grow on each tree mcts_nodes=100, # no. of nodes to grow on each tree
comm_n=10, # no. of action dists to communicate comm_n=10, # no. of action dists to communicate
c_traj_save_file=False, c_traj_save_file=False,
...@@ -251,7 +250,6 @@ def decmcts(contour_tracker, ...@@ -251,7 +250,6 @@ def decmcts(contour_tracker,
last_comp_print_height = 0 last_comp_print_height = 0
print_block = None print_block = None
env = tu.SimEnv(env_desc=env_desc, gui=gui, home=home)
plan = tu.Plan(env) plan = tu.Plan(env)
# save calculated trajectories for contours between loops # save calculated trajectories for contours between loops
...@@ -262,7 +260,7 @@ def decmcts(contour_tracker, ...@@ -262,7 +260,7 @@ def decmcts(contour_tracker,
c_traj = pickle.load(f) c_traj = pickle.load(f)
except FileNotFoundError: except FileNotFoundError:
print("File does not exist, will create new one") print("File does not exist, will create new one")
n_arms = env_desc.n_arms n_arms = env.numRobots
arm_done = [False]*n_arms arm_done = [False]*n_arms
update_savefile = False update_savefile = False
...@@ -506,14 +504,13 @@ if __name__ == "__main__": ...@@ -506,14 +504,13 @@ if __name__ == "__main__":
# 2arms real calibration # 2arms real calibration
env_desc2 = tu.read_env('calibrations/r1_tforms.yaml', env_desc2 = tu.read_env('calibrations/r1_tforms.yaml',
'calibrations/r2_tforms.yaml') 'calibrations/r2_tforms.yaml')
env = tu.SimEnv(env_desc=env_desc2, gui=False, home=home)
# decmcts plan first n contours # decmcts plan first n contours
c_traj_file = "gcode/" + model + ".c_traj" c_traj_file = "gcode/" + model + ".c_traj"
cs, plan = decmcts(tracker, cs, plan = decmcts(tracker,
env_desc2, env,
n_layers=2, n_layers=2,
c_traj_save_file=c_traj_file,
gui=False,
mcts_nodes=1000 mcts_nodes=1000
) )
visualiseCombinedSchedule(cs) visualiseCombinedSchedule(cs)
......
This diff is collapsed.
This diff is collapsed.
import sys
import subprocess as sp
import os
default_config = '../config/Slic3rConfig.ini'
def slice_stls(filenames, out_address, config=default_config):
"""
Slice a list of STLs, construct gcode files with same name
"""
gcodes = []
for f in filenames:
# create gcode file
object_name = f.split('/')[-1].split('.')[0]
out_fname = out_address + object_name + '.gcode'
command = 'slic3r ' + f + \
' --load ' + config + \
' -o ' + out_fname
sp.run(command.split())
gcodes.append(out_fname)
return gcodes
if __name__ == '__main__':
# read stl files to slice
filenames = ['cylinder.stl', 'flexirex.stl']
out = '../src/gcode/bulk/'
# slice
gcode_files = slice_stls(filenames, out)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment