This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Added a fake DriveTrainVariant and a constant to disable the DriveTrain. #6
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
|
95 changes: 95 additions & 0 deletions
95
src/main/java/ca/warp7/frc2022/subsystems/drivetrain/LazyDriveTrainVariant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider pushing this up to the caller, which is this line in robotInit()
The problem that I see is that if we don't have the drivetrain hardware then I think the new FalconDriveTrainVariant() will trigger the FalconDriverTrainVariant constructor, which will try to connect to the non-existent motors and gear box solenoids. My guess is that it'll generate a bunch of CAN bus warnings on the console output and it'll work fine, but that's a guess.
Another thought is to just make the driveTrainVariant in the constructor for DriveTrain() and remove the setVariant method completely. driveTrainVariant becomes a non-static member of DriveTrain, but I think that's okay... The only way to create a DriveTrain appears to be DriveTrain's getInstance method; the DriveTrain constructor is private. DriveTrain is a classic singleton.