-
Notifications
You must be signed in to change notification settings - Fork 0
/
justincase
65 lines (54 loc) · 1.73 KB
/
justincase
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
from discovery_bot import pins
from discovery_bot import Movement
from discovery_bot import Ultrasound
import time
import datetime
class Move:
def __init__(self, start = (0,0)):
self.location = start
self.x = start[0]
self.y = start[1]
self.movement = Movement()
def move(self, x ,y):
self.y += y
self.x += x
self.location = (self.x,self.y)
def timedSpin(self,spinTime,direction):
while time.time() < spinTime:
if (direction == 'left'):
self.movement.rotate_left();
elif (direction == 'right'):
self.movement.rotate_right()
self.movement.stop()
def turn(self,angle):
# 90 degrees of rotation comes to approx 0.66 seconds, 2 seconds = 270* of rotation on a smooth surface
angle = float(angle)
timeToSpin = angle*0.00740740741
spinTime = time.time() + timeToSpin
if (angle == 'left' or angle == -90 or angle == 270):
self.timedSpin(spinTime,'left')
elif (angle == 'right' or angle == 90 or angle == -270):
self.timedSpin(spinTime,'right')
elif (angle == 'around' or angle ==180):
self.timedSpin(spinTime,'right')
elif (angle == 360 or angle == 'fullspin'):
self.timedSpin(spinTime,'right')
elif (angle == 180):
self.timedSpin(time.time() + 1.3333333)
elif (angle > 0):
self.timedSpin(spinTime,'right')
else:
self.timedSpin(spinTime,'left')
def moveForward(self,distance):
forwardTime = time.time() + 5
while (time.time() < forwardTime):
self.movement.forward(100)
self.movement.stop()
#calculate the distance travelled in this time frame, by subtracting sensor closest wall twice, once in beggining once at the end
#then I will know the distance travelled per 5 seconds, etc
robot =Move()
s = raw_input()
robot.turn(90)
if (s =='s'):
robot.movement.stop()
exit()