X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=src%2Forg%2Fusfirst%2Ffrc%2Fteam3501%2Frobot%2Fsubsystems%2FShooter.java;h=bf743b1a3195139d8ec59c73f4d5f713087458e3;hb=f56e6ebf87134eccc3b8bb0e1d2529bd6cb061dd;hp=7a11c2d74440abff3dea25a9c2e60adbaad0e4d4;hpb=ac77a7b890c794f807b764221ff72d9044791fab;p=3501%2F2017steamworks diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java index 7a11c2d..bf743b1 100644 --- a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java @@ -3,22 +3,27 @@ package org.usfirst.frc.team3501.robot.subsystems; import org.usfirst.frc.team3501.robot.Constants; import org.usfirst.frc.team3501.robot.MathLib; import org.usfirst.frc.team3501.robot.utils.HallEffectSensor; +import org.usfirst.frc.team3501.robot.utils.PIDController; import com.ctre.CANTalon; import edu.wpi.first.wpilibj.command.Subsystem; public class Shooter extends Subsystem { - public double wheelP = 0.0003, wheelI = 0, wheelD = -0.00004; + public double wheelP = 0.00007, wheelI = 0, wheelD = 0.0008; private static Shooter shooter; private static HallEffectSensor hallEffect; private final CANTalon flyWheel1, flyWheel2, indexWheel; - public static final double DEFAULT_INDEXING_SPEED = -1.0; - public static final double DEFAULT_SHOOTING_SPEED = 0.75; - public static double CURRENT_SHOOTING_SPEED = DEFAULT_SHOOTING_SPEED; + private PIDController wheelController; - public static final double SHOOTING_SPEED_INCREMENT = 0.05; + private static final double RPM_THRESHOLD = 10; + private static final double DEFAULT_INDEXING_MOTOR_VALUE = 0.75; + private static final double DEFAULT_SHOOTING_SPEED = 2800; // rpm + private static final double SHOOTING_SPEED_INCREMENT = 50; + + private double targetShootingSpeed = DEFAULT_SHOOTING_SPEED; + private double currentShooterMotorValue = 0; private Shooter() { flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1); @@ -28,10 +33,6 @@ public class Shooter extends Subsystem { hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1); } - public static HallEffectSensor getHallEffectSensor() { - return hallEffect; - } - /** * Returns shooter object * @@ -82,20 +83,61 @@ public class Shooter extends Subsystem { indexWheel.set(0); } - public double getCurrentShootingSpeed() { - return CURRENT_SHOOTING_SPEED; - } - - public void setCurrentShootingSpeed(double Value) { - CURRENT_SHOOTING_SPEED = Value; - } - @Override protected void initDefaultCommand() { } + public double getRPMThreshold() { + return RPM_THRESHOLD; + } + public double getShooterRPM() { return hallEffect.getRPM(); } + + public void setTargetShootingSpeed(double Value) { + targetShootingSpeed = Value; + } + + public void decrementTargetShootingSpeed() { + this.targetShootingSpeed -= this.SHOOTING_SPEED_INCREMENT; + } + + public void incrementTargetShootingSpeed() { + this.targetShootingSpeed += this.SHOOTING_SPEED_INCREMENT; + } + + public void resetTargetShootingSpeed() { + this.targetShootingSpeed = this.DEFAULT_SHOOTING_SPEED; + } + + public double getTargetShootingSpeed() { + return targetShootingSpeed; + } + + public void reverseIndexWheel() { + this.setIndexWheelMotorVal(-DEFAULT_INDEXING_MOTOR_VALUE); + } + + public void runIndexWheel() { + this.setIndexWheelMotorVal(DEFAULT_INDEXING_MOTOR_VALUE); + } + + public double calculateShooterSpeed() { + this.wheelController.setSetPoint(targetShootingSpeed); + double calculatedShooterIncrement = this.wheelController + .calcPID(this.getShooterRPM()); + currentShooterMotorValue += calculatedShooterIncrement; + return currentShooterMotorValue; + } + + public void initializePIDController() { + this.wheelController = new PIDController(wheelP, wheelI, wheelD); + this.wheelController.setDoneRange(10); + this.wheelController.setMaxOutput(1.0); + this.wheelController.setMinDoneCycles(3); + this.wheelController.setSetPoint(this.targetShootingSpeed); + this.currentShooterMotorValue = 0; + } }