Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 committed Jan 27, 2025
1 parent 2f0caaf commit fa043cf
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 73 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/team1540/robot2025/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* constants are needed, to reduce verbosity.
*/
public final class Constants {
private static final Mode kSimMode = Mode.SIM;
public static final Mode kCurrentMode = Robot.isReal() ? Mode.REAL : kSimMode;
private static final Mode SIM_MODE = Mode.SIM;
public static final Mode CURRENT_MODE = Robot.isReal() ? Mode.REAL : SIM_MODE;

private static final boolean kTuningMode = true;
private static final boolean TUNING_MODE = true;

public static boolean isTuningMode() {
return !DriverStation.isFMSAttached() && kTuningMode;
return !DriverStation.isFMSAttached() && TUNING_MODE;
}

public enum Mode {
Expand All @@ -30,10 +30,10 @@ public enum Mode {
REPLAY
}

public static final double kLoopPeriodSecs = 0.02;
public static final double LOOP_PERIOD_SECS = 0.02;

public static final double kRobotMassKg = Units.lbsToKilograms(147);
public static final double kRobotMOIKgM2 = 5.8;
public static final double ROBOT_MASS_KG = Units.lbsToKilograms(147);
public static final double ROBOT_MOI_KGM2 = 5.8;

public static final double kBumperLengthXMeters = Units.inchesToMeters(35.0);
public static final double kBumperLengthYMeters = Units.inchesToMeters(33.0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/team1540/robot2025/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Robot() {
Logger.recordMetadata("TuningMode", Constants.isTuningMode() ? "on" : "off");

// Set up data receivers & replay source
switch (Constants.kCurrentMode) {
switch (Constants.CURRENT_MODE) {
case REAL:
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/team1540/robot2025/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class RobotContainer {

/** The container for the robot. Contains subsystems, IO devices, and commands. */
public RobotContainer() {
switch (Constants.kCurrentMode) {
switch (Constants.CURRENT_MODE) {
case REAL:
// Real robot, instantiate hardware IO implementations
drivetrain = Drivetrain.createReal();
Expand Down Expand Up @@ -95,7 +95,7 @@ private void configurePeriodicCallbacks() {
.withName("AlertManager update")
.ignoringDisable(true));

if (Constants.kCurrentMode == Constants.Mode.SIM) {
if (Constants.CURRENT_MODE == Constants.Mode.SIM) {
CommandScheduler.getInstance()
.schedule(Commands.run(SimState.getInstance()::update)
.withName("Simulation update")
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/team1540/robot2025/RobotState.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public static RobotState getInstance() {
new SwerveModulePosition(), new SwerveModulePosition(), new SwerveModulePosition(), new SwerveModulePosition()
};

// private Trajectory<SwerveSample> activeTrajectory = null;
private Pose2d[] activeTrajectory;

private final Field2d field = new Field2d();

private RobotState() {
poseEstimator = new SwerveDrivePoseEstimator(
Drivetrain.kKinematics,
Drivetrain.KINEMATICS,
lastGyroRotation,
lastModulePositions,
Pose2d.kZero,
Expand Down Expand Up @@ -77,7 +76,7 @@ public void setTrajectoryTarget(Pose2d target) {
}

public void resetPose(Pose2d newPose) {
if (Constants.kCurrentMode == Constants.Mode.SIM) SimState.getInstance().resetSimPose(newPose);
if (Constants.CURRENT_MODE == Constants.Mode.SIM) SimState.getInstance().resetSimPose(newPose);
poseEstimator.resetPosition(lastGyroRotation, lastModulePositions, newPose);
resetTimer.restart();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/team1540/robot2025/SimState.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public static SimState getInstance() {
private final SwerveDriveSimulation driveSim;

private SimState() {
if (Constants.kCurrentMode != Constants.Mode.SIM)
if (Constants.CURRENT_MODE != Constants.Mode.SIM)
throw new IllegalStateException("SimState should only be used in simulation");

SimulatedArena.getInstance().resetFieldForAuto();

var simConfig = DriveTrainSimulationConfig.Default()
.withRobotMass(Kilograms.of(Constants.kRobotMassKg))
.withCustomModuleTranslations(Drivetrain.kModuleTranslations)
.withRobotMass(Kilograms.of(Constants.ROBOT_MASS_KG))
.withCustomModuleTranslations(Drivetrain.MODULE_TRANSLATIONS)
.withBumperSize(Meters.of(Constants.kBumperLengthXMeters), Meters.of(Constants.kBumperLengthYMeters))
.withGyro(() -> new GyroSimulation(0.12 / 120, 0.02))
.withSwerveModule(() -> new SwerveModuleSimulation(new SwerveModuleSimulationConfig(
Expand All @@ -47,7 +47,7 @@ private SimState() {
Volts.of(TunerConstants.FrontLeft.SteerFrictionVoltage),
Meters.of(TunerConstants.FrontLeft.WheelRadius),
KilogramSquareMeters.of(TunerConstants.FrontLeft.SteerInertia),
Drivetrain.kWheelCOF)));
Drivetrain.WHEEL_COF)));
driveSim = new SwerveDriveSimulation(simConfig, Pose2d.kZero);
SimulatedArena.getInstance().addDriveTrainSimulation(driveSim);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.team1540.robot2025.util.math.PolynomialRegression;

public class CharacterizationCommands {
private static final double kStartDelaySecs = 1.0;
private static final double START_DELAY_SECS = 1.0;

private static final LoggedTunableNumber ffRampVoltsPerSec =
new LoggedTunableNumber("Characterization/Feedforward/RampVoltsPerSec", 0.1);
Expand All @@ -34,7 +34,7 @@ public static Command feedforward(
velocitySamples.clear();
voltageSamples.clear();
}),
Commands.run(() -> voltageConsumer.accept(0.0)).withTimeout(kStartDelaySecs),
Commands.run(() -> voltageConsumer.accept(0.0)).withTimeout(START_DELAY_SECS),
Commands.runOnce(timer::restart),
Commands.run(() -> {
double voltage = timer.get() * ffRampVoltsPerSec.get();
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Command wheelRadius(
omegaConsumer.accept(omega);
})),
Commands.sequence(
Commands.waitSeconds(kStartDelaySecs),
Commands.waitSeconds(START_DELAY_SECS),
Commands.runOnce(() -> {
state.startPositions = wheelPositionsRadsSupplier.get();
state.lastYawRads = gyroYawRadsSupplier.getAsDouble();
Expand All @@ -110,7 +110,7 @@ public static Command wheelRadius(
wheelDelta += Math.abs(positions[i] - state.startPositions[i]);
}
wheelDelta /= 4.0;
double effectiveRadius = (state.accumGyroYawRads * Drivetrain.kDrivebaseRadius) / wheelDelta;
double effectiveRadius = (state.accumGyroYawRads * Drivetrain.DRIVEBASE_RADIUS) / wheelDelta;
effectiveRadius = Units.metersToInches(effectiveRadius);

System.out.println("********** Wheel Radius Characterization Results **********");
Expand Down
Loading

0 comments on commit fa043cf

Please sign in to comment.