Add buttons pressed method and also also add state update
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / subsystems / Shooter.java
CommitLineData
416c4380
YN
1package org.usfirst.frc.team3501.robot.subsystems;\r
2\r
40348cab 3import org.usfirst.frc.team3501.robot.Constants;\r
e8986b9b
E
4import org.usfirst.frc.team3501.robot.Constants.Shooter.State;\r
5import org.usfirst.frc.team3501.robot.Robot;\r
40348cab
E
6\r
7import edu.wpi.first.wpilibj.CANTalon;\r
416c4380
YN
8import edu.wpi.first.wpilibj.command.Subsystem;\r
9\r
5585bd31 10public class Shooter extends Subsystem {\r
e8986b9b
E
11 private CANTalon shooter;\r
12 private State state;\r
5585bd31 13\r
40348cab 14 public Shooter() {\r
e9234163 15 shooter = new CANTalon(Constants.Shooter.PORT);\r
e8986b9b 16 state = State.STOPPED;\r
40348cab 17 }\r
416c4380 18\r
cb3389eb 19 public double getCurrentSpeed() {\r
9e247b05 20 return shooter.get();\r
cb3389eb
E
21 }\r
22\r
23 public void setSpeed(double speed) {\r
e8986b9b 24 state = State.RUNNING;\r
9e247b05 25 shooter.set(speed);\r
cb3389eb
E
26 }\r
27\r
e8986b9b
E
28 public void shooterButtonsPressed() {\r
29\r
30 if (Robot.oi.rightJoystick\r
31 .getRawButton(Constants.OI.INCREMENT_SHOOTER_PORT)) {\r
32 changeSpeed(0.1);\r
33 }\r
34\r
35 if (Robot.oi.rightJoystick\r
36 .getRawButton(Constants.OI.DECREMENT_SHOOTER_PORT)) {\r
37 changeSpeed(-0.1);\r
38 }\r
39\r
40 if (Robot.oi.rightJoystick.getRawButton(Constants.OI.TRIGGER_PORT)) {\r
41 if (this.getState() == State.STOPPED)\r
42 this.setSpeed(0.5);\r
43 } else {\r
44 if (this.getState() == State.RUNNING) {\r
45 this.stop();\r
46 }\r
47 }\r
48\r
49 if (Robot.oi.rightJoystick.getRawButton(Constants.OI.PRINT_PORT)) {\r
50 System.out.println("Current Shooter Speed: " + getCurrentSpeed());\r
51 }\r
52 }\r
53\r
54 private void stop() {\r
55 this.setSpeed(0.0);\r
56 }\r
57\r
58 private State getState() {\r
59 return state;\r
60 }\r
61\r
9e247b05
E
62 // Use negative # for decrement. Positive for increment.\r
63 public void changeSpeed(double change) {\r
b87f9700 64 if (getCurrentSpeed() + change >= 1.0)\r
9e247b05 65 shooter.set(1.0);\r
b87f9700 66 else if (getCurrentSpeed() + change <= -1.0)\r
9e247b05 67 shooter.set(-1.0);\r
8e5f83d9 68 else {\r
9e247b05 69 double newSpeed = getCurrentSpeed() + change;\r
e9234163 70 setSpeed(newSpeed);\r
cb3389eb 71 }\r
e8986b9b 72 this.state = State.RUNNING;\r
cb3389eb
E
73 }\r
74\r
40348cab
E
75 @Override\r
76 protected void initDefaultCommand() {\r
40348cab 77 }\r
416c4380 78}\r