From cb7ed34793f0a61d0032a309ab477eab63cf9e56 Mon Sep 17 00:00:00 2001 From: Kate Brownbill Date: Mon, 31 Jan 2022 10:42:18 -0500 Subject: [PATCH 1/2] Added a fake DriveTrainVariant and a constant to disable the DriveTrain. --- src/main/java/ca/warp7/frc2022/Constants.java | 1 + .../warp7/frc2022/subsystems/DriveTrain.java | 9 +- .../drivetrain/LazyDriveTrainVariant.java | 95 +++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java diff --git a/src/main/java/ca/warp7/frc2022/Constants.java b/src/main/java/ca/warp7/frc2022/Constants.java index a7fd646..246ce3e 100644 --- a/src/main/java/ca/warp7/frc2022/Constants.java +++ b/src/main/java/ca/warp7/frc2022/Constants.java @@ -24,6 +24,7 @@ public final class Constants { // Configuration public static final boolean kEnableSolenoids = true; + public static final boolean kEnableDriveTrain = true; public static final boolean kDebugCommandScheduler = false; public static final boolean kUseKinematicsDrive = false; diff --git a/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java b/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java index a073f62..5975b6b 100644 --- a/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java +++ b/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java @@ -10,6 +10,8 @@ import ca.warp7.frc2022.lib.LazySolenoid; import ca.warp7.frc2022.lib.control.PID; import ca.warp7.frc2022.subsystems.drivetrain.DriveTrainVariant; +import ca.warp7.frc2022.subsystems.drivetrain.LazyDriveTrainVariant; + import com.kauailabs.navx.frc.AHRS; import edu.wpi.first.wpilibj.I2C; import edu.wpi.first.wpilibj.Timer; @@ -39,7 +41,12 @@ public static void setVariant(DriveTrainVariant variant) { if (driveTrainVariant != null) { throw new IllegalStateException("Cannot set drive train variant"); } - driveTrainVariant = variant; + if (kEnableDriveTrain){ + driveTrainVariant = variant; + } + else{ + driveTrainVariant = new LazyDriveTrainVariant(); + } } private final LazySolenoid shifterSolenoid = diff --git a/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java b/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java new file mode 100644 index 0000000..d9e81c2 --- /dev/null +++ b/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java @@ -0,0 +1,95 @@ +package ca.warp7.frc2022.subsystems.drivetrain; + +import ca.warp7.frc2022.lib.control.PID; + + +/* + This class is suppose to be a substitute for an instance of DriveTrainVariant. To the rest of the program, + its a valid DriveTrainVariant, however it does not actually do anything. +*/ +public final class LazyDriveTrainVariant implements DriveTrainVariant { + public LazyDriveTrainVariant() { + } + + @Override + public void setVelocityPID( + double leftVelocityRotationsPerSecond, + double rightVelocityRotationsPerSecond, + double leftVoltage, + double rightVoltage) { + } + + @Override + public void setPositionPID(double leftDistanceRotations, double rightDistanceRotations) { + } + + @Override + public void configurePID(PID pid) { + } + + @Override + public void configureRampRate(double secondsFromNeutralToFull) { + } + + @Override + public void setEncoderPosition(double leftRotations, double rightRotations) { + } + + @Override + public void setBrake() { + } + + @Override + public void setCoast() { + } + + @Override + public double getLeftPositionRotations() { + return (0.0); + } + + @Override + public double getRightPositionRotations() { + return (0.0); + } + + @Override + public double getLeftVelocityRPS() { + return (0.0); + } + + @Override + public double getRightVelocityRPS() { + return (0.0); + } + + @Override + public double getLeftVoltage() { + return (0.0); + } + + @Override + public double getRightVoltage() { + return (0.0); + } + + @Override + public void neutralOutput() { + } + + @Override + public void setPercentOutput(double leftPercent, double rightPercent) { + } + + @Override + public double getLeftPIDErrorRotations() { + return(0.0); + + } + + @Override + public double getRightPIDErrorRotations() { + return(0.0); + + } +} \ No newline at end of file From e3f3345ccd4128a902a874f962e6222bee84ac62 Mon Sep 17 00:00:00 2001 From: Kate Brownbill Date: Wed, 2 Feb 2022 09:47:15 -0500 Subject: [PATCH 2/2] Moved the initalization of all DriveTrainVarients to DriveTrain --- src/main/java/ca/warp7/frc2022/Robot.java | 2 -- .../warp7/frc2022/subsystems/DriveTrain.java | 21 +++++++------------ .../drivetrain/LazyDriveTrainVariant.java | 2 ++ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/ca/warp7/frc2022/Robot.java b/src/main/java/ca/warp7/frc2022/Robot.java index d363e76..10b0ec8 100644 --- a/src/main/java/ca/warp7/frc2022/Robot.java +++ b/src/main/java/ca/warp7/frc2022/Robot.java @@ -41,8 +41,6 @@ public final class Robot extends TimedRobot { public void robotInit() { System.out.println("Hello me is robit!"); - DriveTrain.setVariant(new FalconDriveTrainVariant()); - scheduler = CommandScheduler.getInstance(); if (Constants.kDebugCommandScheduler) { diff --git a/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java b/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java index 5975b6b..06400bd 100644 --- a/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java +++ b/src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java @@ -9,8 +9,7 @@ import ca.warp7.frc2022.lib.LazySolenoid; import ca.warp7.frc2022.lib.control.PID; -import ca.warp7.frc2022.subsystems.drivetrain.DriveTrainVariant; -import ca.warp7.frc2022.subsystems.drivetrain.LazyDriveTrainVariant; +import ca.warp7.frc2022.subsystems.drivetrain.*; import com.kauailabs.navx.frc.AHRS; import edu.wpi.first.wpilibj.I2C; @@ -37,18 +36,6 @@ public static DriveTrain getInstance() { private static DriveTrainVariant driveTrainVariant; - public static void setVariant(DriveTrainVariant variant) { - if (driveTrainVariant != null) { - throw new IllegalStateException("Cannot set drive train variant"); - } - if (kEnableDriveTrain){ - driveTrainVariant = variant; - } - else{ - driveTrainVariant = new LazyDriveTrainVariant(); - } - } - private final LazySolenoid shifterSolenoid = new LazySolenoid(kDriveShifterID, kEnableSolenoids); @@ -68,6 +55,12 @@ public static void setVariant(DriveTrainVariant variant) { private double previousRightPosition = 0.0; // m private DriveTrain() { + if (kEnableDriveTrain){ + driveTrainVariant = new FalconDriveTrainVariant(); + } + else{ + driveTrainVariant = new LazyDriveTrainVariant(); + } } @Override diff --git a/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java b/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java index d9e81c2..1a504d9 100644 --- a/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java +++ b/src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java @@ -6,6 +6,8 @@ /* This class is suppose to be a substitute for an instance of DriveTrainVariant. To the rest of the program, its a valid DriveTrainVariant, however it does not actually do anything. + + THIS CLASS IS NOT USED WHEN THE DRIVE TRAIN IS ENABLED, NONE OF THE METHODS DO ANYTHING OF USE. */ public final class LazyDriveTrainVariant implements DriveTrainVariant { public LazyDriveTrainVariant() {