implement shooter pid
[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.command.Subsystem;
10
11 public class Shooter extends Subsystem {
12 public double wheelP = 0.0001, wheelI = 0, wheelD = 0.0004;
13 private static Shooter shooter;
14 private static HallEffectSensor hallEffect;
15 private final CANTalon flyWheel1, flyWheel2, indexWheel;
16
17 public static final double DEFAULT_INDEXING_SPEED = -0.75;
18 public static final double DEFAULT_SHOOTING_SPEED = 2700; // rpm
19 private static double CURRENT_SHOOTING_SPEED = DEFAULT_SHOOTING_SPEED;
20
21 public static final double SHOOTING_SPEED_INCREMENT = 25;
22
23 private Shooter() {
24 flyWheel1 = new CANTalon(Constants.Shooter.FLY_WHEEL1);
25 flyWheel2 = new CANTalon(Constants.Shooter.FLY_WHEEL2);
26 indexWheel = new CANTalon(Constants.Shooter.INDEX_WHEEL);
27
28 hallEffect = new HallEffectSensor(Constants.Shooter.HALL_EFFECT_PORT, 1);
29 }
30
31 public static HallEffectSensor getHallEffectSensor() {
32 return hallEffect;
33 }
34
35 /**
36 * Returns shooter object
37 *
38 * @return Shooter object
39 */
40 public static Shooter getShooter() {
41 if (shooter == null) {
42 shooter = new Shooter();
43 }
44 return shooter;
45 }
46
47 /**
48 * Sets fly wheel motor value to input.
49 *
50 * @param val
51 * motor value from -1 to 1(fastest forward)
52 */
53 public void setFlyWheelMotorVal(double val) {
54 val = MathLib.restrictToRange(val, 0.0, 1.0);
55 flyWheel1.set(val);
56 flyWheel2.set(val);
57 }
58
59 /**
60 * Stops fly wheel motor.
61 */
62 public void stopFlyWheel() {
63 flyWheel1.set(0);
64 flyWheel2.set(0);
65 }
66
67 /**
68 * Sets index wheel motor value to input.
69 *
70 * @param val
71 * motor value from -1 to 1(fastest forward)
72 */
73 public void setIndexWheelMotorVal(double val) {
74 val = MathLib.restrictToRange(val, -1.0, 1.0);
75 indexWheel.set(val);
76 }
77
78 /**
79 * Stops index wheel motor.
80 */
81 public void stopIndexWheel() {
82 indexWheel.set(0);
83 }
84
85 public double getCurrentShootingSpeed() {
86 return CURRENT_SHOOTING_SPEED;
87 }
88
89 public void setCurrentShootingSpeed(double Value) {
90 CURRENT_SHOOTING_SPEED = Value;
91 }
92
93 @Override
94 protected void initDefaultCommand() {
95
96 }
97
98 public double getShooterRPM() {
99 return hallEffect.getRPM();
100 }
101 }