Make command for running the shooter when trigger is pressed
authorEvanYap <evanyap.14@gmail.com>
Fri, 22 Jan 2016 03:16:24 +0000 (19:16 -0800)
committerKevin Zhang <icestormf1@gmail.com>
Sat, 23 Jan 2016 03:37:35 +0000 (19:37 -0800)
src/org/usfirst/frc/team3501/robot/OI.java
src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java [deleted file]
src/org/usfirst/frc/team3501/robot/commands/runShooter.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java [new file with mode: 0644]
src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java

index 4367d6ae50ea68a7b3d2bda87707e826c42abc7a..c93ce127ac1cc777d3e7b696721143e17f6ab4ae 100644 (file)
@@ -1,6 +1,7 @@
 package org.usfirst.frc.team3501.robot;
 
-import org.usfirst.frc.team3501.robot.commands.changeSpeed;
+import org.usfirst.frc.team3501.robot.commands.runShooter;
+import org.usfirst.frc.team3501.robot.commands.setShooterSpeed;
 
 import edu.wpi.first.wpilibj.Joystick;
 import edu.wpi.first.wpilibj.buttons.Button;
@@ -20,19 +21,17 @@ public class OI {
 
     decrementSpeed = new JoystickButton(rightJoystick,
         Constants.OI.DECREMENT_SHOOTER_PORT);
+    decrementSpeed.whenPressed(new setShooterSpeed(-0.1));
 
     incrementSpeed = new JoystickButton(rightJoystick,
         Constants.OI.INCREMENT_SHOOTER_PORT);
+    incrementSpeed.whenPressed(new setShooterSpeed(0.1));
 
     outputCurrentShooterSpeed = new JoystickButton(rightJoystick,
         Constants.OI.SHOOTER_PORT);
 
     runWheel = new JoystickButton(rightJoystick, Constants.OI.TRIGGER_PORT);
-
-    incrementSpeed.whenPressed(new changeSpeed(0.1));
-
-    decrementSpeed.whenPressed(new changeSpeed(-0.1));
-
+    runWheel.whenPressed(new runShooter());
   }
 
 }
diff --git a/src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java b/src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java
deleted file mode 100644 (file)
index 4928d87..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.usfirst.frc.team3501.robot.commands;
-
-import org.usfirst.frc.team3501.robot.Robot;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-public class changeSpeed extends Command {
-  double change = 0.0;
-
-  public changeSpeed(double change) {
-    this.change = change;
-  }
-
-  @Override
-  protected void initialize() {
-  }
-
-  @Override
-  protected void execute() {
-    Robot.shooter.changeSpeed(change);
-  }
-
-  @Override
-  protected boolean isFinished() {
-    return true;
-  }
-
-  @Override
-  protected void end() {
-  }
-
-  @Override
-  protected void interrupted() {
-  }
-}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/runShooter.java b/src/org/usfirst/frc/team3501/robot/commands/runShooter.java
new file mode 100644 (file)
index 0000000..3d87624
--- /dev/null
@@ -0,0 +1,37 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+import org.usfirst.frc.team3501.robot.Robot;
+
+import edu.wpi.first.wpilibj.command.Command;
+
+/**
+ *
+ */
+public class runShooter extends Command {
+
+  public runShooter() {
+
+  }
+
+  @Override
+  protected void initialize() {
+    Robot.shooter.setSpeed(0.5);
+  }
+
+  @Override
+  protected void execute() {
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return true;
+  }
+
+  @Override
+  protected void end() {
+  }
+
+  @Override
+  protected void interrupted() {
+  }
+}
diff --git a/src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java b/src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java
new file mode 100644 (file)
index 0000000..197da91
--- /dev/null
@@ -0,0 +1,41 @@
+package org.usfirst.frc.team3501.robot.commands;
+
+import org.usfirst.frc.team3501.robot.Robot;
+
+import edu.wpi.first.wpilibj.command.Command;
+
+public class setShooterSpeed extends Command {
+  double change = 0.0;
+  double speed = Robot.shooter.getCurrentSpeed();
+
+  public setShooterSpeed(double speed) {
+    this.speed = speed;
+  }
+
+  public setShooterSpeed(double speed, double change) {
+    this.speed = speed;
+    this.change = change;
+  }
+
+  @Override
+  protected void initialize() {
+  }
+
+  @Override
+  protected void execute() {
+    Robot.shooter.setSpeed(change);
+  }
+
+  @Override
+  protected boolean isFinished() {
+    return true;
+  }
+
+  @Override
+  protected void end() {
+  }
+
+  @Override
+  protected void interrupted() {
+  }
+}
index 51bccd2832413efef480bf029ec6fa9fe8d0365a..4ad89fd30469342ca1dcc3c086ee739b500e1eca 100755 (executable)
@@ -22,9 +22,9 @@ public class Shooter extends Subsystem {
 \r
   // Use negative # for decrement. Positive for increment.\r
   public void changeSpeed(double change) {\r
-    if (getCurrentSpeed() >= 1.0)\r
+    if (getCurrentSpeed() + change >= 1.0)\r
       shooter.set(1.0);\r
-    else if (getCurrentSpeed() <= -1.0)\r
+    else if (getCurrentSpeed() + change <= -1.0)\r
       shooter.set(-1.0);\r
     else {\r
       double newSpeed = getCurrentSpeed() + change;\r