1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
4 import org
.usfirst
.frc
.team3501
.robot
.MathLib
;
5 import org
.usfirst
.frc
.team3501
.robot
.utils
.HallEffectSensor
;
6 import org
.usfirst
.frc
.team3501
.robot
.utils
.PIDController
;
8 import com
.ctre
.CANTalon
;
10 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
;
11 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
.Value
;
12 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
14 public class Shooter
extends Subsystem
{
15 public double wheelP
= 0.00007, wheelI
= 0, wheelD
= 0.0008;
16 private static Shooter shooter
;
17 private static HallEffectSensor hallEffect
;
18 private final CANTalon flyWheel1
, flyWheel2
, indexWheel
;
20 private PIDController wheelController
;
22 private static final double RPM_THRESHOLD
= 10;
23 private static final double DEFAULT_INDEXING_MOTOR_VALUE
= 0.75;
24 private static final double REVERSE_FLYWHEEL_MOTOR_VALUE
= -0.75;
25 private static final double DEFAULT_SHOOTING_SPEED
= 2700; // rpm
26 private static final double SHOOTING_SPEED_INCREMENT
= 50;
28 private double targetShootingSpeed
= DEFAULT_SHOOTING_SPEED
;
29 private double currentShooterMotorValue
= 0;
31 private final DoubleSolenoid piston
;
34 flyWheel1
= new CANTalon(Constants
.Shooter
.FLY_WHEEL1
);
35 flyWheel2
= new CANTalon(Constants
.Shooter
.FLY_WHEEL2
);
36 indexWheel
= new CANTalon(Constants
.Shooter
.INDEX_WHEEL
);
38 hallEffect
= new HallEffectSensor(Constants
.Shooter
.HALL_EFFECT_PORT
, 1);
40 piston
= new DoubleSolenoid(Constants
.Shooter
.MODULE_NUMBER
,
41 Constants
.Shooter
.PISTON_FORWARD
, Constants
.Shooter
.PISTON_REVERSE
);
45 * Returns shooter object
47 * @return Shooter object
49 public static Shooter
getShooter() {
50 if (shooter
== null) {
51 shooter
= new Shooter();
57 * Sets fly wheel motor value to input.
60 * motor value from -1 to 1(fastest forward)
62 public void setFlyWheelMotorVal(double val
) {
63 val
= MathLib
.restrictToRange(val
, 0.0, 1.0);
69 * Stops fly wheel motor.
71 public void stopFlyWheel() {
77 * Sets index wheel motor value to input.
80 * motor value from -1 to 1(fastest forward)
82 public void setIndexWheelMotorVal(double val
) {
83 val
= MathLib
.restrictToRange(val
, -1.0, 1.0);
88 * Stops index wheel motor.
90 public void stopIndexWheel() {
95 protected void initDefaultCommand() {
99 public double getRPMThreshold() {
100 return RPM_THRESHOLD
;
103 public double getShooterRPM() {
104 return hallEffect
.getRPM();
107 public void setTargetShootingSpeed(double Value
) {
108 targetShootingSpeed
= Value
;
111 public void decrementTargetShootingSpeed() {
112 this.targetShootingSpeed
-= this.SHOOTING_SPEED_INCREMENT
;
115 public void incrementTargetShootingSpeed() {
116 this.targetShootingSpeed
+= this.SHOOTING_SPEED_INCREMENT
;
119 public void resetTargetShootingSpeed() {
120 this.targetShootingSpeed
= this.DEFAULT_SHOOTING_SPEED
;
123 public double getTargetShootingSpeed() {
124 return targetShootingSpeed
;
127 public void reverseIndexWheel() {
128 this.setIndexWheelMotorVal(-DEFAULT_INDEXING_MOTOR_VALUE
);
131 public void runIndexWheel() {
132 this.setIndexWheelMotorVal(DEFAULT_INDEXING_MOTOR_VALUE
);
135 public double calculateShooterSpeed() {
136 this.wheelController
.setSetPoint(targetShootingSpeed
);
137 double calculatedShooterIncrement
= this.wheelController
138 .calcPID(this.getShooterRPM());
139 currentShooterMotorValue
+= calculatedShooterIncrement
;
140 return currentShooterMotorValue
;
143 public void initializePIDController() {
144 this.wheelController
= new PIDController(wheelP
, wheelI
, wheelD
);
145 this.wheelController
.setDoneRange(10);
146 this.wheelController
.setMaxOutput(1.0);
147 this.wheelController
.setMinDoneCycles(3);
148 this.wheelController
.setSetPoint(this.targetShootingSpeed
);
149 this.currentShooterMotorValue
= 0;
152 public Value
getPistonValue() {
156 public void setHighGear() {
157 changeGear(Constants
.Shooter
.HIGH_GEAR
);
160 public void setLowGear() {
161 changeGear(Constants
.Shooter
.LOW_GEAR
);
164 private void changeGear(DoubleSolenoid
.Value gear
) {
168 public void reverseFlyWheel() {
169 this.setFlyWheelMotorVal(shooter
.REVERSE_FLYWHEEL_MOTOR_VALUE
);