-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (54 loc) · 1.66 KB
/
main.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
import switch
import servo
import vision
import thread
import time
SLEEP_PERIOD = .05
# States
WAITING = 1
BALL_FOUND = 2
DOG_FOUND = 3
class Robot:
def __init__(self):
# TODO add the correct pin numbers here
self.state = WAITING
self.dog_location = None
self.hammer_servo = servo.Servo(27)
print "hammer started"
self.base_servo = servo.Servo(22)
print "base started"
self.switch = switch.Switch(11, self.switch_triggered)
print "switch started"
self.dog_detector = vision.Detector(self.dog_found)
def switch_triggered(self, sender, value):
if value == 1:
print "ball faound"
self.state = BALL_FOUND
def dog_found(self, location):
print location
self.dog_location = location
if self.state == BALL_FOUND:
self.state = DOG_FOUND
def original_location(self):
return self._original_location
def throw_location(self):
throw_location = "left" if self.dog_location == "right" else "right"
self._original_location = self.dog_location
return throw_location
def run(self):
while True:
print "CURRENT STATE IS " + str(self.state)
time.sleep(SLEEP_PERIOD)
if self.state == DOG_FOUND:
self.base_servo.spin(self.throw_location(), 10)
time.sleep(5)
self.hammer_servo.spin("hammer", 33)
time.sleep(5)
self.base_servo.spin(self.original_location(), 10)
time.sleep(5)
self.state = WAITING
def main():
print "Starting robot"
robot = Robot()
robot.run()
main()