5727cc286cb6f1513b9c3c867af4f0468c1cb9b9
[3501/stronghold-2016] / 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.Constants.Shooter.State;
5 import org.usfirst.frc.team3501.robot.Robot;
6
7 import edu.wpi.first.wpilibj.CANTalon;
8 import edu.wpi.first.wpilibj.command.Subsystem;
9
10 public class Shooter extends Subsystem {
11 private CANTalon shooter;
12 private State state;
13
14 public Shooter() {
15 shooter = new CANTalon(Constants.Shooter.PORT);
16 state = State.STOPPED;
17 }
18
19 public double getCurrentSpeed() {
20 return shooter.get();
21 }
22
23 public void setSpeed(double speed) {
24 state = State.RUNNING;
25 shooter.set(speed);
26 }
27
28 public void shooterButtonsPressed() {
29
30 if (Robot.oi.incrementSpeed.get()) {
31 changeSpeed(0.1);
32 }
33
34 if (Robot.oi.decrementSpeed.get()) {
35 changeSpeed(-0.1);
36 }
37
38 if (Robot.oi.trigger.get()) {
39 if (this.getState() == State.STOPPED)
40 this.setSpeed(0.5);
41 } else {
42 if (this.getState() == State.RUNNING) {
43 this.stop();
44 }
45 }
46
47 if (Robot.oi.outputCurrentShooterSpeed.get()) {
48 System.out.println("Current Shooter Speed: " + getCurrentSpeed());
49 }
50 }
51
52 private void stop() {
53 this.setSpeed(0.0);
54 }
55
56 private State getState() {
57 return state;
58 }
59
60 // Use negative # for decrement. Positive for increment.
61 public void changeSpeed(double change) {
62 if (getCurrentSpeed() + change >= 1.0)
63 shooter.set(1.0);
64 else if (getCurrentSpeed() + change <= -1.0)
65 shooter.set(-1.0);
66 else {
67 double newSpeed = getCurrentSpeed() + change;
68 setSpeed(newSpeed);
69 }
70 this.state = State.RUNNING;
71 }
72
73 @Override
74 protected void initDefaultCommand() {
75 }
76 }