3b91bfe03c451333cdcdd8ef2035071b71a6af3a
[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.Lidar;
5 import org.usfirst.frc.team3501.robot.MathLib;
6
7 import edu.wpi.first.wpilibj.CANTalon;
8 import edu.wpi.first.wpilibj.CounterBase.EncodingType;
9 import edu.wpi.first.wpilibj.DoubleSolenoid;
10 import edu.wpi.first.wpilibj.Encoder;
11 import edu.wpi.first.wpilibj.command.Subsystem;
12
13 /***
14 * The Shooter consists of a platform and wheel, each controlled by separate
15 * motors. The piston controlling the platform pushes the ball onto the wheel.
16 * The wheel is controlled by a motor, which is running before the ball is
17 * pushed 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 DoubleSolenoid hood, punch;
26 private Encoder encoder;
27 private Lidar lidar;
28
29 public Shooter() {
30 shooter = new CANTalon(Constants.Shooter.PORT);
31 hood = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD,
32 Constants.Shooter.HOOD_REVERSE);
33 punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD,
34 Constants.Shooter.PUNCH_REVERSE);
35
36 encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
37 Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
38
39 lidar = new Lidar(Constants.Shooter.LIDAR_I2C_PORT);
40 }
41
42 /***
43 * This method checks to see if the ball has successfully passed through the
44 * intake rollers and is inside.
45 *
46 * @return whether the presence of the ball is true or false and returns the
47 * state of the condition (true or false).
48 */
49
50 public boolean isBallInside() {
51 return true;
52 }
53
54 public void setSpeed(double speed) {
55 speed = MathLib.constrain(speed, -1, 1);
56 shooter.set(speed);
57 }
58
59 // This getDistance() will return the distance using the lidar from the
60 // desired target during match. This distance is returned in units of
61 // CENTIMETERS.
62 public double getDistance() {
63 return lidar.getDistance();
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 = getSpeed() + change;
78 setSpeed(newSpeed);
79 }
80
81 // Punch Commands
82 public void punch() {
83 punch.set(Constants.Shooter.punch);
84 }
85
86 public void retractPunch() {
87 punch.set(Constants.Shooter.retract);
88 }
89
90 public boolean isHoodOpen() {
91 return hood.get() == Constants.Shooter.open;
92 }
93
94 public void openHood() {
95 hood.set(Constants.Shooter.open);
96 }
97
98 public void closeHood() {
99 hood.set(Constants.Shooter.closed);
100 }
101
102 @Override
103 protected void initDefaultCommand() {
104 }
105 }