-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper.py
102 lines (81 loc) · 2.36 KB
/
stepper.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#
# Copyright (c) 2014 David Jander
#
# vim: set tabstop=4:
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
from audiostep import audiostep
from gpio import AsyncGPInput
class StepperCluster(object):
def __init__(self, audiodev, dim, cfg, esw):
self.cfg = cfg
self.invert = [1 - int(x) * 2 for x in cfg.settings["invert_motor"]]
self.audio = audiostep(cfg, audiodev, dim, esw)
cfb = self.cfg.settings["current_feedback"]
if cfb:
self.audio.set_amplitude_dc(1.0)
else:
self.audio.set_amplitude_dc(0.3)
self.dim = dim
self.set_speed_scale(1.0)
self.set_max_feedrate(cfg.settings["max_feedrate"] / 60.0)
def connect_cmd_buffer(self, buf):
self.audio.connect_cmd_buffer(buf)
def pull_cmd_buffer(self):
return self.audio.pull_cmd_buffer()
def flush_queue(self):
self.audio.flush_queue()
def set_speed_scale(self, ss):
self.speed_scale = ss
self.audio.set_speed_scale(ss)
def set_max_feedrate(self, limit):
if limit:
self.max_feedrate = limit
self.audio.set_max_feedrate(limit)
def handle_command(self, obj):
cmd = obj[0]
pos = obj[1]
if cmd == "feedrate":
rate = pos
self.set_feedrate(rate)
elif cmd == "feedrate3":
rate = pos
self.set_feedrate3(*rate)
elif cmd == "position":
self.set_destination(pos)
elif cmd == "set_position":
if pos is None:
self.audio.set_home()
else:
self.audio.set_position(pos)
else:
print("SC: Unknown object:", repr(obj))
def set_feedrate(self, rate):
self.audio.set_feedrate(rate, rate, rate)
def set_feedrate3(self, begin, high, end):
self.audio.set_feedrate(begin, high, end)
def set_destination(self, pos):
self.audio.set_destination(pos)
def get_position(self):
return self.audio.get_position()
def set_position(self, pos):
self.audio.set_position(pos)
def process_one_move(self):
self.audio.process_one_move()
def zero_output(self):
self.audio.zero_output()
def close(self):
self.audio.close()
def stop(self):
self.audio.stop()
def restart(self):
self.audio.restart()
def cancel_destination(self):
self.audio.cancel_destination()
def fileno(self):
return self.audio.fileno()
def write_more(self):
return self.audio.write_more()