-
Notifications
You must be signed in to change notification settings - Fork 0
/
motob.py
executable file
·59 lines (51 loc) · 1.92 KB
/
motob.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
from motors import Motors
from sensob import CameraSensob
from time import sleep
class Motob:
def __init__(self, bbcon):
self.bbcon = bbcon
self.values = []
self.motor = Motors()
self.photograph = False
self.camera=CameraSensob()
def update(self, motor_recommendation):
# Mottar en anbefaling fra bbcon og behaviors
self.values = motor_recommendation
self.operationlize()
def operationlize(self):
# Henter ut forste verdi fra anbefalinger, antall grader gis som andre vektor i self.values dersom anbefaling er
# 'l' eller 'r'
value=self.values[0]
print("Motor Recommendation = ", value)
if value == "f":
print("Forward")
self.motor.set_value([0.5, 0.5],0.15)
elif value == "l":
print("Left")
self.motor.set_value([-1,1], self.turn_n_degrees(self.values[1]))
elif value == "r":
print("Right")
self.motor.set_value([1,-1], self.turn_n_degrees(self.values[1]))
elif value == 'fl':
print('Left and forward')
self.motor.set_value([0.05, 0.35],0.15)
elif value == 'fr':
print('Right and forward')
self.motor.set_value([0.35, 0.05],0.15)
elif value == 't':
self.motor.set_value([-0.5, 0.5], 0.25)
self.motor.set_value([0.5, -0.5], 0.25)
print("Found red!")
self.motor.set_value([-1, 1], self.turn_n_degrees(180))
self.bbcon.photo_taken()
elif value == "s":
print("Stop")
self.motor.stop()
self.photograph = True
sleep(1)
elif value == 'p':
self.camera.update()
@staticmethod
def turn_n_degrees(deg):
# Returnerer antall sekunder motorene maa kjores paa full speed, henholdsvis frem og bak for aa tilsvare grader
return 0.0028 * deg