-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovements.py
130 lines (99 loc) · 1.69 KB
/
movements.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from time import sleep
import RPi.GPIO as io
import checks as chk
io.setmode(io.BCM)
io.setwarnings(False)
# Left
io.setup(2,io.OUT)
io.setup(3,io.OUT)
# Right
io.setup(4,io.OUT)
io.setup(5,io.OUT)
all = [2, 3, 4, 5]
def l_fwd():
io.output(2,0)
io.output(3,1)
def r_fwd():
io.output(4,0)
io.output(5,1)
def l_bwd():
io.output(2,1)
io.output(3,0)
def r_bwd():
io.output(4,1)
io.output(5,0)
def stop():
io.output(all, 0)
def fwd():
l_fwd()
r_fwd()
def bwd():
l_bwd()
r_bwd()
def right():
l_fwd()
r_bwd()
def left():
l_bwd()
r_fwd()
def right_15():
right()
sleep(0.1)
def left_15():
left()
sleep(0.1)
def right_45():
right()
sleep(.3)
def left_45():
left()
sleep(.3)
def right_90():
right()
sleep(0.7)
def left_90():
left()
sleep(0.7)
def turn_180():
right()
sleep(1.25)
def cleanup():
io.cleanup()
io.setmode(io.BCM)
def path_not_clear():
print("Front is not clear")
if chk.turn_count():
when_stuck()
else:
pick_a_side()
def path_clear():
while True:
if chk.front_3():
sleep(0.1)
print("Front is clear.")
fwd()
else:
path_not_clear()
def when_stuck():
print("Seemingly stuck.")
if chk.sides == 'left':
left_45()
stop()
sleep(0.2)
else:
right_45()
stop()
sleep(0.2)
def pick_a_side():
stop()
sleep(0.5)
side = chk.sides()
if side == "back":
turn_180()
elif side == "left":
left_15()
elif side == "right":
right_15()
else:
bwd()
sleep(0.2)