forked from Ridhwanluthra/NLMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_movement.py
130 lines (115 loc) · 2.8 KB
/
bot_movement.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
130
from gpiozero import Motor
#from gpiozero.Pin import
#import RPi.GPIO as GPIO
from encoders import d_move, refresh
ml = Motor(2, 3)
mr = Motor(14, 15)
ml.stop()
mr.stop()
"""
I am assuming that the initial location of the bot
is facing upwards at 0,0
the bot can make only 90 degree turns
"""
direction = 'n' # n,e,w,s for different locations that it is facing
usfront = 20
try:
# ADD SOMETHING TO DO WHEN US IS LESS THAN 5;
def forward():
if usfront <= 5:
print "error"
else:
ml.forward()
mr.forward()
def sstop():
ml.stop()
mr.stop()
def turn_left():
while d_move()[0] <= 20 and d_move()[1] <= 20:
ml.backward()
mr.forward()
sstop()
refresh()
def turn_right():
while d_move()[0] <= 20 and d_move()[1] <= 20:
ml.forward()
mr.backward()
sstop()
refresh()
def up():
look_up()
while d_move()[0] <= 20 and d_move()[1] <= 20:
forward()
sstop()
refresh()
def left():
look_left()
while d_move()[0] <= 20 and d_move()[1] <= 20:
forward()
sstop()
refresh()
def right():
look_right()
while d_move()[0] <= 20 and d_move()[1] <= 20:
forward()
sstop()
refresh()
def down():
look_down()
while d_move()[0] <= 20 and d_move()[1] <= 20:
forward()
sstop()
refresh()
def look_up():
global direction
if (direction == 'n'):
pass
elif (direction == 'e'):
turn_left()
elif (direction == 'w'):
turn_right()
elif (drection == 's'):
turn_left()
turn_left()
direction = 'n'
def look_down():
global direction
if (direction == 'n'):
turn_left()
turn_left()
elif (direction == 'e'):
turn_right()
elif (direction == 'w'):
turn_left()
elif (drection == 's'):
pass
direction = 's'
def look_left():
global direction
if (direction == 'n'):
turn_left()
elif (direction == 'e'):
turn_left()
turn_left()
elif (direction == 'w'):
pass
elif (drection == 's'):
turn_right()
direction = 'w'
def look_right():
global direction
if (direction == 'n'):
turn_right()
elif (direction == 'e'):
pass
elif (direction == 'w'):
turn_left()
turn_left()
elif (drection == 's'):
turn_left()
direction = 'e'
except KeyboardInterrupt:
print "cleaning"
finally:
#GPIO.cleanup()
print"check it"