Skip to content

Commit eadceeb

Browse files
committed
Add mode manager: demo and competition
1 parent 01670d6 commit eadceeb

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/main/java/frc/robot/Robot.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import frc.robot.subsystems.visionIO.VisionIOSim;
6868
import frc.robot.util.ChangeDetector;
6969
import frc.robot.util.MechanismManager;
70+
import frc.robot.util.ModeManager;
7071
import frc.robot.util.RedHawkUtil;
7172
import frc.robot.util.RumbleManager;
7273
import frc.robot.util.SwerveHeadingController;
@@ -104,10 +105,19 @@ public class Robot extends LoggedRobot {
104105
private Command autoCommand;
105106
private final LoggedDashboardChooser<RHRFullRoutine> autoChooser =
106107
new LoggedDashboardChooser<>("Autonomous Routine");
108+
private final LoggedDashboardChooser<RobotMode> modeChooser =
109+
new LoggedDashboardChooser<>("Robot Mode");
107110

108111
private ChangeDetector<Optional<Alliance>> allianceChangeDetector;
109112
private ChangeDetector<RHRFullRoutine> autoChangeDetector;
113+
private ChangeDetector<RobotMode> modeChangeDetector;
110114
private Rotation2d gyroInitial = Rotation2d.fromRadians(0);
115+
public static final ModeManager modeManager = new ModeManager(RobotMode.DEMO);
116+
117+
public enum RobotMode {
118+
DEMO,
119+
COMPETITION
120+
}
111121

112122
@Override
113123
public void robotInit() {
@@ -199,6 +209,12 @@ public void robotInit() {
199209
gyroInitial = auto.traj1.getInitialPose().getRotation();
200210
seedGyroBasedOnAlliance();
201211
});
212+
213+
modeChangeDetector =
214+
new ChangeDetector<>(
215+
(mode) -> {
216+
modeManager.setMode(mode);
217+
});
202218
}
203219

204220
public void createDriverBindings() {
@@ -989,6 +1005,7 @@ public void disabledPeriodic() {
9891005
swerveDrive.seed();
9901006
allianceChangeDetector.feed(DriverStation.getAlliance());
9911007
autoChangeDetector.feed(autoChooser.get());
1008+
modeChangeDetector.feed(modeChooser.get());
9921009
}
9931010

9941011
@Override
@@ -1062,6 +1079,12 @@ public void buildAutoChooser() {
10621079
autoChooser.addOption("NopeAmp", new NopeAmp());
10631080
}
10641081

1082+
public void buildModeChooser() {
1083+
modeChooser.addDefaultOption(modeManager.getMode().toString(), Robot.modeManager.getMode());
1084+
modeChooser.addOption("Demo", RobotMode.DEMO);
1085+
modeChooser.addOption("Competition", RobotMode.COMPETITION);
1086+
}
1087+
10651088
public void updatePreMatchDashboardValues() {
10661089
var encoderReadings = swerveDrive.getAbsoluteEncoderAngles();
10671090
SmartDashboard.putNumber("Dashboard/Battery Voltage", RobotController.getBatteryVoltage());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package frc.robot.util;
2+
3+
import frc.robot.Robot.RobotMode;
4+
5+
public class ModeManager
6+
{
7+
private RobotMode mode;
8+
9+
public ModeManager(RobotMode initialMode) {
10+
this.mode = initialMode;
11+
}
12+
13+
public RobotMode getMode() {
14+
return this.mode;
15+
}
16+
17+
public void setMode(RobotMode newMode) {
18+
this.mode = newMode;
19+
}
20+
}
21+

src/main/java/frc/robot/util/MotionHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import edu.wpi.first.math.util.Units;
99
import frc.robot.Constants.DriveConstants;
1010
import frc.robot.Robot;
11+
import frc.robot.Robot.RobotMode;
1112
import frc.robot.VehicleState;
1213
import frc.robot.commands.otf.RotateScore;
1314
import frc.robot.rhr.auto.RHRTrajectoryController;
@@ -52,7 +53,7 @@ public static ChassisSpeeds driveTrajectoryHeadingController(ChassisSpeeds cs) {
5253
* @return The desired array of desaturated swerveModuleStates.
5354
*/
5455
public static ChassisSpeeds driveFullControl() {
55-
double speedFactor = 1; // Robot.driver.rightBumper().getAsBoolean() ? 0.33 : 1.0;
56+
double speedFactor = Robot.modeManager.getMode() == RobotMode.DEMO ? 0.5 : 1;
5657

5758
double xSpeed =
5859
MathUtil.applyDeadband(-Robot.driver.getLeftY(), DriveConstants.K_JOYSTICK_TURN_DEADZONE)

0 commit comments

Comments
 (0)