Skip to content

Commit 481ef54

Browse files
authored
feat: add config ternaries for multiple robots (#8)
1 parent a4d0e0c commit 481ef54

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/main/java/org/team1540/robot2024/Constants.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
* constants are needed, to reduce verbosity.
1212
*/
1313
public final class Constants {
14-
public static final Mode currentMode = Robot.isReal() ? Mode.REAL : Mode.SIM;
14+
public static final boolean IS_COMPETITION_ROBOT = true;
15+
private static final Mode simMode = Mode.SIM; // Can also be Mode.REPLAY
16+
17+
18+
public static final Mode currentMode = Robot.isReal() ? Mode.REAL : simMode;
1519

1620
public enum Mode {
1721
/**
@@ -32,8 +36,14 @@ public enum Mode {
3236

3337
public static final double LOOP_PERIOD_SECS = 0.02;
3438

39+
public static class SwerveConfig {
40+
public static final String CAN_BUS = IS_COMPETITION_ROBOT ? "" : "";
41+
public static final int FRONT_LEFT = IS_COMPETITION_ROBOT ? 3 : 0;
42+
public static final int FRONT_RIGHT = IS_COMPETITION_ROBOT ? 4 : 0;
43+
public static final int BACK_LEFT = IS_COMPETITION_ROBOT ? 7 : 0;
44+
public static final int BACK_RIGHT = IS_COMPETITION_ROBOT ? 1 : 0;
45+
}
3546
public static class Drivetrain {
36-
public static final String CAN_BUS = "";
3747
public static final double DRIVE_GEAR_RATIO = (50.0 / 14.0) * (17.0 / 27.0) * (45.0 / 15.0);
3848
public static final double TURN_GEAR_RATIO = 150.0 / 7.0;
3949
public static final boolean IS_TURN_MOTOR_INVERTED = true;

src/main/java/org/team1540/robot2024/RobotContainer.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import edu.wpi.first.wpilibj2.command.Command;
99
import edu.wpi.first.wpilibj2.command.Commands;
1010
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
11+
12+
1113
import org.team1540.robot2024.commands.FeedForwardCharacterization;
1214
import org.team1540.robot2024.commands.SwerveDriveCommand;
1315
import org.team1540.robot2024.subsystems.drive.*;
1416
import org.team1540.robot2024.util.swerve.SwerveFactory;
1517
import org.littletonrobotics.junction.networktables.LoggedDashboardChooser;
1618

19+
import static org.team1540.robot2024.Constants.SwerveConfig;
1720

1821
/**
1922
* This class is where the bulk of the robot should be declared. Since Command-based is a
@@ -42,10 +45,10 @@ public RobotContainer() {
4245
drivetrain =
4346
new Drivetrain(
4447
new GyroIONavx(),
45-
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(3, SwerveFactory.SwerveCorner.FRONT_LEFT)),
46-
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(4, SwerveFactory.SwerveCorner.FRONT_RIGHT)),
47-
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(7, SwerveFactory.SwerveCorner.BACK_LEFT)),
48-
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(1, SwerveFactory.SwerveCorner.BACK_RIGHT)));
48+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.FRONT_LEFT, SwerveFactory.SwerveCorner.FRONT_LEFT)),
49+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.FRONT_RIGHT, SwerveFactory.SwerveCorner.FRONT_RIGHT)),
50+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.BACK_LEFT, SwerveFactory.SwerveCorner.BACK_LEFT)),
51+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.BACK_RIGHT, SwerveFactory.SwerveCorner.BACK_RIGHT)));
4952
break;
5053

5154
case SIM:

src/main/java/org/team1540/robot2024/util/swerve/SwerveFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.ctre.phoenix6.signals.InvertedValue;
99
import com.ctre.phoenix6.signals.SensorDirectionValue;
1010
import edu.wpi.first.math.geometry.Rotation2d;
11-
import org.team1540.robot2024.Constants;
11+
import static org.team1540.robot2024.Constants.SwerveConfig.CAN_BUS;;
1212

1313
public class SwerveFactory {
1414
private static final double[] moduleOffsetsRots = new double[]{
@@ -23,7 +23,7 @@ public class SwerveFactory {
2323
};
2424

2525
public static SwerveModuleHW getModuleMotors(int id, SwerveCorner corner) {
26-
return new SwerveModuleHW(id, corner, Constants.Drivetrain.CAN_BUS);
26+
return new SwerveModuleHW(id, corner, CAN_BUS);
2727
}
2828

2929
public enum SwerveCorner {

0 commit comments

Comments
 (0)