Skip to content

Commit 733e2df

Browse files
committed
feat: add config ternaries for multiple robots
1 parent 9394320 commit 733e2df

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-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

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
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+
import org.team1540.robot2024.Constants.SwerveConfig;
1113
import org.team1540.robot2024.commands.FeedForwardCharacterization;
1214
import org.team1540.robot2024.commands.SwerveDriveCommand;
1315
import org.team1540.robot2024.subsystems.drive.*;
@@ -42,10 +44,10 @@ public RobotContainer() {
4244
drivetrain =
4345
new Drivetrain(
4446
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)));
47+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.FRONT_LEFT, SwerveFactory.SwerveCorner.FRONT_LEFT)),
48+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.FRONT_RIGHT, SwerveFactory.SwerveCorner.FRONT_RIGHT)),
49+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.BACK_LEFT, SwerveFactory.SwerveCorner.BACK_LEFT)),
50+
new ModuleIOTalonFX(SwerveFactory.getModuleMotors(SwerveConfig.BACK_RIGHT, SwerveFactory.SwerveCorner.BACK_RIGHT)));
4951
break;
5052

5153
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)