add corrections
[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.utils.HallEffectSensor;
5
6 import com.ctre.CANTalon;
7
8 import edu.wpi.first.wpilibj.command.Subsystem;
9
10 public class Shooter extends Subsystem {
11 private double wheelP = 0, wheelI = 0, wheelD = -0;
12 private static Shooter shooter;
13 private HallEffectSensor hallEffect;
14 private final CANTalon flyWheel1, flyWheel2, indexWheel;
15
16 private static final double DEFAULT_INDEXING_SPEED = -0.75;
17 private static final double DEFAULT_SHOOTING_SPEED = 0.75;
18 private double currentShootingSpeed = DEFAULT_SHOOTING_SPEED;
19
20 private static final double SHOOTING_SPEED_INCREMENT = 0.05;
21
22 private Shooter() {
23 flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1);
24 flyWheel2 = new CANTalon(Constants.Shooter.FLY_WHEEL2);
25 indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL);
26
27 hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1);
28 }
29
30 /**
31 * Returns shooter object
32 *
33 * @return Shooter object
34 */
35 public static Shooter getShooter() {
36 if (shooter == null) {
37 shooter = new Shooter();
38 }
39 return shooter;
40 }
41
42 /**
43 * Sets fly wheel motor value to input.
44 *
45 * @param val
46 * motor value from -1 to 1(fastest forward)
47 */
48 private void setFlyWheelMotorVal(final double val) {
49 flyWheel1.set(val);
50 flyWheel2.set(val);
51 }
52
53 public void incrementCurrentShootingSpeed() {
54 currentShootingSpeed += SHOOTING_SPEED_INCREMENT;
55 }
56
57 public void runFlyWheel() {
58 flyWheel1.set(currentShootingSpeed);
59 }
60
61 /**
62 * Stops fly wheel motor.
63 */
64 public void stopFlyWheel() {
65 flyWheel1.set(0);
66 flyWheel2.set(0);
67 }
68
69 /**
70 * Stops index wheel motor.
71 */
72 public void stopIndexWheel() {
73 indexWheel.set(0);
74 }
75
76 /**
77 * Run the index wheel forwards
78 */
79 public void runIndexWheelForward() {
80 indexWheel.set(currentShootingSpeed);
81 }
82
83 /**
84 * Run the index wheel backwards
85 */
86 public void runIndexWheelReverse() {
87 indexWheel.set(-currentShootingSpeed);
88 }
89
90 @Override
91 protected void initDefaultCommand() {
92
93 }
94
95 public double getShooterRPM() {
96 return hallEffect.getRPM();
97 }
98
99 public void decrementCurrentShootingSpeed() {
100 currentShootingSpeed -= SHOOTING_SPEED_INCREMENT;
101
102 }
103
104 public void resetCurrentShootingSpeed() {
105 currentShootingSpeed = DEFAULT_SHOOTING_SPEED;
106 }
107
108 /**
109 * @return the wheelP
110 */
111 public double getWheelP() {
112 return wheelP;
113 }
114
115 /**
116 * @return the wheelI
117 */
118 public double getWheelI() {
119 return wheelI;
120 }
121
122 /**
123 * @return the wheelD
124 */
125 public double getWheelD() {
126 return wheelD;
127 }
128
129 /**
130 * @return the currentShootingSpeed
131 */
132 public double getShootingSpeed() {
133 return currentShootingSpeed;
134 }
135
136 }