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
;
7 import com
.ctre
.CANTalon
;
9 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
;
10 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
.Value
;
11 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
13 public class Shooter
extends Subsystem
{
14 public double wheelP
= 0.0001, wheelI
= 0, wheelD
= 0.0004;
15 private static Shooter shooter
;
16 private static HallEffectSensor hallEffect
;
17 private final CANTalon flyWheel1
, flyWheel2
, indexWheel
;
19 private static final double DEFAULT_INDEXING_SPEED
= -0.75;
20 private static final double DEFAULT_SHOOTING_SPEED
= 2800; // rpm
21 private static final double SHOOTING_SPEED_INCREMENT
= 25;
23 private double currentShootingSpeed
= DEFAULT_SHOOTING_SPEED
;
26 flyWheel1
= new CANTalon(Constants
.Shooter
.FLY_WHEEL1
);
27 flyWheel2
= new CANTalon(Constants
.Shooter
.FLY_WHEEL2
);
28 indexWheel
= new CANTalon(Constants
.Shooter
.INDEX_WHEEL
);
30 hallEffect
= new HallEffectSensor(Constants
.Shooter
.HALL_EFFECT_PORT
, 1);
34 * Returns shooter object
36 * @return Shooter object
38 public static Shooter
getShooter() {
39 if (shooter
== null) {
40 shooter
= new Shooter();
46 * Sets fly wheel motor value to input.
49 * motor value from -1 to 1(fastest forward)
51 public void setFlyWheelMotorVal(double val
) {
52 val
= MathLib
.restrictToRange(val
, 0.0, 1.0);
58 * Stops fly wheel motor.
60 public void stopFlyWheel() {
66 * Sets index wheel motor value to input.
69 * motor value from -1 to 1(fastest forward)
71 public void setIndexWheelMotorVal(double val
) {
72 val
= MathLib
.restrictToRange(val
, -1.0, 1.0);
77 * Stops index wheel motor.
79 public void stopIndexWheel() {
84 protected void initDefaultCommand() {
88 public double getShooterRPM() {
89 return hallEffect
.getRPM();
92 public void setCurrentShootingSpeed(double Value
) {
93 currentShootingSpeed
= Value
;
96 public void decrementCurrentShootingSpeed() {
97 this.currentShootingSpeed
-= this.SHOOTING_SPEED_INCREMENT
;
100 public void incrementCurrentShootingSpeed() {
101 this.currentShootingSpeed
+= this.SHOOTING_SPEED_INCREMENT
;
104 public void resetCurrentShootingSpeed() {
105 this.currentShootingSpeed
= this.DEFAULT_SHOOTING_SPEED
;
108 public double getCurrentShootingSpeed() {
109 return currentShootingSpeed
;
112 public void reverseIndexWheel() {
113 this.setIndexWheelMotorVal(-DEFAULT_INDEXING_SPEED
);
116 public void runIndexWheel() {
117 this.setIndexWheelMotorVal(DEFAULT_INDEXING_SPEED
);
120 public Value
getPistonValue() {
124 public void setHighGear() {
125 changeGear(Constants
.Shooter
.HIGH_GEAR
);
128 public void setLowGear() {
129 changeGear(Constants
.Shooter
.LOW_GEAR
);
132 private void changeGear(DoubleSolenoid
.Value gear
) {