Skip to content

Commit

Permalink
Drive singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH0 committed Sep 17, 2024
1 parent c91f4fb commit 6a55ffb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ public RobotContainer() {
switch (Constants.currentMode) {
case REAL:
// Real robot, instantiate hardware IO implementations
drive =
new Drive(
new GyroIOPigeon2(),
drive = Drive.initialize(
new GyroIOPigeon2(),
new ModuleIOSparkMax(0),
new ModuleIOSparkMax(1),
new ModuleIOSparkMax(2),
new ModuleIOSparkMax(3));

// new Drive(
// new GyroIOPigeon2(),
// new ModuleIOSparkMax(0),
// new ModuleIOSparkMax(1),
// new ModuleIOSparkMax(2),
// new ModuleIOSparkMax(3));

flywheel = new Flywheel(new FlywheelIOSparkMax());
// drive = new Drive(
// new GyroIOPigeon2(),
Expand Down Expand Up @@ -151,7 +158,7 @@ private void configureButtonBindings() {
() -> -controller.getLeftX(),
() -> -controller.getRightX()));
controller.x().onTrue(Commands.runOnce(drive::stopWithX, drive));

controller
.b()
.onTrue(
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.littletonrobotics.junction.Logger;

public class Drive extends SubsystemBase {
private static Drive instance;
private static final double MAX_LINEAR_SPEED = Units.feetToMeters(14.5);
private static final double TRACK_WIDTH_X = Units.inchesToMeters(25.0);
private static final double TRACK_WIDTH_Y = Units.inchesToMeters(25.0);
Expand All @@ -63,9 +64,21 @@ public class Drive extends SubsystemBase {
new SwerveModulePosition(),
new SwerveModulePosition()
};

private SwerveDrivePoseEstimator poseEstimator =
new SwerveDrivePoseEstimator(kinematics, rawGyroRotation, lastModulePositions, new Pose2d());

public static Drive getInstance() {
return instance;
}

public static Drive initialize(GyroIO gyro, ModuleIO fl, ModuleIO fr, ModuleIO bl, ModuleIO br) {
if (instance == null) {
instance = new Drive(gyro, fl, fr, bl, br);
}
return instance;
}

public Drive(
GyroIO gyroIO,
ModuleIO flModuleIO,
Expand Down

0 comments on commit 6a55ffb

Please sign in to comment.