-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoa.py
More file actions
53 lines (32 loc) · 1.7 KB
/
Copy pathoa.py
File metadata and controls
53 lines (32 loc) · 1.7 KB
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
from myro import *
import functions
tolerance = 300
def blocked():
return (getObstacle()[0] >= tolerance)
print("Started")
functions.moveUntilBlocked(0.2, 500) #move forward until an obstacle sensor reaches 500
while(blocked()):
functions.turn(10) #the robot will keep turning right until it becomes parallel with the box
functions.turn(50) #an additional little turn to avoid collisions with the box; now the robot should be parallel with the box's side
timeOffCourse = 0
i = 0
for i in range(0, 2): #go through the 'turn left when safe to do so' process twice
turnBlocked = True #assume turn is blocked
while(turnBlocked):
if(i == 0):
timeOffCourse += 1 #if going laterally, add time spent going the other way later
functions.moveForward(0.7, 1) #move forward slightly
functions.turn(-90) #turn left
if(not(blocked())):
functions.turn(-45) #if unblocked, turn left to face the box more
if(not(blocked())):
turnBlocked = False
functions.turn(45) #if still unblocked, undo 45 degree turn and move forward
else:
functions.turn(135) #if blocked, undo 90 and 45 degree turn
else:
functions.turn(90) #if blocked, undo 90 degree turn
functions.moveForward(0.7, timeOffCourse) #move amount displaced laterally
functions.turn(90) #turn right
functions.moveForward(1, 1) #robot has avoided obstacle, and can now celebrate by moving forward
print("Done")