From: EvanYap Date: Thu, 21 Jan 2016 04:23:14 +0000 (-0800) Subject: Creates methods for setting speed, adding to speed, and subtracting from speed along... X-Git-Url: http://challenge-bot.com/repos/?a=commitdiff_plain;h=cb3389ebe0d39363292bfde20bb5345bd1e34253;hp=40348cabbc95d9cb1253b78e61783933e6a33af6;p=3501%2Fstronghold-2016 Creates methods for setting speed, adding to speed, and subtracting from speed along with buttons corresponding to their actions --- diff --git a/src/org/usfirst/frc/team3501/robot/Constants.java b/src/org/usfirst/frc/team3501/robot/Constants.java index eaf8bc62..564f7a14 100644 --- a/src/org/usfirst/frc/team3501/robot/Constants.java +++ b/src/org/usfirst/frc/team3501/robot/Constants.java @@ -11,6 +11,8 @@ public class Constants { public final static int LEFT_STICK_PORT = 0; public final static int RIGHT_STICK_PORT = 0; public final static int RIGHT_STICK_TRIGGER = 0; + public final static int RIGHT_STICK_LEFT_SILVER_BUTTON = 0; + public final static int RIGHT_STICK_RIGHT_SILVER_BUTTON = 0; } public static class DriveTrain { diff --git a/src/org/usfirst/frc/team3501/robot/OI.java b/src/org/usfirst/frc/team3501/robot/OI.java index 997be71c..0bf9e3a4 100644 --- a/src/org/usfirst/frc/team3501/robot/OI.java +++ b/src/org/usfirst/frc/team3501/robot/OI.java @@ -1,14 +1,27 @@ package org.usfirst.frc.team3501.robot; import edu.wpi.first.wpilibj.Joystick; +import edu.wpi.first.wpilibj.buttons.Button; +import edu.wpi.first.wpilibj.buttons.JoystickButton; public class OI { public static Joystick leftJoystick; public static Joystick rightJoystick; + public static Button leftSilverButton; + public static Button rightSilverButton; public OI() { leftJoystick = new Joystick(Constants.OI.LEFT_STICK_PORT); rightJoystick = new Joystick(Constants.OI.RIGHT_STICK_PORT); + leftSilverButton = new JoystickButton(rightJoystick, + Constants.OI.RIGHT_STICK_LEFT_SILVER_BUTTON); + ; + + rightSilverButton = new JoystickButton(rightJoystick, + Constants.OI.RIGHT_STICK_RIGHT_SILVER_BUTTON); + ; + } + } diff --git a/src/org/usfirst/frc/team3501/robot/commands/ShooterTest.java b/src/org/usfirst/frc/team3501/robot/commands/ShooterTest.java index 21666071..da1fc777 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/ShooterTest.java +++ b/src/org/usfirst/frc/team3501/robot/commands/ShooterTest.java @@ -1,7 +1,6 @@ package org.usfirst.frc.team3501.robot.commands; -import org.usfirst.frc.team3501.robot.OI; -import org.usfirst.frc.team3501.robot.subsystems.Shooter; +import org.usfirst.frc.team3501.robot.Robot; import edu.wpi.first.wpilibj.command.Command; @@ -9,24 +8,38 @@ import edu.wpi.first.wpilibj.command.Command; * */ public class ShooterTest extends Command { - public static Shooter shooter; - public static OI oi; public ShooterTest() { - // Use requires() here to declare subsystem dependencies - // eg. requires(chassis); - requires(shooter); + + requires(Robot.shooter); } - // 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() { + boolean triggerPressed = Robot.oi.rightJoystick.getTrigger(); + boolean leftSidePressed = Robot.oi.leftSilverButton.get(); + boolean rightSidePressed = Robot.oi.rightSilverButton.get(); + + double currentWheelSpeed = Robot.shooter.getCurrentSpeed(); + + if (triggerPressed = true) { + Robot.shooter.setSpeed(currentWheelSpeed); + } else { + Robot.shooter.setSpeed(0.0); + } + + if (leftSidePressed = true) { + Robot.shooter.setDecrementSpeed(0.1); + } + + if (rightSidePressed = true) { + Robot.shooter.setIncrementSpeed(0.1); + } + } // Make this return true when this Command no longer needs to run execute() diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java index b916c044..614fe059 100755 --- a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java @@ -12,6 +12,40 @@ public class Shooter extends Subsystem { wheel = new CANTalon(Constants.Shooter.SHOOTER_WHEEL_PORT); } + public double getCurrentSpeed() { + return wheel.get(); + } + + public void setSpeed(double speed) { + wheel.set(speed); + } + + public void setIncrementSpeed(double increment) { + double newSpeed = getCurrentSpeed() + increment; + + if (getCurrentSpeed() >= 1.0) { + wheel.set(1.0); + } else if (getCurrentSpeed() <= -1.0) { + wheel.set(-1.0); + } + + wheel.set(newSpeed); + } + + // THIS DECREMENT METHOD TAKES ONLY POSITIVE VALUES SINCE IT ACCOUNTS FOR + // SUBTRACTING THE CURRENT MOTOR SPEED! + public void setDecrementSpeed(double decrement) { + double newSpeed = getCurrentSpeed() - decrement; + + if (getCurrentSpeed() >= 1.0) { + wheel.set(1.0); + } else if (getCurrentSpeed() <= -1.0) { + wheel.set(-1.0); + } + + wheel.set(newSpeed); + } + @Override protected void initDefaultCommand() {