-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachine.py
More file actions
84 lines (72 loc) · 2.45 KB
/
machine.py
File metadata and controls
84 lines (72 loc) · 2.45 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from pyaxidraw import axidraw
class Machine:
def __init__(self, port='/dev/tty.usbmodem14101', dry=False):
self.dry = dry
self.ad = axidraw.AxiDraw()
self.ad.interactive()
MILLIMETER_FLAG = 2
self.ad.options.units = MILLIMETER_FLAG
if not self.dry:
self.ad.connect()
else:
print('Running in DRY mode.')
def pen_up(self):
if not self.dry:
self.ad.penup()
return 'pen_up'
def pen_down(self):
if not self.dry:
self.ad.pendown()
return 'pen_down'
def line(self, pt):
if not self.dry:
self.ad.lineto(pt[0], pt[1])
return f'line {pt}'
def travel(self, pt):
if not self.dry:
self.ad.moveto(pt[0], pt[1])
return f'travel {pt}'
def disconnect(self):
if not self.dry:
self.ad.disconnect()
return 'disconnect'
def return_to_origin(self):
if not self.dry:
self.travel((0, 0))
return 'return_to_origin'
def plot_rect_hw(self, start_pt, height, width):
if not self.dry:
pt1 = (start_pt[0] + width, start_pt[1])
pt2 = (start_pt[0] + width, start_pt[1] + height)
pt3 = (start_pt[0], start_pt[1] + height)
self.travel(start_pt)
self.line(pt1)
self.line(pt2)
self.line(pt3)
self.line(start_pt)
self.pen_up()
return f'square at {start_pt} height {height} width {width}'
def generate_axidraw_instructions(self, filepath):
self.ad.plot_setup(filepath)
self.ad.options.preview = True
preview_svg, instructions = self.ad.plot_run(True)
return instructions
def generate_preview_svg(self, filepath):
self.ad.plot_setup(filepath)
self.ad.options.preview = True
self.ad.options.rendering = 3
self.ad.options.report_time = True
preview_svg, _ = self.ad.plot_run(True)
# TODO: use the time estimate values
# time_estimate = self.ad.time_estimate
# distance_total = self.ad.distance_total
# distance_pendown = self.ad.distance_pendown
return preview_svg
def plot_svg(self, filepath):
if not self.dry:
try:
self.ad.plot_setup(filepath)
self.ad.plot_run()
except Exception as e:
print(e)
return f'plotted {filepath}'