Пример #1
0
 def test_pen_updown(self):
     op = parse_gcode(GCode.pen_down(), current_position=[0, 0])
     self.assertEqual(PenMode.PEN_DOWN, op.pen_mode)
     op = parse_gcode(GCode.pen_up(), current_position=[0, 0])
     self.assertEqual(PenMode.PEN_UP, op.pen_mode)
     self.assertEqual(0, op.get_pen_distance())
     op.get_duration()
Пример #2
0
def draw_main(args):
    commands = []
    with open(args.gcode) as r:
        for line in r:
            commands.append(line.strip())

    gcode_rect = get_gcode_bounds(commands)
    x_min, x_max, y_min, y_max = gcode_rect.to_xxyy()

    print('Bounds: {} {} {} {}'.format(x_min, x_max, y_min, y_max))

    # Maybe in the future we support some sort of 'glitch mode?'
    if not args.skip_bounds_check:
        if x_min < 0.0 or x_max > DRAW_WIDTH_EU:
            raise RuntimeError('Invalid x boundaries! {} {}'.format(
                x_min, x_max))
        if y_min < 0.0 or y_max > DRAW_HEIGHT_EU:
            raise RuntimeError('Invalid y boundaries: {} {}'.format(
                y_min, y_max))

    trace_bounds_commands = [
        GCode.move_fast([0, 0]),
        GCode.move_fast([x_min, y_min]),
        GCode.move_fast([x_max, y_min]),
        GCode.move_fast([x_max, y_max]),
        GCode.move_fast([x_min, y_max]),
        GCode.move_fast([x_min, y_min]),
    ]

    all_commands = trace_bounds_commands

    all_commands.append(GCode.set_feed_rate(args.feed_rate))

    if args.frame:
        all_commands += [
            GCode.move_fast(0, 0),
            GCode.pen_down(),
            GCode.move_linear([x_min, y_min], 2000),
            GCode.move_linear([x_max, y_min], 2000),
            GCode.move_linear([x_max, y_max], 2000),
            GCode.move_linear([x_min, y_max], 2000),
            GCode.move_linear([x_min, y_min], 2000),
            GCode.pen_up(),
        ]

    if not args.test:
        all_commands += commands

    all_commands.append(GCode.move_home())

    if args.no_pen:
        all_commands = [
            command for command in commands
            if not GCode.is_pen_down_command(command)
        ]

    run_gcode(all_commands, device=args.device)
Пример #3
0
def move_main(args):
    run_gcode([GCode.move_fast([args.x, args.y])], device=args.device)
Пример #4
0
def down_main(args):
    run_gcode([GCode.pen_down()], device=args.device)
Пример #5
0
def up_main(args):
    run_gcode([GCode.pen_up()], device=args.device)
Пример #6
0
 def test_partial_arc(self):
     op = parse_gcode(GCode.move_arc([1, 1], [2, 2], [1, 2]),
                      current_position=[1, 1])
     self.assertEqual(0.5 * np.pi, op.get_pen_distance())
     self.assertListEqual([1, 2, 1, 2], op.get_aabb().get_rect().to_xxyy())
Пример #7
0
 def test_move_linear(self):
     op = parse_gcode(GCode.move_linear([1, 1]), current_position=[0, 0])
     self.assertListEqual([0, 1, 0, 1], op.get_aabb().get_rect().to_xxyy())
     self.assertEqual(2**0.5, op.get_pen_distance())