Add command group for ToggleWinch
authorRohan Rodrigues <rohanrodrigues19@gmail.com>
Wed, 8 Feb 2017 05:09:40 +0000 (21:09 -0800)
committerEric Sandoval <harpnart@gmail.com>
Sun, 19 Feb 2017 18:43:55 +0000 (10:43 -0800)
src/org/usfirst/frc/team3501/robot/OI.java
src/org/usfirst/frc/team3501/robot/commandgroups/ToggleWinch.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java

index 8b5cdacb84b0a96ea8be573add14da2e85042ef7..40df56df3ae0170c7be6ccf88d3f1e36915411ba 100644 (file)
@@ -21,7 +21,6 @@ public class OI {
   public static Joystick leftJoystick;
   public static Joystick rightJoystick;
   public static Button toggleWinch;
-  private boolean isClimbing = false;
 
   public static Button runIndexWheel;
   public static Button reverseIndexWheel;
@@ -83,6 +82,13 @@ public class OI {
       toggleWinch.whenPressed(new MaintainClimbedPosition());
       isClimbing = false;
     }
+    /*
+     * if (!Robot.getDriveTrain().isClimbing()) { toggleWinch.whenPressed(new
+     * RunWinchContinuous()); Robot.getDriveTrain().setClimbing(true); } else {
+     * toggleWinch.whenPressed(new MaintainClimbedPosition());
+     * Robot.getDriveTrain().setClimbing(false); }
+     */
+    toggleWinch.whenPressed(new ToggleWinch());
   }
 
   public static OI getOI() {
diff --git a/src/org/usfirst/frc/team3501/robot/commandgroups/ToggleWinch.java b/src/org/usfirst/frc/team3501/robot/commandgroups/ToggleWinch.java
new file mode 100644 (file)
index 0000000..3766aee
--- /dev/null
@@ -0,0 +1,22 @@
+package org.usfirst.frc.team3501.robot.commandgroups;
+
+import org.usfirst.frc.team3501.robot.Robot;
+import org.usfirst.frc.team3501.robot.commands.climber.MaintainClimbedPosition;
+import org.usfirst.frc.team3501.robot.commands.climber.RunWinchContinuous;
+
+import edu.wpi.first.wpilibj.command.CommandGroup;
+
+public class ToggleWinch extends CommandGroup {
+
+  public ToggleWinch() {
+    if (!Robot.getDriveTrain().isClimbing()) {
+      Robot.getDriveTrain().setClimbing(true);
+      addSequential(new RunWinchContinuous());
+
+    } else {
+      Robot.getDriveTrain().setClimbing(false);
+      addSequential(new MaintainClimbedPosition());
+    }
+  }
+
+}
index 2a4ccf7788d3f7a44b6d98a28859b3f0af1830f7..0718539d16a534e7a4dd3bfc69c21c40b1ec4fdc 100644 (file)
@@ -118,6 +118,7 @@ public class DriveTrain extends Subsystem {
 
     frontRight.set(-right);
     rearRight.set(-right);
+    this.isClimbing = true;
   }
 
   public void joystickDrive(final double thrust, final double twist) {
@@ -126,6 +127,7 @@ public class DriveTrain extends Subsystem {
 
   public void stop() {
     setMotorValues(0, 0);
+    this.isClimbing = false;
   }
 
   public double getLeftMotorVal() {
@@ -229,6 +231,10 @@ public class DriveTrain extends Subsystem {
     return this.isClimbing;
   }
 
+  public void setClimbing(boolean isClimbing) {
+    this.isClimbing = isClimbing;
+  }
+
   public double getClimbingSpeed() {
     return this.CLIMBER_SPEED;
   }