Add ToggleIndexerPiston class
authorRohan Rodrigues <rohanrodrigues19@gmail.com>
Sat, 4 Mar 2017 17:50:55 +0000 (09:50 -0800)
committerRohan Rodrigues <rohanrodrigues19@gmail.com>
Sat, 4 Mar 2017 17:50:55 +0000 (09:50 -0800)
src/org/usfirst/frc/team3501/robot/OI.java
src/org/usfirst/frc/team3501/robot/Robot.java
src/org/usfirst/frc/team3501/robot/commands/driving/ToggleDrivePiston.java [deleted file]
src/org/usfirst/frc/team3501/robot/commands/driving/ToggleGear.java
src/org/usfirst/frc/team3501/robot/commands/shooter/ToggleIndexerPiston.java
src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java
src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java

index 9000e35fa16a56ff67b549d4ee829c42d10dd198..07ad53c765b9f50318f9cb024d4a46c1344e02e1 100644 (file)
@@ -1,7 +1,6 @@
 package org.usfirst.frc.team3501.robot;
 
 import org.usfirst.frc.team3501.robot.commands.climber.ToggleWinch;
-import org.usfirst.frc.team3501.robot.commands.driving.ToggleDrivePiston;
 import org.usfirst.frc.team3501.robot.commands.driving.ToggleGear;
 import org.usfirst.frc.team3501.robot.commands.intake.ReverseIntakeContinuous;
 import org.usfirst.frc.team3501.robot.commands.intake.RunIntakeContinuous;
@@ -11,6 +10,7 @@ import org.usfirst.frc.team3501.robot.commands.shooter.ReverseIndexWheelContinuo
 import org.usfirst.frc.team3501.robot.commands.shooter.RunFlyWheelContinuous;
 import org.usfirst.frc.team3501.robot.commands.shooter.RunIndexWheelContinuous;
 import org.usfirst.frc.team3501.robot.commands.shooter.ToggleIndexerPiston;
+import org.usfirst.frc.team3501.robot.utils.ChangeCameraView;
 
 import edu.wpi.first.wpilibj.Joystick;
 import edu.wpi.first.wpilibj.buttons.Button;
@@ -79,11 +79,9 @@ public class OI /* implements KeyListener */ {
         Constants.OI.DECREASE_SHOOTER_SPEED_PORT);
     decreaseShooterSpeed.whenPressed(new DecreaseShootingSpeed());
 
-    /*
-     * changeCam = new JoystickButton(rightJoystick,
-     * Constants.OI.CHANGE_CAMERA_VIEW); changeCam.toggleWhenPressed(new
-     * ChangeCameraView());
-     */
+    changeCam = new JoystickButton(rightJoystick,
+        Constants.OI.CHANGE_CAMERA_VIEW);
+    changeCam.toggleWhenPressed(new ChangeCameraView());
 
     togglePiston = new JoystickButton(rightJoystick,
         Constants.Shooter.TOGGLE_INDEXER);
