-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.py
120 lines (97 loc) · 5.07 KB
/
robot.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import subprocess
import wpilib
import config
import OrphanCommand
# import soul
from DataLogger import DataLogger
from wpilib.buttons import JoystickButton
from wpilib.command import Scheduler, CommandGroup
from DriveSubsystem import DriveSubsystem
from ShooterSubsystem import ShooterSubsystem
from TomahawkSubsystem import TomahawkSubsystem
from TeleopCommand import TeleopCommand
from AutonomousCommand import AutonomousCommand
from AutoDriveCommand import AutoDriveCommand
from AutoTargetCommand import AutoTargetCommand
from AutoChevalDeFriseCommand import AutoChevalDeFriseCommand
class MyRobot(wpilib.IterativeRobot):
def __init__(self):
super().__init__()
self.pdp = wpilib.PowerDistributionPanel()
self.subsystems = {}
self.datalogger = DataLogger(logfile=open("robot.log", mode='a'),
curtime=wpilib.DriverStation.getInstance().getMatchTime)
def robotInit(self):
subprocess.Popen("/home/lvuser/grip", shell=True) # Start GRIP process
self.subsystems['drive'] = DriveSubsystem()
self.subsystems['shooter'] = ShooterSubsystem(self)
self.subsystems['tomahawk'] = TomahawkSubsystem()
self.teleopCommand = TeleopCommand(self)
self.autonomousCommand = CommandGroup()
self.autonomousCommand.setTimeout(15)
self.autoPositionChooser = wpilib.SendableChooser()
self.autoPositionChooser.addDefault("Position 1", 1)
self.autoPositionChooser.addObject("Position 2", 2)
self.autoPositionChooser.addObject("Position 3", 3)
self.autoPositionChooser.addObject("Position 4", 4)
self.autoPositionChooser.addObject("Position 5", 5)
wpilib.SmartDashboard.putData("PositionChooser", self.autoPositionChooser)
self.autoDefenseChooser = wpilib.SendableChooser()
self.autoDefenseChooser.addDefault("Nothing", None)
self.autoDefenseChooser.addObject("Reach", AutoDriveCommand(self, power=.5, dist=100))
self.autoDefenseChooser.addObject("Rough Terrain", AutoDriveCommand(self, power=.7, dist=200))
self.autoDefenseChooser.addObject("Rock Wall", AutoDriveCommand(self, power=.9, dist=200,
holdpos=config.articulateAngleHigh))
self.autoDefenseChooser.addObject("Moat", AutoDriveCommand(self, power=-.9, dist=270))
self.autoDefenseChooser.addObject("Ramparts", AutoDriveCommand(self, power=-.7,
dist=200,
holdpos=config.articulateAngleHigh))
self.autoDefenseChooser.addObject("Low Bar", AutoDriveCommand(self, power=.6,
dist=200,
holdpos=config.articulateAngleLow))
self.autoDefenseChooser.addObject("Portcullis", AutoDriveCommand(self, power=.6,
dist=200,
holdpos=config.articulateAngleLow))
self.autoDefenseChooser.addObject("Cheval de Frise", AutoChevalDeFriseCommand(self))
wpilib.SmartDashboard.putData("DefenseChooser", self.autoDefenseChooser)
self.autoActionChooser = wpilib.SendableChooser()
self.autoActionChooser.addDefault("Nothing", None)
self.autoActionChooser.addObject("Aim", AutoTargetCommand(self, shoot=False))
self.autoActionChooser.addObject("Shoot", AutoTargetCommand(self, shoot=True))
wpilib.SmartDashboard.putData("ActionChooser", self.autoActionChooser)
wpilib.SmartDashboard.putNumber("Aim at", 150)
self.datalogger.ready()
def teleopPeriodic(self):
Scheduler.getInstance().run()
self.datalogger.log_data()
def autonomousPeriodic(self):
Scheduler.getInstance().run()
self.datalogger.log_data()
def teleopInit(self):
self.autonomousCommand.cancel()
self.jsAutoTargetButton = JoystickButton(wpilib.Joystick(2), 8)
self.autoTargetCommand = AutoTargetCommand(self)
self.teleopCommand.start()
self.autoTargetCommand.start()
def autonomousInit(self):
defense = self.autoDefenseChooser.getSelected()
action = self.autoActionChooser.getSelected()
position = self.autoPositionChooser.getSelected()
k = []
if defense is not None:
k += [defense]
if action is not None:
action.setPosition(position)
k += [action]
for cmd in k:
cmd.setParent(None)
self.autonomousCommand = AutonomousCommand(k)
self.autonomousCommand.start()
def autoAimShooter(self):
shooter = self.subsystems['shooter']
drive = self.subsystems['drive']
pitch, yawDelta = shooter.calculateShooterParams()
drive.driveAngle += yawDelta
shooter.setArticulateAngle(pitch)
if __name__ == '__main__':
wpilib.run(MyRobot)