f457ba57c57cf04b7fd472f3d8980661a158e412
[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.0003, wheelI = 0, wheelD = -0.00004;
15 private static Shooter shooter;
16 private static HallEffectSensor hallEffect;
17 private final CANTalon flyWheel1, flyWheel2, indexWheel;
18
19 public static final double DEFAULT_INDEXING_SPEED = -1.0;
20 public static final double DEFAULT_SHOOTING_SPEED = 0.75;
21 public static double CURRENT_SHOOTING_SPEED = DEFAULT_SHOOTING_SPEED;
22
23 public static final double SHOOTING_SPEED_INCREMENT = 0.05;
24
25 private final 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.DriveTrain.MODULE_NUMBER,
35 Constants.Shooter.PISTON_FORWARD, Constants.Shooter.PISTON_REVERSE);
36 }
37
38 public static HallEffectSensor getHallEffectSensor() {
39 return hallEffect;
40 }
41
42 /**
43 * Returns shooter object
44 *
45 * @return Shooter object
46 */
47 public static Shooter getShooter() {
48 if (shooter == null) {
49 shooter = new Shooter();
50 }
51 return shooter;
52 }
53
54 /**
55 * Sets fly wheel motor value to input.
56 *
57 * @param val
58 * motor value from -1 to 1(fastest forward)
59 */
60 public void setFlyWheelMotorVal(double val) {
61 val = MathLib.restrictToRange(val, 0.0, 1.0);
62 flyWheel1.set(val);
63 flyWheel2.set(val);
64 }
65
66 /**
67 * Stops fly wheel motor.
68 */
69 public void stopFlyWheel() {
70 flyWheel1.set(0);
71 flyWheel2.set(0);
72 }
73
74 /**
75 * Sets index wheel motor value to input.
76 *
77 * @param val
78 * motor value from -1 to 1(fastest forward)
79 */
80 public void setIndexWheelMotorVal(double val) {
81 val = MathLib.restrictToRange(val, -1.0, 1.0);
82 indexWheel.set(val);
83 }
84
85 /**
86 * Stops index wheel motor.
87 */
88 public void stopIndexWheel() {
89 indexWheel.set(0);
90 }
91
92 public double getCurrentShootingSpeed() {
93 return CURRENT_SHOOTING_SPEED;
94 }
95
96 public void setCurrentShootingSpeed(double Value) {
97 CURRENT_SHOOTING_SPEED = Value;
98 }
99
100 @Override
101 protected void initDefaultCommand() {
102
103 }
104
105 public double getShooterRPM() {
106 return hallEffect.getRPM();
107 }
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 }
124 }