Add piston getters in Shooter
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / subsystems / Shooter.java
CommitLineData
79ba119a 1package org.usfirst.frc.team3501.robot.subsystems;
2
04227dc0 3import org.usfirst.frc.team3501.robot.Constants;
ac77a7b8 4import org.usfirst.frc.team3501.robot.MathLib;
268b0048 5import org.usfirst.frc.team3501.robot.utils.HallEffectSensor;
04227dc0 6
7import com.ctre.CANTalon;
8
5ab65eab
RR
9import edu.wpi.first.wpilibj.DoubleSolenoid;
10import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
04227dc0 11import edu.wpi.first.wpilibj.command.Subsystem;
12
13public class Shooter extends Subsystem {
1782cbad 14 public double wheelP = 0.0001, wheelI = 0, wheelD = 0.0004;
079a8cb6 15 private static Shooter shooter;
268b0048 16 private static HallEffectSensor hallEffect;
3a86b1a5 17 private final CANTalon flyWheel1, flyWheel2, indexWheel;
79ba119a 18
f625e57a 19 private static final double DEFAULT_INDEXING_SPEED = -0.75;
005d6bf0 20 private static final double DEFAULT_SHOOTING_SPEED = 2800; // rpm
f625e57a 21 private static final double SHOOTING_SPEED_INCREMENT = 25;
ad7e6b1e 22
f625e57a 23 private double currentShootingSpeed = DEFAULT_SHOOTING_SPEED;
ad7e6b1e 24
079a8cb6 25 private Shooter() {
3a86b1a5
CZ
26 flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1);
27 flyWheel2 = new CANTalon(Constants.Shooter.FLY_WHEEL2);
04227dc0 28 indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL);
ad7e6b1e 29
268b0048 30 hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1);
31 }
32
04227dc0 33 /**
34 * Returns shooter object
35 *
36 * @return Shooter object
37 */
079a8cb6
CZ
38 public static Shooter getShooter() {
39 if (shooter == null) {
40 shooter = new Shooter();
41 }
42 return shooter;
43 }
41dfad94 44
079a8cb6 45 /**
04227dc0 46 * Sets fly wheel motor value to input.
47 *
48 * @param val
49 * motor value from -1 to 1(fastest forward)
079a8cb6 50 */
ac77a7b8
CZ
51 public void setFlyWheelMotorVal(double val) {
52 val = MathLib.restrictToRange(val, 0.0, 1.0);
3a86b1a5
CZ
53 flyWheel1.set(val);
54 flyWheel2.set(val);
079a8cb6 55 }
41dfad94 56
04227dc0 57 /**
58 * Stops fly wheel motor.
59 */
60 public void stopFlyWheel() {
3a86b1a5
CZ
61 flyWheel1.set(0);
62 flyWheel2.set(0);
04227dc0 63 }
41dfad94 64
04227dc0 65 /**
66 * Sets index wheel motor value to input.
67 *
68 * @param val
69 * motor value from -1 to 1(fastest forward)
70 */
ac77a7b8
CZ
71 public void setIndexWheelMotorVal(double val) {
72 val = MathLib.restrictToRange(val, -1.0, 1.0);
04227dc0 73 indexWheel.set(val);
079a8cb6 74 }
41dfad94 75
079a8cb6 76 /**
04227dc0 77 * Stops index wheel motor.
079a8cb6
CZ
78 */
79 public void stopIndexWheel() {
04227dc0 80 indexWheel.set(0);
079a8cb6 81 }
41dfad94 82
f625e57a
CZ
83 @Override
84 protected void initDefaultCommand() {
85
86 }
87
88 public double getShooterRPM() {
89 return hallEffect.getRPM();
09e509d3
NA
90 }
91
92 public void setCurrentShootingSpeed(double Value) {
f625e57a 93 currentShootingSpeed = Value;
09e509d3
NA
94 }
95
f625e57a
CZ
96 public void decrementCurrentShootingSpeed() {
97 this.currentShootingSpeed -= this.SHOOTING_SPEED_INCREMENT;
98 }
079a8cb6 99
f625e57a
CZ
100 public void incrementCurrentShootingSpeed() {
101 this.currentShootingSpeed += this.SHOOTING_SPEED_INCREMENT;
079a8cb6 102 }
381dad77 103
f625e57a
CZ
104 public void resetCurrentShootingSpeed() {
105 this.currentShootingSpeed = this.DEFAULT_SHOOTING_SPEED;
106 }
107
108 public double getCurrentShootingSpeed() {
109 return currentShootingSpeed;
110 }
111
112 public void reverseIndexWheel() {
113 this.setIndexWheelMotorVal(-DEFAULT_INDEXING_SPEED);
114 }
115
116 public void runIndexWheel() {
117 this.setIndexWheelMotorVal(DEFAULT_INDEXING_SPEED);
381dad77 118 }
5ab65eab
RR
119
120 public Value getPistonValue() {
121 return piston.get();
122 }
123
124 public void setHighGear() {
125 changeGear(Constants.Shooter.HIGH_GEAR);
126 }
127
128 public void setLowGear() {
129 changeGear(Constants.Shooter.LOW_GEAR);
130 }
131
132 private void changeGear(DoubleSolenoid.Value gear) {
133 piston.set(gear);
134 }
79ba119a 135}