| 1 | package org.usfirst.frc.team3501.robot.subsystems; |
| 2 | |
| 3 | import org.usfirst.frc.team3501.robot.Constants; |
| 4 | |
| 5 | import edu.wpi.first.wpilibj.CANTalon; |
| 6 | import edu.wpi.first.wpilibj.CounterBase.EncodingType; |
| 7 | import edu.wpi.first.wpilibj.DoubleSolenoid; |
| 8 | import edu.wpi.first.wpilibj.Encoder; |
| 9 | import edu.wpi.first.wpilibj.command.Subsystem; |
| 10 | |
| 11 | public class Shooter extends Subsystem { |
| 12 | private CANTalon shooter; |
| 13 | private CANTalon angleAdjuster; |
| 14 | private DoubleSolenoid punch; |
| 15 | private Encoder encoder; |
| 16 | |
| 17 | public Shooter() { |
| 18 | shooter = new CANTalon(Constants.Shooter.PORT); |
| 19 | angleAdjuster = new CANTalon(Constants.Shooter.ANGLE_ADJUSTER_PORT); |
| 20 | punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD_PORT, |
| 21 | Constants.Shooter.PUNCH_REVERSE_PORT); |
| 22 | |
| 23 | encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A, |
| 24 | Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X); |
| 25 | } |
| 26 | |
| 27 | public double getCurrentSetPoint() { |
| 28 | return shooter.get(); |
| 29 | } |
| 30 | |
| 31 | public void setSpeed(double speed) { |
| 32 | if (speed > 1.0) |
| 33 | shooter.set(1.0); |
| 34 | else if (speed < -1.0) |
| 35 | shooter.set(-1.0); |
| 36 | else |
| 37 | shooter.set(speed); |
| 38 | } |
| 39 | |
| 40 | public void stop() { |
| 41 | this.setSpeed(0.0); |
| 42 | } |
| 43 | |
| 44 | public double getSpeed() { |
| 45 | return encoder.getRate(); |
| 46 | } |
| 47 | |
| 48 | // Use negative # for decrement. Positive for increment. |
| 49 | public void changeSpeed(double change) { |
| 50 | double newSpeed = getCurrentSetPoint() + change; |
| 51 | if (newSpeed > 1.0) |
| 52 | shooter.set(1.0); |
| 53 | else if (newSpeed < -1.0) |
| 54 | shooter.set(-1.0); |
| 55 | else { |
| 56 | setSpeed(newSpeed); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Punch Commands |
| 61 | public void punch() { |
| 62 | punch.set(Constants.Shooter.punch); |
| 63 | } |
| 64 | |
| 65 | public void resetPunch() { |
| 66 | punch.set(Constants.Shooter.retract); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | protected void initDefaultCommand() { |
| 71 | } |
| 72 | } |