-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRobot.java
More file actions
199 lines (172 loc) · 6.17 KB
/
Robot.java
File metadata and controls
199 lines (172 loc) · 6.17 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import au.grapplerobotics.CanBridge;
import com.pathplanner.lib.commands.FollowPathCommand;
import edu.wpi.first.net.WebServer;
import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Filesystem;
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import frc.robot.Subsystems.SubsystemConstants;
import frc.robot.subsystems.SuperStructure;
import frc.robot.subsystems.auto.AutoBuilderConfig;
import frc.robot.subsystems.auto.AutoLogic;
import frc.robot.subsystems.auto.AutonomousField;
import frc.robot.util.BuildInfo;
import frc.robot.util.MatchTab;
import frc.robot.util.RobotType;
import frc.robot.util.WheelRadiusCharacterization;
public class Robot extends TimedRobot {
/** Singleton Stuff */
private static Robot instance = null;
public static Robot getInstance() {
if (instance == null) instance = new Robot();
return instance;
}
private final RobotType robotType;
public final Controls controls;
public final Subsystems subsystems;
public final Sensors sensors;
public final SuperStructure superStructure;
private final PowerDistribution PDH;
protected Robot() {
// non public for singleton. Protected so test class can subclass
instance = this;
robotType = RobotType.getCurrent();
CanBridge.runTCP();
PDH = new PowerDistribution(Hardware.PDH_ID, ModuleType.kRev);
LiveWindow.disableAllTelemetry();
LiveWindow.enableTelemetry(PDH);
sensors = new Sensors();
subsystems = new Subsystems(sensors);
if (SubsystemConstants.DRIVEBASE_ENABLED) {
AutoBuilderConfig.buildAuto(subsystems.drivebaseSubsystem);
}
if (SubsystemConstants.ELEVATOR_ENABLED
&& SubsystemConstants.ARMPIVOT_ENABLED
&& SubsystemConstants.SPINNYCLAW_ENABLED) {
superStructure =
new SuperStructure(
subsystems.elevatorSubsystem,
subsystems.armPivotSubsystem,
subsystems.spinnyClawSubsytem,
subsystems.groundArm,
subsystems.groundSpinny,
subsystems.elevatorLEDSubsystem,
sensors.armSensor,
sensors.branchSensors,
sensors.intakeSensor);
} else {
superStructure = null;
}
controls = new Controls(subsystems, sensors, superStructure);
SmartDashboard.putString("current bot", robotType.toString());
if (RobotBase.isReal()) {
DataLogManager.start();
DriverStation.startDataLog(DataLogManager.getLog(), true);
}
CommandScheduler.getInstance()
.onCommandInitialize(
command -> System.out.println("Command initialized: " + command.getName()));
CommandScheduler.getInstance()
.onCommandInterrupt(
(command, interruptor) ->
System.out.println(
"Command interrupted: "
+ command.getName()
+ "; Cause: "
+ interruptor.map(cmd -> cmd.getName()).orElse("<none>")));
CommandScheduler.getInstance()
.onCommandFinish(command -> System.out.println("Command finished: " + command.getName()));
SmartDashboard.putData(CommandScheduler.getInstance());
BuildInfo.logBuildInfo();
if (SubsystemConstants.DRIVEBASE_ENABLED) {
AutoLogic.registerCommands();
AutonomousField.initShuffleBoard("Field", 0, 0, this::addPeriodic);
AutoLogic.initShuffleBoard();
FollowPathCommand.warmupCommand().schedule();
}
MatchTab.create(sensors, subsystems);
WebServer.start(5800, Filesystem.getDeployDirectory().getPath());
}
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
if (subsystems.visionSubsystem != null) {
subsystems.visionSubsystem.update();
}
}
@Override
public void disabledInit() {}
@Override
public void disabledPeriodic() {}
@Override
public void disabledExit() {
// on the end of diabling, make sure all of the motors are set to break and wont move upon
// enabling
if (subsystems.drivebaseSubsystem != null) {
subsystems.drivebaseSubsystem.brakeMotors();
}
if (subsystems.climbPivotSubsystem != null) {
subsystems.climbPivotSubsystem.brakeMotors();
subsystems.climbPivotSubsystem.moveCompleteTrue();
}
if (subsystems.elevatorSubsystem != null) {
subsystems.elevatorSubsystem.brakeMotors();
}
}
@Override
public void autonomousInit() {
Shuffleboard.startRecording();
if (SubsystemConstants.DRIVEBASE_ENABLED
&& AutoLogic.getSelectedAuto() != null
&& !AutoLogic.RUN_MEASUREMENT_AUTO) {
AutoLogic.getSelectedAuto().schedule();
}
if (subsystems.climbPivotSubsystem != null) {
subsystems.climbPivotSubsystem.moveCompleteFalse();
}
if (SubsystemConstants.DRIVEBASE_ENABLED && AutoLogic.RUN_MEASUREMENT_AUTO) {
WheelRadiusCharacterization.wheelRadiusCharacterizationCommand(subsystems.drivebaseSubsystem)
.schedule();
}
}
@Override
public void autonomousExit() {
CommandScheduler.getInstance().cancelAll();
}
@Override
public void teleopInit() {
CommandScheduler.getInstance().cancelAll();
Shuffleboard.startRecording();
}
@Override
public void teleopPeriodic() {}
@Override
public void teleopExit() {
CommandScheduler.getInstance().cancelAll();
}
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();
}
@Override
public void testPeriodic() {}
@Override
public void testExit() {}
public RobotType getRobotType() {
return robotType;
}
public boolean isCompetition() {
return getRobotType() == RobotType.COMPETITION;
}
}