@@ -91,7 +89,7 @@ public class OI /* implements KeyListener */ {
 
     toggleDriveTrainPiston = new JoystickButton(rightJoystick,
         Constants.DriveTrain.TOGGLE_DRIVE_PISTON);
-    toggleDriveTrainPiston.whenPressed(new ToggleDrivePiston());
+    toggleDriveTrainPiston.whenPressed(new ToggleGear());
   }
 
   public static OI getOI() {
index e72f07e03b85c3a2c8512acf2989800469be42af..455de4e62ec598d5270faa5e97c4a2746d15b380 100644 (file)
@@ -55,7 +55,8 @@ public class Robot extends IterativeRobot {
   // both set to high gear
   @Override
   public void autonomousInit() {
-    driveTrain.setHighGear();
+    driveTrain.setHighGear(driveTrain.getRightPiston());
+    driveTrain.setHighGear(driveTrain.getLeftPiston());
   }
 
   @Override
diff --git a/src/org/usfirst/frc/team3501/robot/commands/driving/ToggleDrivePiston.java b/src/org/usfirst/frc/team3501/robot/commands/driving/ToggleDrivePiston.java
deleted file mode 100644 (file)
index ad13cc0..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.usfirst.frc.team3501.robot.commands.driving;
-
-import org.usfirst.frc.team3501.robot.Constants;
-import org.usfirst.frc.team3501.robot.Robot;
-import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
-import edu.wpi.first.wpilibj.command.Command;
-
-public class ToggleDrivePiston extends Command {
-  private DriveTrain driveTrain = Robot.getDriveTrain();
-
-  /**
-   * See JavaDoc comment in class for details
-   *
-   * @param motorVal
-   *          value range from -1 to 1
-   */
-  public ToggleDrivePiston() {
-    requires(driveTrain);
-  }
-
-  // Called just before this Command runs the first time
-  @Override
-  protected void initialize() {
-  }
-
-  // Called repeatedly when this Command is scheduled to run
-  @Override
-  protected void execute() {
-    if (DriveTrain.getDriveTrain()
-        .getLeftGearPistonValue() == Constants.DriveTrain.HIGH_GEAR) {
-      DriveTrain.getDriveTrain().setLowGear();
-    } else {
-      DriveTrain.getDriveTrain().setHighGear();
-    }
-
-    // check to make sure that both pistons are set to the same gear. Otherwise,
-    // the code must be changed
-  }
-
-  // Called once after isFinished returns true
-  @Override
-  protected void end() {
-  }
-
-  // Called when another command which requires one or more of the same
-  // subsystems is scheduled to run
-  @Override
-  protected void interrupted() {
-    end();
-  }
-
-  @Override
-  protected boolean isFinished() {
-    return false;
-
-  }
-
-}
index ce7489096ec57d9443c0e17f1cc5da1ec71ad9f3..3a17440b1e920cd182db1cbc87d20c003296346e 100644 (file)
@@ -29,10 +29,17 @@ public class ToggleGear extends Command {
   protected void execute() {
     Value leftGearPistonValue = driveTrain.getLeftGearPistonValue();
     Value rightGearPistonValue = driveTrain.getRightGearPistonValue();
+
     if (leftGearPistonValue == Constants.DriveTrain.LOW_GEAR) {
-      driveTrain.setHighGear();
+      driveTrain.setHighGear(driveTrain.getLeftPiston());
+    } else {
+      driveTrain.setLowGear(driveTrain.getLeftPiston());
+    }
+
+    if (rightGearPistonValue == Constants.DriveTrain.LOW_GEAR) {
+      driveTrain.setHighGear(driveTrain.getRightPiston());
     } else {
-      driveTrain.setLowGear();
+      driveTrain.setLowGear(driveTrain.getRightPiston());
     }
   }
 
index 42cf3bcbef392aaaf9642656e809d9bc69cf042a..a653293d97ad4ca99b0dca5aa21c785415d87917 100644 (file)
@@ -27,10 +27,10 @@ public class ToggleIndexerPiston extends Command {
   // Called repeatedly when this Command is scheduled to run
   @Override
   protected void execute() {
-    if (Shooter.getShooter().getPistonValue() == Constants.Shooter.LOW_GEAR) {
-      Shooter.getShooter().setHighGear();
+    if (shooter.getPistonValue() == Constants.Shooter.LOW_GEAR) {
+      shooter.setHighGear();
     } else {
-      Shooter.getShooter().setLowGear();
+      shooter.setLowGear();
     }
   }
 
index 32ec7b221ab237ef17747dfa46f47f8246ace31b..328209e5d82a9f87149130d4657c1938f3508d6a 100644 (file)
@@ -165,26 +165,33 @@ public class DriveTrain extends Subsystem {
     return rightGearPiston.get();
   }
 
+  public DoubleSolenoid getLeftPiston() {
+    return this.leftGearPiston;
+  }
+
+  public DoubleSolenoid getRightPiston() {
+    return this.rightGearPiston;
+  }
+
   /*
    * Changes the ball shift gear assembly to high
    */
-  public void setHighGear() {
-    changeGear(Constants.DriveTrain.HIGH_GEAR);
+  public void setHighGear(DoubleSolenoid p) {
+    changeGear(Constants.DriveTrain.HIGH_GEAR, p);
   }
 
   /*
    * Changes the ball shift gear assembly to low
    */
-  public void setLowGear() {
-    changeGear(Constants.DriveTrain.LOW_GEAR);
+  public void setLowGear(DoubleSolenoid p) {
+    changeGear(Constants.DriveTrain.LOW_GEAR, p);
   }
 
   /*
    * Changes the gear to a DoubleSolenoid.Value
    */
-  private void changeGear(DoubleSolenoid.Value gear) {
-    leftGearPiston.set(gear);
-    rightGearPiston.set(gear);
+  private void changeGear(DoubleSolenoid.Value gear, DoubleSolenoid piston) {
+    piston.set(gear);
   }
 
   @Override
index dac23fd6a8214aee7ff03faf4a95798cbb6e2b55..e526dac106a4652dd1b2cc02d29a562febc9a72d 100644 (file)
@@ -22,7 +22,7 @@ public class Shooter extends Subsystem {
 
   private double currentShootingSpeed = DEFAULT_SHOOTING_SPEED;
 
-  private DoubleSolenoid piston;
+  private final DoubleSolenoid piston;
 
   private Shooter() {
     flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1);