Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Added a fake DriveTrainVariant and a constant to disable the DriveTrain. #6

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/ca/warp7/frc2022/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ca/warp7/frc2022/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/ca/warp7/frc2022/subsystems/DriveTrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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.*;

import com.kauailabs.navx.frc.AHRS;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.Timer;
Expand All @@ -35,13 +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");
}
driveTrainVariant = variant;
}

private final LazySolenoid shifterSolenoid =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LazySolenoid here also needs a be tied into the kEnableDriveTrain

Also, are we missing something like a kEnableDriveTrainShifter constant? i.e., should this be

new LazySolenoid(kDriveShifterID, kEnableSolenoids && kEnableDriveTrain && kEnableDriveTrainShifter);

new LazySolenoid(kDriveShifterID, kEnableSolenoids);

Expand All @@ -61,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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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.

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() {
}

@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);

}
}