public class DriveTrain extends PIDSubsystem {
// Current Drive Mode Default Drive Mode is Manual
private int DRIVE_MODE = 1;
+ private boolean outputFlipped = false;
private static double pidOutput = 0;
private Encoder leftEncoder, rightEncoder;
this.disable();
gyro.start();
- leftGearPiston = new DoubleSolenoid(10, Constants.DriveTrain.LEFT_FORWARD,
- Constants.DriveTrain.LEFT_REVERSE);
- rightGearPiston = new DoubleSolenoid(10,
- Constants.DriveTrain.RIGHT_FORWARD,
- Constants.DriveTrain.RIGHT_REVERSE);
+ leftGearPiston = new DoubleSolenoid(Constants.DriveTrain.LEFT_MODULE,
+ Constants.DriveTrain.LEFT_FORWARD, Constants.DriveTrain.LEFT_REVERSE);
+ rightGearPiston = new DoubleSolenoid(Constants.DriveTrain.RIGHT_MODULE,
+ Constants.DriveTrain.RIGHT_FORWARD, Constants.DriveTrain.RIGHT_REVERSE);
Constants.DriveTrain.inverted = false;
}
/*
* Method is a required method that the PID Subsystem uses to return the
* calculated PID value to the driver
- *
+ *
* @param Gives the user the output from the PID algorithm that is calculated
* internally
- *
+ *
* Body: Uses the output, does some filtering and drives the robot
*/
@Override
/*
* Checks the drive mode
- *
+ *
* @return the current state of the robot in each state Average distance from
* both sides of tank drive for Encoder Mode Angle from the gyro in GYRO_MODE
*/
/*
* constrains the distance to within -100 and 100 since we aren't going to
* drive more than 100 inches
- *
+ *
* Configure Encoder PID
- *
+ *
* Sets the setpoint to the PID subsystem
*/
public void driveDistance(double dist, double maxTimeOut) {
/*
* Turning method that should be used repeatedly in a command
- *
+ *
* First constrains the angle to within -360 and 360 since that is as much as
* we need to turn
- *
+ *
* Configures Gyro PID and sets the setpoint as an angle
*/
public void turnAngle(double angle) {
rearRight.set(right);
}
- /*
- * @return a value that is the current setpoint for the piston kReverse or
- * kForward
- */
- public Value getLeftGearPistonValue() {
- return leftGearPiston.get();
- }
-
- /*
- * @return a value that is the current setpoint for the piston kReverse or
- * kForward
+ /**
+ * @return a value that is the current setpoint for the piston (kReverse or
+ * kForward)
*/
- public Value getRightGearPistonValue() {
- return rightGearPiston.get();
+ public Value getGearPistonValue() {
+ return leftGearPiston.get(); // Pistons should always be in the same state
}
- /*
+ /**
* Changes the ball shift gear assembly to high
*/
public void setHighGear() {
changeGear(Constants.DriveTrain.HIGH_GEAR);
}
- /*
+ /**
* Changes the ball shift gear assembly to low
*/
public void setLowGear() {
changeGear(Constants.DriveTrain.LOW_GEAR);
}
- /*
- * changes the gear to a DoubleSolenoid.Value
+ /**
+ * Changes the gear to a DoubleSolenoid.Value
*/
public void changeGear(DoubleSolenoid.Value gear) {
leftGearPiston.set(gear);
rightGearPiston.set(gear);
}
+ /**
+ * Switches drivetrain gears from high to low or low to high
+ */
+ public void switchGear() {
+ Value currentValue = getGearPistonValue();
+ Value setValue = (currentValue == Constants.DriveTrain.HIGH_GEAR) ? Constants.DriveTrain.LOW_GEAR
+ : Constants.DriveTrain.HIGH_GEAR;
+ changeGear(setValue);
+ }
+
+ /**
+ * Toggle whether the motor outputs are flipped, effectively switching which
+ * side of the robot is the front.
+ */
+ public void toggleFlipped() {
+ outputFlipped = !outputFlipped;
+ }
+
+ public boolean isFlipped() {
+ return outputFlipped;
+ }
+
}