This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
robot.py
executable file
·103 lines (72 loc) · 2.95 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
#!/usr/bin/env python3
from commands2 import TimedCommandRobot
from wpilib._impl.main import run
from wpilib import RobotBase, DriverStation
from custom import driverhud
import controller.layout
import subsystems
import shutil, sys, os, inspect
from commands2 import SubsystemBase, CommandScheduler
from commands import autoconfig
from commands.autonomouscommandgroup import AutonomousCommandGroup
from subsystems.monitor import Monitor as monitor
from subsystems.drivetrain import DriveTrain as drivetrain
from subsystems.cougarsystem import CougarSystem
import math
class KryptonBot(TimedCommandRobot):
"""Implements a Command Based robot design"""
def robotInit(self):
"""Set up everything we need for a working robot."""
if RobotBase.isSimulation():
import mockdata
DriverStation.getInstance().silenceJoystickConnectionWarning(True) # Amen!
self.subsystems()
controller.layout.init()
autoconfig.init()
driverhud.init()
self.selectedAuto = autoconfig.getAutoProgram()
self.auto = AutonomousCommandGroup()
from commands.startupcommandgroup import StartUpCommandGroup
StartUpCommandGroup().schedule()
from commands.drivetrain.drivecommand import DriveCommand
def autonomousInit(self):
"""This function is called each time autonomous mode starts."""
from commands.autonomouscommandgroup import AutonomousCommandGroup
from commands2 import InstantCommand
# Send field data to the dashboard
driverhud.showField()
# Schedule the autonomous command
self.auto.schedule()
driverhud.showInfo("Starting %s" % self.auton)
def disabledInit(self):
try:
self.auton.disable() # TODO: Fix this.
except (AttributeError):
pass
def disabledPeriodic(self):
if autoconfig.getAutoProgram() != self.selectedAuto:
self.selectedAuto = autoconfig.getAutoProgram()
self.auto = AutonomousCommandGroup()
# Recreate the auto and its counterparts if the selection changes.
def handleCrash(self, error):
super().handleCrash()
driverhud.showAlert("Fatal Error: %s" % error)
@classmethod
def subsystems(cls):
vars = globals()
module = sys.modules["robot"]
for key, var in vars.items():
try:
if issubclass(var, CougarSystem) and var is not CougarSystem:
try:
setattr(module, key, var())
except TypeError as e:
print("failed " + str(key))
raise ValueError(f"Could not instantiate {key}") from e
except TypeError:
pass
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "deploy":
shutil.rmtree("opkg_cache", ignore_errors=True)
shutil.rmtree("pip_cache", ignore_errors=True)
run(KryptonBot)