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