1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
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
;
7 import com
.ctre
.CANTalon
;
9 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
;
10 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
.Value
;
11 import edu
.wpi
.first
.wpilibj
.command
.Subsystem
;
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
;
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;
23 private double currentShootingSpeed
= DEFAULT_SHOOTING_SPEED
;
25 private DoubleSolenoid piston
;
28 flyWheel1
= new CANTalon(Constants
.Shooter
.FLY_WHEEL1
);
29 flyWheel2
= new CANTalon(Constants
.Shooter
.FLY_WHEEL2
);
30 indexWheel
= new CANTalon(Constants
.Shooter
.INDEX_WHEEL
);
32 hallEffect
= new HallEffectSensor(Constants
.Shooter
.HALL_EFFECT_PORT
, 1);
34 piston
= new DoubleSolenoid(Constants
.Shooter
.PISTON_MODULE
,
35 Constants
.Shooter
.PISTON_FORWARD
, Constants
.Shooter
.PISTON_REVERSE
);
39 * Returns shooter object
41 * @return Shooter object
43 public static Shooter
getShooter() {
44 if (shooter
== null) {
45 shooter
= new Shooter();
51 * Sets fly wheel motor value to input.
54 * motor value from -1 to 1(fastest forward)
56 public void setFlyWheelMotorVal(double val
) {
57 val
= MathLib
.restrictToRange(val
, 0.0, 1.0);
63 * Stops fly wheel motor.
65 public void stopFlyWheel() {
71 * Sets index wheel motor value to input.
74 * motor value from -1 to 1(fastest forward)
76 public void setIndexWheelMotorVal(double val
) {
77 val
= MathLib
.restrictToRange(val
, -1.0, 1.0);
82 * Stops index wheel motor.
84 public void stopIndexWheel() {
89 protected void initDefaultCommand() {
93 public double getShooterRPM() {
94 return hallEffect
.getRPM();
97 public void setCurrentShootingSpeed(double Value
) {
98 currentShootingSpeed
= Value
;
101 public void decrementCurrentShootingSpeed() {
102 this.currentShootingSpeed
-= this.SHOOTING_SPEED_INCREMENT
;
105 public void incrementCurrentShootingSpeed() {
106 this.currentShootingSpeed
+= this.SHOOTING_SPEED_INCREMENT
;
109 public void resetCurrentShootingSpeed() {
110 this.currentShootingSpeed
= this.DEFAULT_SHOOTING_SPEED
;
113 public double getCurrentShootingSpeed() {
114 return currentShootingSpeed
;
117 public void reverseIndexWheel() {
118 this.setIndexWheelMotorVal(-DEFAULT_INDEXING_SPEED
);
121 public void runIndexWheel() {
122 this.setIndexWheelMotorVal(DEFAULT_INDEXING_SPEED
);
125 public Value
getPistonValue() {
129 public void setHighGear() {
130 changeGear(Constants
.Shooter
.HIGH_GEAR
);
133 public void setLowGear() {
134 changeGear(Constants
.Shooter
.LOW_GEAR
);
137 private void changeGear(DoubleSolenoid
.Value gear
) {