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