Commit | Line | Data |
---|---|---|
79ba119a | 1 | package org.usfirst.frc.team3501.robot.subsystems; |
2 | ||
04227dc0 | 3 | import org.usfirst.frc.team3501.robot.Constants; |
268b0048 | 4 | import org.usfirst.frc.team3501.robot.utils.HallEffectSensor; |
04227dc0 | 5 | |
6 | import com.ctre.CANTalon; | |
7 | ||
8 | import edu.wpi.first.wpilibj.command.Subsystem; | |
9 | ||
10 | public class Shooter extends Subsystem { | |
6af2bd85 | 11 | private double wheelP = 0, wheelI = 0, wheelD = -0; |
079a8cb6 | 12 | private static Shooter shooter; |
6af2bd85 | 13 | private HallEffectSensor hallEffect; |
3a86b1a5 | 14 | private final CANTalon flyWheel1, flyWheel2, indexWheel; |
79ba119a | 15 | |
6af2bd85 ES |
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; | |
ad7e6b1e | 19 | |
6af2bd85 | 20 | private static final double SHOOTING_SPEED_INCREMENT = 0.05; |
ad7e6b1e | 21 | |
079a8cb6 | 22 | private Shooter() { |
3a86b1a5 CZ |
23 | flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1); |
24 | flyWheel2 = new CANTalon(Constants.Shooter.FLY_WHEEL2); | |
04227dc0 | 25 | indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL); |
ad7e6b1e | 26 | |
268b0048 | 27 | hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1); |
28 | } | |
29 | ||
04227dc0 | 30 | /** |
31 | * Returns shooter object | |
32 | * | |
33 | * @return Shooter object | |
34 | */ | |
079a8cb6 CZ |
35 | public static Shooter getShooter() { |
36 | if (shooter == null) { | |
37 | shooter = new Shooter(); | |
38 | } | |
39 | return shooter; | |
40 | } | |
41dfad94 | 41 | |
079a8cb6 | 42 | /** |
04227dc0 | 43 | * Sets fly wheel motor value to input. |
44 | * | |
45 | * @param val | |
46 | * motor value from -1 to 1(fastest forward) | |
079a8cb6 | 47 | */ |
6af2bd85 | 48 | private void setFlyWheelMotorVal(final double val) { |
3a86b1a5 CZ |
49 | flyWheel1.set(val); |
50 | flyWheel2.set(val); | |
079a8cb6 | 51 | } |
41dfad94 | 52 | |
6af2bd85 ES |
53 | public void incrementCurrentShootingSpeed() { |
54 | currentShootingSpeed += SHOOTING_SPEED_INCREMENT; | |
55 | } | |
56 | ||
57 | public void runFlyWheel() { | |
58 | flyWheel1.set(currentShootingSpeed); | |
59 | } | |
60 | ||
04227dc0 | 61 | /** |
62 | * Stops fly wheel motor. | |
63 | */ | |
64 | public void stopFlyWheel() { | |
3a86b1a5 CZ |
65 | flyWheel1.set(0); |
66 | flyWheel2.set(0); | |
04227dc0 | 67 | } |
41dfad94 | 68 | |
04227dc0 | 69 | /** |
6af2bd85 | 70 | * Stops index wheel motor. |
04227dc0 | 71 | */ |
6af2bd85 ES |
72 | public void stopIndexWheel() { |
73 | indexWheel.set(0); | |
079a8cb6 | 74 | } |
41dfad94 | 75 | |
079a8cb6 | 76 | /** |
6af2bd85 | 77 | * Run the index wheel forwards |
079a8cb6 | 78 | */ |
6af2bd85 ES |
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); | |
079a8cb6 | 88 | } |
41dfad94 | 89 | |
04227dc0 | 90 | @Override |
91 | protected void initDefaultCommand() { | |
079a8cb6 CZ |
92 | |
93 | } | |
381dad77 | 94 | |
268b0048 | 95 | public double getShooterRPM() { |
96 | return hallEffect.getRPM(); | |
381dad77 | 97 | } |
6af2bd85 ES |
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 | ||
79ba119a | 136 | } |