Allow use of photogate as an option in shoot.java command group
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / subsystems / Shooter.java
CommitLineData
a0c3ca74
KZ
1package org.usfirst.frc.team3501.robot.subsystems;
2
3import org.usfirst.frc.team3501.robot.Constants;
7670b3f4 4import org.usfirst.frc.team3501.robot.sensors.Lidar;
49b6d711 5import org.usfirst.frc.team3501.robot.sensors.Photogate;
a0c3ca74
KZ
6
7import edu.wpi.first.wpilibj.CANTalon;
2c52cb6e 8import edu.wpi.first.wpilibj.CounterBase.EncodingType;
9b10474d 9import edu.wpi.first.wpilibj.DoubleSolenoid;
2c52cb6e 10import edu.wpi.first.wpilibj.Encoder;
a0c3ca74
KZ
11import edu.wpi.first.wpilibj.command.Subsystem;
12
27fac8ed 13/***
3b2038bb
ME
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.
27fac8ed
YA
18 *
19 * @author superuser
20 *
21 */
22
a0c3ca74 23public class Shooter extends Subsystem {
a0c3ca74 24 private CANTalon shooter;
5930d874 25 private DoubleSolenoid hood1, hood2, punch;
2c52cb6e 26 private Encoder encoder;
06fda04b 27 private Lidar lidar;
49b6d711 28 private Photogate photogate;
a0c3ca74
KZ
29
30 public Shooter() {
31 shooter = new CANTalon(Constants.Shooter.PORT);
5930d874
CZ
32 hood1 = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD,
33 Constants.Shooter.HOOD_REVERSE);
34 hood2 = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD,
a56412b7 35 Constants.Shooter.HOOD_REVERSE);
93453536
CZ
36 punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD,
37 Constants.Shooter.PUNCH_REVERSE);
2c52cb6e
K
38
39 encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
40 Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
a0c3ca74
KZ
41 }
42
64055177 43 /***
f08a2eef
YA
44 * This method checks to see if the ball has successfully passed through the
45 * intake rollers and is inside.
46 *
47 * @return whether the presence of the ball is true or false and returns the
48 * state of the condition (true or false).
49 */
50
51 public boolean isBallInside() {
24850996 52 if (usePhotogate())
53 return photogate.isBallPresent();
54 else
55 return false;
f08a2eef
YA
56 }
57
a0c3ca74 58 public void setSpeed(double speed) {
0b403e60
ME
59 if (speed > 1.0)
60 shooter.set(1.0);
61 else if (speed < -1.0)
62 shooter.set(-1.0);
63 else
64 shooter.set(speed);
4b29730e
E
65 }
66
a0c3ca74
KZ
67 public void stop() {
68 this.setSpeed(0.0);
69 }
70
2c52cb6e
K
71 public double getSpeed() {
72 return encoder.getRate();
73 }
74
29697d89
KZ
75 /*
76 * We are going to map a lidar distance to a shooter speed that will be set to
77 * the shooter. This function does not yet exist so we will just use y=x but
78 * when testing commences we shall create the function
79 */
984e903a
SC
80 public double getShooterSpeed() {
81 double distanceToGoal = lidar.getDistance();
82 double shooterSpeed = distanceToGoal; // Function to be determined
83 return shooterSpeed;
84 }
85
a0c3ca74 86 // Use negative # for decrement. Positive for increment.
27fac8ed 87
a0c3ca74 88 public void changeSpeed(double change) {
92d4c21a 89 double newSpeed = getSpeed() + change;
64055177 90 setSpeed(newSpeed);
a0c3ca74
KZ
91 }
92
9b10474d 93 // Punch Commands
0b403e60 94 public void extendPunch() {
9b10474d
GK
95 punch.set(Constants.Shooter.punch);
96 }
97
c8c4e6d9 98 public void retractPunch() {
9b10474d
GK
99 punch.set(Constants.Shooter.retract);
100 }
101
a56412b7 102 public void raiseHood() {
5930d874
CZ
103 hood1.set(Constants.Shooter.open);
104 hood2.set(Constants.Shooter.open);
a56412b7
CZ
105 }
106
107 public void lowerHood() {
5930d874
CZ
108 hood1.set(Constants.Shooter.closed);
109 hood2.set(Constants.Shooter.closed);
a56412b7
CZ
110 }
111
cc72c5b2 112 public boolean isHoodDown() {
ee31518f
CZ
113 if (hood1.get() == Constants.Shooter.open
114 && hood2.get() == Constants.Shooter.open)
cc72c5b2
CZ
115 return true;
116 return false;
117 }
118
24850996 119 public boolean usePhotogate() {
120 return true;
121 }
122
3b2038bb
ME
123 @Override
124 protected void initDefaultCommand() {
071ab315 125 }
a0c3ca74 126}