-
Notifications
You must be signed in to change notification settings - Fork 1
/
orient.py
66 lines (50 loc) · 1.03 KB
/
orient.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
from myro import *
from time import sleep
def turnRightNotch(notches=1):
for i in range(0, notches):
turnRight(0.25,0.2)
def turnLeftNotch():
turnLeft(0.25,0.25)
def orient():
totalNotches = 0
max = getObstacle()[1]
while 1:
turnRightNotch()
totalNotches += 1
curObs = getObstacle()[1]
if curObs < max and curObs == 0:
break
else:
max = curObs
max = 0
noMax = 0
while 1:
turnLeftNotch()
totalNotches -= 1
curObs = getObstacle()[1]
if curObs <= max and noMax == 1:
break
elif curObs < max and noMax == 0:
noMax += 1
max = curObs
else:
max = curObs
noMax = 0
turnRightNotch(2)
"""for i in range(CIRCLECOUNTS):
L,C,R = getObstacle()
obstaclevalues += [C]
turnRightNotch()
max = 0
index =0
for i in range(len(obstaclevalues)):
if obstaclevalues[i] > max:
max = obstaclevalues[i]
index = i
print "max=%d, index=%d" % (max, index)
turnRight(1,0.1*index)"""
return totalNotches
if __name__=="__main__":
initialize("/dev/tty.IPRE6-193907-DevB")
setIRPower(130)
orient()