Exemple #1
0
def generate_prn(out, paths, title):
    doc = Document(title)
    dpi = doc.getResolution()
    for path in paths:
        cut = Cut(4, 100, 50)
        # Convert to doc's resolution.
        cut.points = [Vector2(p.x*dpi/DPI, p.y*dpi/DPI) for p in path]
        doc.addCut(cut)

    epilog.generate_prn(out, doc)
Exemple #2
0
def vector_test():
    doc = Document("Untitled-1")

    cut = Cut(4, 100, 50)
    cut.points = [
        Vector2(1200, 1300),
        Vector2(1400, 1500),
    ]
    doc.addCut(cut)

    cut = Cut(4, 100, 50)
    cut.points = [
        Vector2(1200 + 600 * 10, 1300 + 200),
        Vector2(1400 + 600 * 10, 1500 + 200),
    ]
    doc.addCut(cut)

    cut = Cut(50, 100, 50)
    cut.points = [
        Vector2(1200 + 200, 1300 + 200),
        Vector2(1400 + 200, 1500 + 200),
    ]
    doc.addCut(cut)

    return doc
Exemple #3
0
def find_cut(x, y, current_cuts):
    global best_score
    global best_cuts
    for x0 in range(x, C):
        for y0 in range(y, R):
            for x1 in range(x0, C):
                for y1 in range(y0, R):
                    if (x1 - x0 + 1) * (y1 - y0 + 1) <= H:
                        cut = Cut(Point(x0, y0), Point(x1, y1))
                        if cut.valid() and not contains(current_cuts, cut):
                            current_cuts.append(cut)
                            if approciate_way(current_cuts):
                                find_cut(x0, y0, current_cuts)
                                if score(current_cuts) > best_score:
                                    best_score = score(current_cuts)
                                    best_cuts = current_cuts.copy()
                            current_cuts.remove(cut)
Exemple #4
0
    def solve(self, goals, env, gvars, level):
        goal = goals.pop(0)

        if isinstance(goal, bool):
            return self.bcprove(goals, env, gvars, level + 1)
        elif isinstance(goal, tuple) and goal[0].name is "cut":
            goals.insert(0, goal[1])
            result = self.bcprove(goals, env, gvars, level + 1)
            Cut().set()

            return result

        key = self.make_key(goal)
        iteratorBcr = self.bcr[key].__iter__()

        for kbRule in iteratorBcr:
            freshRule = copy.deepcopy(kbRule)
            freshvars = self.get_variables(freshRule)

            for i in freshvars:
                i.rename(level)

            newenv = {}
            newenv.update(env)
            test = True

            for i in range(len(freshRule[0])):
                q = Unify().unify(freshRule[0][i], goal[i], newenv)

                if q is None:
                    test = False
                    break
                else:
                    newenv.update(q)

            if test:
                newgoals = copy.deepcopy(goals)
                newgoals.insert(0, freshRule[1])
                result = self.bcprove(newgoals, newenv, gvars, level + 1)

                if Cut().test() or result:
                    return result

        return False
Exemple #5
0
    def prove(self, goals):
        print "?-", Printer().deref(goals, {})

        Cut().reset()
        gvars = self.get_variables(goals)
        result = self.bcprove(goals, {}, gvars, 0)

        print Printer().deref(result, {}), "\n"

        return result
Exemple #6
0
    def __init__(self,
                 features,
                 time,
                 fps,
                 sound_dict,
                 hl_max_size=-1,
                 hl_min_size=-1):
        Cut.__init__(self, features, time, fps, sound_dict, hl_max_size,
                     hl_min_size)

        self.W = None
        self.end = None
        self.start = None
        self.end_cut = None
        self.best = dict()
        self.simil_labels = [
            'plateau_start', 'plateau_end', 'valley_start', 'hill_top',
            'valley_pit'
        ]
Exemple #7
0
                            current_cuts.remove(cut)


def main():
    print('R = {}, C = {}, L = {}, H = {}'.format(R, C, L, H))
    print(pizza)
    current_cuts = []

    for x0 in range(0, C):
        for y0 in range(0, R):
            find_cut(x0, y0, current_cuts.copy())

    with open(OUTFILENAME, 'w') as outfile:
        print(best_score)
        outfile.write(str(len(best_cuts)))
        outfile.write('\n')
        for cut in best_cuts:
            outfile.writelines('{} {} {} {}'.format(cut.begin.y, cut.begin.x,
                                                    cut.end.y, cut.end.x))
            outfile.write('\n')


if __name__ == '__main__':
    best_score = 0
    best_cuts = []
    all_pizza = Cut(Point(0, 0), Point(C - 1, R - 1))
    all_mushrooms = all_pizza.count('M')
    all_tomatoes = all_pizza.count('T')
    all_square = all_pizza.square()
    main()
Exemple #8
0
TFD_PORT = "/dev/ttyS36"

endmill = EndMill(3, 3.175e-3, 3.175e-3, 12e-3, 5e-3)

