| 1 | package org.usfirst.frc.team3501.robot.subsystems; |
| 2 | |
| 3 | import org.usfirst.frc.team3501.robot.Constants; |
| 4 | import org.usfirst.frc.team3501.robot.sensors.Lidar; |
| 5 | import org.usfirst.frc.team3501.robot.sensors.Photogate; |
| 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 hood1, hood2, punch; |
| 26 | private Encoder encoder; |
| 27 | private Lidar lidar; |
| 28 | private Photogate photogate; |
| 29 | private boolean usePhotoGate; |
| 30 | |
| 31 | public Shooter() { |
| 32 | shooter = new CANTalon(Constants.Shooter.PORT); |
| 33 | hood1 = new DoubleSolenoid(Constants.DriveTrain.MODULE_B_ID, |
| 34 | Constants.Shooter.RIGHT_HOOD_FORWARD, |
| 35 | Constants.Shooter.RIGHT_HOOD_REVERSE); // right |
| 36 | hood2 = new DoubleSolenoid(Constants.DriveTrain.MODULE_A_ID, |
| 37 | Constants.Shooter.LEFT_HOOD_FORWARD, |
| 38 | Constants.Shooter.LEFT_HOOD_REVERSE);// left |
| 39 | punch = new DoubleSolenoid(Constants.DriveTrain.MODULE_A_ID, |
| 40 | Constants.Shooter.PUNCH_FORWARD, Constants.Shooter.PUNCH_REVERSE); |
| 41 | |
| 42 | encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A, |
| 43 | Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X); |
| 44 | usePhotoGate = true; |
| 45 | } |
| 46 | |
| 47 | /*** |
| 48 | * This method checks to see if the ball has successfully passed through the |
| 49 | * intake rollers and is inside. |
| 50 | * |
| 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() { |
| 56 | |
| 57 | if (usePhotogate()) |
| 58 | return photogate.isBallPresent(); |
| 59 | else |
| 60 | return true; |
| 61 | |
| 62 | } |
| 63 | |
| 64 | public void setSpeed(double speed) { |
| 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); |
| 71 | } |
| 72 | |
| 73 | public void stop() { |
| 74 | this.setSpeed(0.0); |
| 75 | } |
| 76 | |
| 77 | public double getSpeed() { |
| 78 | return encoder.getRate(); |
| 79 | } |
| 80 | |
| 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 | */ |
| 86 | public double getShooterSpeed() { |
| 87 | double distanceToGoal = lidar.getDistance(); |
| 88 | double shooterSpeed = distanceToGoal; // Function to be determined |
| 89 | return shooterSpeed; |
| 90 | } |
| 91 | |
| 92 | // Use negative # for decrement. Positive for increment. |
| 93 | |
| 94 | public void changeSpeed(double change) { |
| 95 | double newSpeed = getSpeed() + change; |
| 96 | setSpeed(newSpeed); |
| 97 | } |
| 98 | |
| 99 | // Punch Commands |
| 100 | public void extendPunch() { |
| 101 | punch.set(Constants.Shooter.punch); |
| 102 | } |
| 103 | |
| 104 | public void retractPunch() { |
| 105 | punch.set(Constants.Shooter.retract); |
| 106 | } |
| 107 | |
| 108 | public void raiseHood() { |
| 109 | hood1.set(Constants.Shooter.open); |
| 110 | hood2.set(Constants.Shooter.open); |
| 111 | } |
| 112 | |
| 113 | public void lowerHood() { |
| 114 | hood1.set(Constants.Shooter.closed); |
| 115 | hood2.set(Constants.Shooter.closed); |
| 116 | } |
| 117 | |
| 118 | public boolean isHoodDown() { |
| 119 | if (hood1.get() == Constants.Shooter.open |
| 120 | && hood2.get() == Constants.Shooter.open) |
| 121 | return true; |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | public boolean usePhotogate() { |
| 126 | return this.usePhotoGate; |
| 127 | } |
| 128 | |
| 129 | public void togglePhotoGate() { |
| 130 | this.usePhotoGate = !this.usePhotoGate; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | protected void initDefaultCommand() { |
| 135 | } |
| 136 | } |