Add buttons pressed method and also also add state update
[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.rightJoystick
31 .getRawButton(Constants.OI.INCREMENT_SHOOTER_PORT)) {
32 changeSpeed(0.1);
33 }
34
35 if (Robot.oi.rightJoystick
36 .getRawButton(Constants.OI.DECREMENT_SHOOTER_PORT)) {
37 changeSpeed(-0.1);
38 }
39
40 if (Robot.oi.rightJoystick.getRawButton(Constants.OI.TRIGGER_PORT)) {
41 if (this.getState() == State.STOPPED)
42 this.setSpeed(0.5);
43 } else {
44 if (this.getState() == State.RUNNING) {
45 this.stop();
46 }
47 }
48
49 if (Robot.oi.rightJoystick.getRawButton(Constants.OI.PRINT_PORT)) {
50 System.out.println("Current Shooter Speed: " + getCurrentSpeed());
51 }
52 }
53
54 private void stop() {
55 this.setSpeed(0.0);
56 }
57
58 private State getState() {
59 return state;
60 }
61
62 // Use negative # for decrement. Positive for increment.
63 public void changeSpeed(double change) {
64 if (getCurrentSpeed() + change >= 1.0)
65 shooter.set(1.0);
66 else if (getCurrentSpeed() + change <= -1.0)
67 shooter.set(-1.0);
68 else {
69 double newSpeed = getCurrentSpeed() + change;
70 setSpeed(newSpeed);
71 }
72 this.state = State.RUNNING;
73 }
74
75 @Override
76 protected void initDefaultCommand() {
77 }
78 }