fix indexing piston code
[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
69214544
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 {
ac77a7b8 14 public double wheelP = 0.0003, wheelI = 0, wheelD = -0.00004;
079a8cb6 15 private static Shooter shooter;
268b0048 16 private static HallEffectSensor hallEffect;
3a86b1a5 17 private final CANTalon flyWheel1, flyWheel2, indexWheel;
79ba119a 18
ac77a7b8 19 public static final double DEFAULT_INDEXING_SPEED = -1.0;
58bcc21d 20 public static final double DEFAULT_SHOOTING_SPEED = 0.75;
cf77d84e 21 public static double CURRENT_SHOOTING_SPEED = DEFAULT_SHOOTING_SPEED;
ad7e6b1e 22
58bcc21d 23 public static final double SHOOTING_SPEED_INCREMENT = 0.05;
ad7e6b1e 24
69214544
RR
25 private final DoubleSolenoid piston;
26
079a8cb6 27 private Shooter() {
3a86b1a5
CZ
28 flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1);
29 flyWheel2 = new CANTalon(Constants.Shooter.FLY_WHEEL2);
04227dc0 30 indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL);
ad7e6b1e 31
268b0048 32 hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1);
69214544 33
8e45a057 34 piston = new DoubleSolenoid(Constants.Shooter.MODULE_NUMBER,
69214544 35 Constants.Shooter.PISTON_FORWARD, Constants.Shooter.PISTON_REVERSE);
268b0048 36 }
37
38 public static HallEffectSensor getHallEffectSensor() {
39 return hallEffect;
079a8cb6 40 }
41dfad94 41
04227dc0 42 /**
43 * Returns shooter object
44 *
45 * @return Shooter object
46 */
079a8cb6
CZ
47 public static Shooter getShooter() {
48 if (shooter == null) {
49 shooter = new Shooter();
50 }
51 return shooter;
52 }
41dfad94 53
079a8cb6 54 /**
04227dc0 55 * Sets fly wheel motor value to input.
56 *
57 * @param val
58 * motor value from -1 to 1(fastest forward)
079a8cb6 59 */
ac77a7b8
CZ
60 public void setFlyWheelMotorVal(double val) {
61 val = MathLib.restrictToRange(val, 0.0, 1.0);
3a86b1a5
CZ
62 flyWheel1.set(val);
63 flyWheel2.set(val);
079a8cb6 64 }
41dfad94 65
04227dc0 66 /**
67 * Stops fly wheel motor.
68 */
69 public void stopFlyWheel() {
3a86b1a5
CZ
70 flyWheel1.set(0);
71 flyWheel2.set(0);
04227dc0 72 }
41dfad94 73
04227dc0 74 /**
75 * Sets index wheel motor value to input.
76 *
77 * @param val
78 * motor value from -1 to 1(fastest forward)
79 */
ac77a7b8
CZ
80 public void setIndexWheelMotorVal(double val) {
81 val = MathLib.restrictToRange(val, -1.0, 1.0);
04227dc0 82 indexWheel.set(val);
079a8cb6 83 }
41dfad94 84
079a8cb6 85 /**
04227dc0 86 * Stops index wheel motor.
079a8cb6
CZ
87 */
88 public void stopIndexWheel() {
04227dc0 89 indexWheel.set(0);
079a8cb6 90 }
41dfad94 91
09e509d3
NA
92 public double getCurrentShootingSpeed() {
93 return CURRENT_SHOOTING_SPEED;
94 }
95
96 public void setCurrentShootingSpeed(double Value) {
97 CURRENT_SHOOTING_SPEED = Value;
98 }
99
04227dc0 100 @Override
101 protected void initDefaultCommand() {
079a8cb6
CZ
102
103 }
381dad77 104
268b0048 105 public double getShooterRPM() {
106 return hallEffect.getRPM();
381dad77 107 }
69214544
RR
108
109 public Value getPistonValue() {
110 return piston.get();
111 }
112
113 public void setHighGear() {
114 changeGear(Constants.Shooter.HIGH_GEAR);
115 }
116
117 public void setLowGear() {
118 changeGear(Constants.Shooter.LOW_GEAR);
119 }
120
121 private void changeGear(DoubleSolenoid.Value gear) {
122 piston.set(gear);
123 }
79ba119a 124}