bulk_test.py 2.42 KB
Newer Older
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
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)
53
    decmcts_stats = {}
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

    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
                    )
69
70
71
72
73
74
            #plan.visualise()

            decmcts_stats[model] = {'total_time': plan.len(),
                    'print_time': plan.extrusion_time()}
            print(decmcts_stats[model])

75
76
77
78
79
80
81
82
83
84
85
86
87
88
        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)