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; |
49b6d711 | 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. | |
27fac8ed YA |
18 | * |
19 | * @author superuser | |
20 | * | |
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; |
49b6d711 | 28 | private Photogate photogate; |
95f05eb0 | 29 | private boolean usePhotoGate; |
a0c3ca74 KZ |
30 | |
31 | public Shooter() { | |
32 | shooter = new CANTalon(Constants.Shooter.PORT); | |
5930d874 CZ |
33 | hood1 = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD, |
34 | Constants.Shooter.HOOD_REVERSE); | |
35 | hood2 = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD, | |
a56412b7 | 36 | Constants.Shooter.HOOD_REVERSE); |
93453536 CZ |
37 | punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD, |
38 | Constants.Shooter.PUNCH_REVERSE); | |
2c52cb6e K |
39 | |
40 | encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A, | |
41 | Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X); | |
95f05eb0 | 42 | usePhotoGate = true; |
a0c3ca74 KZ |
43 | } |
44 | ||
64055177 | 45 | /*** |
f08a2eef YA |
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() { | |
24850996 | 54 | if (usePhotogate()) |
55 | return photogate.isBallPresent(); | |
56 | else | |
95f05eb0 | 57 | return true; |
f08a2eef YA |
58 | } |
59 | ||
a0c3ca74 | 60 | public void setSpeed(double speed) { |
0b403e60 ME |
61 | if (speed > 1.0) |
62 | shooter.set(1.0); | |
63 | else if (speed < -1.0) | |
64 | shooter.set(-1.0); | |
65 | else | |
66 | shooter.set(speed); | |
4b29730e E |
67 | } |
68 | ||
a0c3ca74 KZ |
69 | public void stop() { |
70 | this.setSpeed(0.0); | |
71 | } | |
72 | ||
2c52cb6e K |
73 | public double getSpeed() { |
74 | return encoder.getRate(); | |
75 | } | |
76 | ||
29697d89 KZ |
77 | /* |
78 | * We are going to map a lidar distance to a shooter speed that will be set to | |
79 | * the shooter. This function does not yet exist so we will just use y=x but | |
80 | * when testing commences we shall create the function | |
81 | */ | |
984e903a SC |
82 | public double getShooterSpeed() { |
83 | double distanceToGoal = lidar.getDistance(); | |
84 | double shooterSpeed = distanceToGoal; // Function to be determined | |
85 | return shooterSpeed; | |
86 | } | |
87 | ||
a0c3ca74 | 88 | // Use negative # for decrement. Positive for increment. |
27fac8ed | 89 | |
a0c3ca74 | 90 | public void changeSpeed(double change) { |
92d4c21a | 91 | double newSpeed = getSpeed() + change; |
64055177 | 92 | setSpeed(newSpeed); |
a0c3ca74 KZ |
93 | } |
94 | ||
9b10474d | 95 | // Punch Commands |
0b403e60 | 96 | public void extendPunch() { |
9b10474d GK |
97 | punch.set(Constants.Shooter.punch); |
98 | } | |
99 | ||
c8c4e6d9 | 100 | public void retractPunch() { |
9b10474d GK |
101 | punch.set(Constants.Shooter.retract); |
102 | } | |
103 | ||
a56412b7 | 104 | public void raiseHood() { |
5930d874 CZ |
105 | hood1.set(Constants.Shooter.open); |
106 | hood2.set(Constants.Shooter.open); | |
a56412b7 CZ |
107 | } |
108 | ||
109 | public void lowerHood() { | |
5930d874 CZ |
110 | hood1.set(Constants.Shooter.closed); |
111 | hood2.set(Constants.Shooter.closed); | |
a56412b7 CZ |
112 | } |
113 | ||
cc72c5b2 | 114 | public boolean isHoodDown() { |
ee31518f CZ |
115 | if (hood1.get() == Constants.Shooter.open |
116 | && hood2.get() == Constants.Shooter.open) | |
cc72c5b2 CZ |
117 | return true; |
118 | return false; | |
119 | } | |
120 | ||
24850996 | 121 | public boolean usePhotogate() { |
95f05eb0 KZ |
122 | return this.usePhotoGate; |
123 | } | |
124 | ||
125 | public void togglePhotoGate() { | |
126 | this.usePhotoGate = !this.usePhotoGate; | |
24850996 | 127 | } |
128 | ||
3b2038bb ME |
129 | @Override |
130 | protected void initDefaultCommand() { | |
071ab315 | 131 | } |
a0c3ca74 | 132 | } |