fixed_conditions = Conditions(D=1e-3,
                              W=1e-3,
                              f_r=0.001,
                              w=300,
                              endmill=endmill)

cut = Cut(
    MACHINE_PORT,
    SPINDLE_PORT,
    TFD_PORT,
    endmill,
    60e-3,
    50.8e-3,
    5e-3,
    300,
    initial_z=0.5e-3,
    save_as="sweep-alu-1_4-v2",
)

f_r_range = np.linspace(2e-3, 0.01, 6)
W_range = np.linspace(1e-3, 3.175e-3 * 1.8, 6)

cut.face_layer(D=0.3e-3)

cut.begin_layer(D=1e-3)

for f_r in f_r_range:
    for W in W_range:
Exemple #9
0
def ammp(MACHINE_PORT, SPINDLE_PORT, TFD_PORT, D, W, f_r, f_r_clearing, w,
         START_DEPTH, START_FACE_D, ENDMILL, D_A, N, X_TRAVEL, CONFIDENCE_RATE,
         USE_OLD_DATA, NAME, MODEL, EQUATIONS, OPTIMIZER, MACHINE):
    """
    Runs the optimizing system. 
    System starts out by facing the stock flat (since we need to make sure the endmill bottom perfectly corresponds to the start of the stock).
    Then does a bootstrap cut to initialize the model.
    Then starts optimizing process itself.

    Args:
        MACHINE_PORT: port name for machine
        SPINDLE_PORT: port name for spindle
        TFD_PORT: port name for tool force dyno
        D: depth of cut (always unchanging...)
        W: initial width of cut for bootstrap
        f_r: initial feedrate for bootstrap
        f_r_clearing: feedrate for facing and cutting start groove
        w: spindle speed
        START_DEPTH: offset depth to start cutting at
        START_FACE_D: how deep to face stock before starting ammp runs
        ENDMILL: endmill parameters
        D_A: maximum allowable deflection
        N: total number of cuts to take, including bootstrap cuts
        X_TRAVEL: travel in the x direction
        CONFIDENCE_RATE: confidence progression during bootstrap cuts
        USE_OLD_DATA: whether or not to use datapoints from an older run. change this to run name to use this feature
        NAME: name to save to / name to draw data from if doing a fake cut
        MODEL: model class to use
        EQUATIONS: equations to use in optimizer
        OPTIMIZER: optimizer to use
        MACHINE: machine characteristics
    """
    FIXED_CONDITIONS = Conditions(D=D, W=W, f_r=f_r, w=w, endmill=ENDMILL)

    logging.info("Initializing all structures")

    cut = None
    if FAKE:
        cut = ReplayCut(NAME, MODEL(), *EQUATIONS, [0, 0], [0.1, 2])
    else:
        cut = Cut(MACHINE_PORT,
                  SPINDLE_PORT,
                  TFD_PORT,
                  ENDMILL,
                  X_TRAVEL,
                  50.8e-3,
                  f_r_clearing,
                  w,
                  START_DEPTH,
                  NAME,
                  graceful_shutdown=True)
    model = MODEL()
    optimizer = OPTIMIZER(model, MACHINE, D_A, FIXED_CONDITIONS)

    logging.info("Beginning facing operation, creating starting groove")
    if START_FACE_D:
        cut.face_layer(START_FACE_D)
    cut.begin_layer(D)

    logging.info("First bootstrap cut to obtain a basic characterization")

    conditions_conservative = Conditions(D, W, f_r, w, ENDMILL)
    datum = cut.cut(conditions_conservative, save=True, auto_layer=True)
    model.ingest_datum(datum)

    logging.info("After bootstrap cut, model params are actually at: " +
                 ", ".join(["{:.5e}".format(p) for p in model.params]))
    if USE_OLD_DATA and not FAKE:
        with shelve.open(os.path.join("saved_cuts", "shelve")) as db:
            model.ingest_data(db[USE_OLD_DATA])
    logging.info("Partially optimized bootstrap cuts starting now")

    # start optimizing, but only slowly start accepting new datums
    confidences = list(CONFIDENCE_RATE) + [1] * (N - len(CONFIDENCE_RATE))
    for i, confidence in enumerate(confidences):
        logging.info("------------------ Run #" + str(i + 1) +
                     " -----------------------")
        logging.info("Confidence at    : " + str(confidence))
        conditions_optimized = optimizer.optimize(verbose=True)
        logging.info("Optimized        : " + str(conditions_optimized))
        conditions_compromise = conditions_conservative.compromise(
            conditions_optimized, confidence)
        logging.info("Compromised      : " + str(conditions_compromise))
        logging.info("Model guesses    : " +
                     str(model.predict_one(conditions_compromise)))
        datum = cut.cut(conditions_compromise, save=True, auto_layer=True)
        logging.info("Datum obtained   : " + str(datum))
        model.ingest_datum(datum)
        logging.info("Params updated to: " +
                     ", ".join(["{:.5e}".format(p) for p in model.params]))

    if FAKE:
        logging.info("Actual cut params: " +
                     ", ".join(["{:.5e}".format(p) for p in cut.params]))