Commit 65556742 authored by Jayant Khatkar's avatar Jayant Khatkar

bulk run script functional (#64)

parent dddf55ef
####################################
Runnning for model Ernesto_Che_Guevara_in_style_Voronoi-ascii
----
Reading Gcode file
Running Dec-MCTS planner
FAILED TO COMPLETE DEC_MCTS ON MODEL Ernesto_Che_Guevara_in_style_Voronoi-ascii
Running Greedy planner
Greedy plan successfully created, saving plan and stats
Running Zone Blocking planner
Zone blocking plan successfully created, saving plan and stats
####################################
Runnning for model Ernesto_Che_Guevara_in_style_Voronoi-ascii
----
Reading Gcode file
Running Dec-MCTS planner
Dec-MCTS plan successfully created, saving plan and stats
Running Greedy planner
FAILED TO COMPLETE GREEDY ON MODEL Ernesto_Che_Guevara_in_style_Voronoi-ascii
Running Zone Blocking planner
Zone blocking plan successfully created, saving plan and stats
Ernesto_Che_Guevara_in_style_Voronoi-ascii:
decmcts:
planning_time: 526.853355884552
print_time: '2081.4001430572853'
total_time: '3583.6980511533625'
every_nth_layer: 20
zoneblocking:
planning_time: 7.67650032043457
print_time: '338.5545063351272'
total_time: '304.73688874073866'
......@@ -3,6 +3,7 @@ import subprocess as sp
import os
from math import pi
import yaml
import time
import decmcts
import greedy
......@@ -15,13 +16,14 @@ def batch_run(
gcode_files,
output_notes_file,
output_stats_file,
layers,
plan_save_dir,
nth_layer,
mcts_nodes_per_layer):
"""
runs various planning algos on multiple gcode files
"""
notes = open(output_notes_file, 'a')
stats = open(output_stats_file, 'w')
stat_file = open(output_stats_file, 'w')
# create one env for all runs
home = [0, -pi/2, pi/4, -pi/4, -pi/2, -pi/4]
......@@ -30,38 +32,101 @@ def batch_run(
env = tu.SimEnv(env_desc=env_desc2, gui=False, home=home)
stats = {}
for f in gcode_files:
for model in models:
model = f.split('/')[-1].split('.')[0]
notes.write("\n####################################\n")
notes.write("Runnning for model {}\n".format(model))
notes.write("----\n")
notes.write("Reading Gcode file\n")
tracker = tu.get_tracker(model)
notes.write("\n####################################")
notes.write("Runnning for model {}".format(model))
notes.write("----")
stats[model] = {}
stats[model]['every_nth_layer'] = nth_layer
notes.write("Running Dec-MCTS planner\n")
try:
s_time = time.time()
plan = decmcts.decmcts(
env,
tracker,
nth_layer=nth_layer
)
e_time = time.time()
notes.write("Dec-MCTS plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_decmcts.plan")
stats[model]['decmcts'] = \
{'total_time': str(plan.len()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time}
except:
notes.write("FAILED TO COMPLETE DEC_MCTS ON MODEL {}\n".format(model))
notes.write("Running Greedy planner\n")
notes.write("Running Dec-MCTS planner")
try:
cs, plan = decmcts.decmcts(tracker,
s_time = time.time()
plan = greedy.greedy(
env,
n_layers=n_layers,
mcts_nodes=mcts_nodes_per_layer
tracker,
nth_layer=nth_layer
)
notes.write("plan successfully created, saving stats")
e_time = time.time()
notes.write("Greedy plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_greedy.plan")
stats[model] = {'total_time': plan.len(),
'print_time': plan.extrusion_time()}
stats.write(yaml.dump(stats))
stats[model]['greedy'] = \
{'total_time': str(plan.len()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time}
except:
notes.write("FAILED TO COMPLETE ON MODEL {}".format(model))
notes.write("FAILED TO COMPLETE GREEDY ON MODEL {}\n".format(model))
notes.write("Running Zone Blocking planner\n")
try:
s_time = time.time()
plan = zoneblocking.zoneblocking(
env,
tracker,
nth_layer=nth_layer
)
e_time = time.time()
notes.write("Zone blocking plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_zoneblocking.plan")
stats[model]['zoneblocking'] = \
{'total_time': str(plan.len()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time}
except:
notes.write("FAILED TO COMPLETE ZONE BLOCKING ON MODEL {}\n".format(model))
break
stat_file.write(yaml.dump(stats))
notes.close()
stats.close()
stat_file.close()
return
if __name__ == '__main__':
# read gcode files to plan for
stl_add = '../stls/'
gcode_files = [stl_add + 'cylinder.gcode', stl_add + 'flexirex.gcode']
# get model names to process
with open('models.txt', 'r') as f:
models = f.readlines()
for i in range(len(models)):
models[i] = models[i][:-1]
batch_run(gcode_files, 2, 500)
batch_run(
models,
'bulk.log',
'bulk.stats',
'plans',
20,
2000)
......@@ -400,6 +400,7 @@ def decmcts_layer(
last_js = plan.trajs[arm][-1].positions[-1]
stayput = tu.JTrajectory([last_js, last_js],[0,default_wait], arm)
if plan.appendTrajectory([stayput], arm)!=0:
print("cannot go home or stay put Logically possible but unlikely - TODO")
raise Exception("cannot go home or stay put Logically possible but unlikely - TODO")
additional_time_spent += default_wait
......@@ -433,7 +434,7 @@ def decmcts_layer(
continue
# if already at home, stay at home
if all(plan.getLastJoint(other_arm) == home):
print("Other arm is already home")
print("Other arm is already home, this should not occur !!!")
raise Exception(" this should not occur")
# Otherwise, go home
......@@ -444,10 +445,14 @@ def decmcts_layer(
athome = True
else:
# other arm cannot go home, send current arm home to make room
if all(plan.getLastJoint(arm) == home):
print("other arm cannot go home despite current arm already being home - this should not happen")
raise Exception("other arm cannot go home despite current arm already being home - this should not happen")
gohome = plan.plan_to(env.home, arm)
if gohome is not None and plan.appendTrajectory([gohome], arm)==0:
print("taking arm {} home since it cannot stay put".format(arm))
print("other arm {} cannot go home, taking arm {} home since it cannot stay put".format(other_arm, arm))
else:
print("Neither arm can go home!")
raise Exception("Neither arm can go home!")
last_js = plan.trajs[arm][-1].positions[-1]
......@@ -458,6 +463,7 @@ def decmcts_layer(
if gohome is not None and plan.appendTrajectory([gohome], arm)==0:
print("taking arm {} home since it cannot stay put".format(arm))
else:
print("Cannot stay put or go home!")
raise Exception("Cannot stay put or go home!")
......@@ -505,8 +511,10 @@ def decmcts(
plan = None
fin_home = False
print("Planning the following layers: {}".format(layers))
for i in layers:
print("PLANNING LAYER {}".format(i))
# take arms home if final layer
if i == layers[-1]:
......
......@@ -165,7 +165,10 @@ def greedy(sim_env, tracker, nth_layer=1, layers=None):
plan = None
fin_home = False
print("Planning the following layers: {}".format(layers))
for i in layers:
print("PLANNING LAYER {}".format(i))
# take arms home if final layer
if i == layers[-1]:
......
Ernesto_Che_Guevara_in_style_Voronoi-ascii
4WD_Shift_collar_-_Scaled-ascii
Base_145x145mm_12holes-ascii
bp_FJ6309_BP23248_FMA52740_Ethmoid_fixed-ascii
entrapment2
finalraptornormaltail-ascii
four_screws-ascii
ir_sensor_main-ascii
Kitchen_sponge_holder_small-ascii
mano_derch_right_hand-ascii
NEW_CORNER-ascii
orb_half_2-ascii
plannet_X_3
prop_v2-ascii
repaird_version._if_given_instructions_give_errors_3D_printed_Marble_Machine_2-ascii
Skulptur_012-ascii
Top-ascii
V1_Front
wind_wheel
zaa-ascii
flexirex
......@@ -10,7 +10,7 @@ import pickle
home = [0, -pi/2, pi/4, -pi/4, -pi/2, -pi/4]
def zoneblocking(
def zoneblocking_layer(
contours,
contour_tracker,
env,
......@@ -53,7 +53,7 @@ def zoneblocking(
for cid in contours:
# only select from contours in their zone
if contour_tracker[cid].pos[0][1] > 0 and arm == 0 or \
if contour_tracker[cid].pos[0][1] >= 0 and arm == 0 or \
contour_tracker[cid].pos[0][1] < 0 and arm == 1:
continue
......@@ -160,6 +160,37 @@ def zoneblocking(
return plan
def zoneblocking(sim_env, tracker, nth_layer=1, layers=None):
"""
plan whole print with greedy using greedy_layer
"""
if layers is None:
n_layers = len(tracker.layers)
layers = list(range(0, n_layers, nth_layer))
plan = None
fin_home = False
print("Planning the following layers: {}".format(layers))
for i in layers:
print("PLANNING LAYER {}".format(i))
# take arms home if final layer
if i == layers[-1]:
fin_home = True
plan = zoneblocking_layer(
tracker.layers[i],
tracker,
sim_env,
plan=plan,
finish_home=fin_home,
)
return plan
if __name__ == "__main__":
# Read gcode file
......@@ -176,7 +207,6 @@ if __name__ == "__main__":
env_desc2 = tu.read_env('calibrations/r1_tforms.yaml',
'calibrations/r2_tforms.yaml')
# Greedily plan first n contours
# plan first n contours
sim_env = tu.SimEnv(env_desc=env_desc2, gui=True, home=home)
plan = zoneblocking(tracker.layers[1], tracker, sim_env, finish_home=False)
plan = zoneblocking(tracker.layers[5], tracker, sim_env, plan=plan)
plan = zoneblocking(sim_env, tracker, nth_layer=20)
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