remove content of changeSpeed and call setSpeed(newSpeed)
[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
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 /***
12 * The Shooter consists of a platform and wheel, each controlled by
13 * separate motors. The motor controlling the platform pushes the ball onto the
14 * wheel. The wheel is controlled by a motor, which runs once the ball is pushed
15 * onto the wheel. The spinning wheel propels the ball.
16 *
17 * @author superuser
18 *
19 */
20
21 public class Shooter extends Subsystem {
22 private CANTalon shooter;
23 private CANTalon angleAdjuster;
24 private DoubleSolenoid punch;
25 private Encoder encoder;
26
27 public Shooter() {
28 shooter = new CANTalon(Constants.Shooter.PORT);
29 angleAdjuster = new CANTalon(Constants.Shooter.ANGLE_ADJUSTER_PORT);
30 punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD_PORT,
31 Constants.Shooter.PUNCH_REVERSE_PORT);
32
33 encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
34 Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
35 }
36
37 /***
38 *
39 * @return current sensor position??
40 */
41 public double getCurrentSetPoint() {
42 return shooter.get();
43 }
44
45 /***
46 * This method checks to see if the ball has successfully passed through the
47 * intake rollers and is inside.
48 *
49 * @return whether the presence of the ball is true or false and returns the
50 * state of the condition (true or false).
51 */
52
53 public boolean isBallInside() {
54 return true;
55 }
56
57 public void setSpeed(double speed) {
58 if (speed > 1.0)
59 shooter.set(1.0);
60 else if (speed < -1.0)
61 shooter.set(-1.0);
62 else
63 shooter.set(speed);
64 }
65
66 public void stop() {
67 this.setSpeed(0.0);
68 }
69
70 public double getSpeed() {
71 return encoder.getRate();
72 }
73
74 // Use negative # for decrement. Positive for increment.
75
76 public void changeSpeed(double change) {
77 double newSpeed = getCurrentSetPoint() + change;
78 setSpeed(newSpeed);
79 }
80
81 // Punch Commands
82 public void punch() {
83 punch.set(Constants.Shooter.punch);
84 }
85
86 public void resetPunch() {
87 punch.set(Constants.Shooter.retract);
88 }
89
90 @Override
91 protected void initDefaultCommand() {
92 }
93 }