-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.py
64 lines (48 loc) · 1.34 KB
/
motor.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
from pin import Pin
import time
DEFAULT_VELOCITY = 120
DEFAULT_WAIT = 0.5
DEFAULT_POSITION_STEP = 5
class Motor:
def __init__(self, directionIO, stepIO):
self.directionIO = Pin(directionIO, 'OUT')
self.stepIO = Pin(stepIO, 'OUT')
self.direction = False
self.velocity = DEFAULT_VELOCITY
self.default_wait = DEFAULT_WAIT
self.position = 0
self.turn = DEFAULT_POSITION_STEP
def set_direction(self, direction):
if direction == "F":
self.direction = True
else:
self.direction = False
self.directionIO.set_state(self.direction)
def step(self, counter, direction):
self.set_direction(direction)
self.do_step(counter)
def do_step(self, counter):
while counter > 0:
self.send_step()
counter -=1
def send_step(self):
self.stepIO.send_signal()
self.wait_time()
def wait_time(self):
time.sleep(self.default_wait / self.velocity)
def next_position(self):
self.step(self.turn, "F")
self.position += 1
def back_position(self):
self.step(self.turn, "B")
self.position -= 1
def move_to(self, destination):
if destination != self.position:
if destination > self.position:
self.next_position()
else:
self.back_position()
self.move_to(destination)
class Nozzle(Motor):
def do_print(self):
self.step(self.turn, "F")