-
Notifications
You must be signed in to change notification settings - Fork 0
/
autonomous.py
60 lines (53 loc) · 1.77 KB
/
autonomous.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
'''
Runs the auto routine. Called once.
'''
import wpilib
from networktables import NetworkTables
class Autonomous(object):
def __init__(self, drive, encoder, gyro, metabox, driverStation):
self.drive = drive
self.encoder = encoder
self.gyro = gyro
self.metabox = metabox
self.driverStation = driverStation
self.sd = NetworkTables.getTable('SmartDashboard')
self.state = 0
self.jawsCalibrated = False
def run(self):
##############
# Get target #
##############
if (self.driverStation.getGameSpecificMessage() == ''):
return False
else:
target = self.driverStation.getGameSpecificMessage()[0]
#############
# Calibrate #
#############
# Move elevator to top
if (self.metabox.isCalibrated == False):
self.metabox.calibrateSync()
else:
# Move jaws to bottom
if (self.jawsCalibrated == False):
if (self.metabox.calibrateJawsSync() == True):
self.jawsCalibrated = True
else:
self.metabox.jawsM.set(0)
########
# Move #
########
#print(target)
if ((target == 'L' and self.sd.getNumber('station', 1) == 1) or
(target == 'R' and self.sd.getNumber('station', 1) == 3)):
# go forward and dump cube
if (self.state == 0):
if (self.drive.toTime(4, 0.3)):
self.state += 1
if (self.state == 1):
if (self.metabox.openAuto(2)):
self.state += 1
else:
if (self.state == 0):
if (self.drive.toTime(4, 0.3)):
self.state += 1