| 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 | |
| 30 | public Shooter() { |
| 31 | shooter = new CANTalon(Constants.Shooter.PORT); |
| 32 | hood1 = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD, |
| 33 | Constants.Shooter.HOOD_REVERSE); |
| 34 | hood2 = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD, |
| 35 | Constants.Shooter.HOOD_REVERSE); |
| 36 | punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD, |
| 37 | Constants.Shooter.PUNCH_REVERSE); |
| 38 | |
| 39 | encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A, |
| 40 | Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X); |
| 41 | } |
| 42 | |
| 43 | /*** |
| 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() { |
| 52 | return photogate.isBallPresent(); |
| 53 | } |
| 54 | |
| 55 | public void setSpeed(double speed) { |
| 56 | if (speed > 1.0) |
| 57 | shooter.set(1.0); |
| 58 | else if (speed < -1.0) |
| 59 | shooter.set(-1.0); |
| 60 | else |
| 61 | shooter.set(speed); |
| 62 | } |
| 63 | |
| 64 | public void stop() { |
| 65 | this.setSpeed(0.0); |
| 66 | } |
| 67 | |
| 68 | public double getSpeed() { |
| 69 | return encoder.getRate(); |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * We are going to map a lidar distance to a shooter speed that will be set to |
| 74 | * the shooter. This function does not yet exist so we will just use y=x but |
| 75 | * when testing commences we shall create the function |
| 76 | */ |
| 77 | public double getShooterSpeed() { |
| 78 | double distanceToGoal = lidar.getDistance(); |
| 79 | double shooterSpeed = distanceToGoal; // Function to be determined |
| 80 | return shooterSpeed; |
| 81 | } |
| 82 | |
| 83 | // Use negative # for decrement. Positive for increment. |
| 84 | |
| 85 | public void changeSpeed(double change) { |
| 86 | double newSpeed = getSpeed() + change; |
| 87 | setSpeed(newSpeed); |
| 88 | } |
| 89 | |
| 90 | // Punch Commands |
| 91 | public void extendPunch() { |
| 92 | punch.set(Constants.Shooter.punch); |
| 93 | } |
| 94 | |
| 95 | public void retractPunch() { |
| 96 | punch.set(Constants.Shooter.retract); |
| 97 | } |
| 98 | |
| 99 | public void raiseHood() { |
| 100 | hood1.set(Constants.Shooter.open); |
| 101 | hood2.set(Constants.Shooter.open); |
| 102 | } |
| 103 | |
| 104 | public void lowerHood() { |
| 105 | hood1.set(Constants.Shooter.closed); |
| 106 | hood2.set(Constants.Shooter.closed); |
| 107 | } |
| 108 | |
| 109 | public boolean isHoodDown() { |
| 110 | if (hood1.get() == Constants.Shooter.open |
| 111 | && hood2.get() == Constants.Shooter.open) |
| 112 | return true; |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | protected void initDefaultCommand() { |
| 118 | } |
| 119 | } |