Finalize piston code in Shooter subsystem
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / subsystems / Shooter.java
1 package org.usfirst.frc.team3501.robot.subsystems;
2
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
7 import com.ctre.CANTalon;
8
9 import edu.wpi.first.wpilibj.DoubleSolenoid;
10 import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
11 import edu.wpi.first.wpilibj.command.Subsystem;
12
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;
18
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;
22
23 private double currentShootingSpeed = DEFAULT_SHOOTING_SPEED;
24
25 private DoubleSolenoid piston;
26
27 private Shooter() {
28 flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1);
29 flyWheel2 = new CANTalon(Constants.Shooter.FLY_WHEEL2);
30 indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL);
31
32 hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1);
33
34 piston = new DoubleSolenoid(Constants.Shooter.PISTON_MODULE,
35 Constants.Shooter.PISTON_FORWARD, Constants.Shooter.PISTON_REVERSE);
36 }
37
38 /**
39 * Returns shooter object
40 *
41 * @return Shooter object
42 */
43 public static Shooter getShooter() {
44 if (shooter == null) {
45 shooter = new Shooter();
46 }
47 return shooter;
48 }
49
50 /**
51 * Sets fly wheel motor value to input.
52 *
53 * @param val
54 * motor value from -1 to 1(fastest forward)
55 */
56 public void setFlyWheelMotorVal(double val) {
57 val = MathLib.restrictToRange(val, 0.0, 1.0);
58 flyWheel1.set(val);
59 flyWheel2.set(val);
60 }
61
62 /**
63 * Stops fly wheel motor.
64 */
65 public void stopFlyWheel() {
66 flyWheel1.set(0);
67 flyWheel2.set(0);
68 }
69
70 /**
71 * Sets index wheel motor value to input.
72 *
73 * @param val
74 * motor value from -1 to 1(fastest forward)
75 */
76 public void setIndexWheelMotorVal(double val) {
77 val = MathLib.restrictToRange(val, -1.0, 1.0);
78 indexWheel.set(val);
79 }
80
81 /**
82 * Stops index wheel motor.
83 */
84 public void stopIndexWheel() {
85 indexWheel.set(0);
86 }
87
88 @Override
89 protected void initDefaultCommand() {
90
91 }
92
93 public double getShooterRPM() {
94 return hallEffect.getRPM();
95 }
96
97 public void setCurrentShootingSpeed(double Value) {
98 currentShootingSpeed = Value;
99 }
100
101 public void decrementCurrentShootingSpeed() {
102 this.currentShootingSpeed -= this.SHOOTING_SPEED_INCREMENT;
103 }
104
105 public void incrementCurrentShootingSpeed() {
106 this.currentShootingSpeed += this.SHOOTING_SPEED_INCREMENT;
107 }
108
109 public void resetCurrentShootingSpeed() {
110 this.currentShootingSpeed = this.DEFAULT_SHOOTING_SPEED;
111 }
112
113 public double getCurrentShootingSpeed() {
114 return currentShootingSpeed;
115 }
116
117 public void reverseIndexWheel() {
118 this.setIndexWheelMotorVal(-DEFAULT_INDEXING_SPEED);
119 }
120
121 public void runIndexWheel() {
122 this.setIndexWheelMotorVal(DEFAULT_INDEXING_SPEED);
123 }
124
125 public Value getPistonValue() {
126 return piston.get();
127 }
128
129 public void setHighGear() {
130 changeGear(Constants.Shooter.HIGH_GEAR);
131 }
132
133 public void setLowGear() {
134 changeGear(Constants.Shooter.LOW_GEAR);
135 }
136
137 private void changeGear(DoubleSolenoid.Value gear) {
138 piston.set(gear);
139 }
140 }