590f4d59ee6ec6817c3071b770b00dc70b0d1209
1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
4 import org
.usfirst
.frc
.team3501
.robot
.Lidar
;
6 import edu
.wpi
.first
.wpilibj
.CANTalon
;
7 import edu
.wpi
.first
.wpilibj
.CounterBase
.EncodingType
;
8 import edu
.wpi
.first
.wpilibj
.DoubleSolenoid
;
9 import edu
.wpi
.first
.wpilibj
.Encoder
;
10 import edu
.wpi
.first
.wpilibj
.command
.PIDSubsystem
;
13 * The Shooter consists of a platform and wheel, each controlled by separate
14 * motors. The piston controlling the platform pushes the ball onto the wheel.
15 * The wheel is controlled by a motor, which is running before the ball is
16 * pushed onto the wheel. The spinning wheel propels the ball.
22 public class Shooter
extends PIDSubsystem
{
23 private static double sp
= 0.015, si
= 0, sd
= 0;
24 private static double encoderTolerance
= 5.0;
25 private static double pidOutput
= 5.0;
27 private CANTalon shooter
;
28 private DoubleSolenoid hood
, punch
;
29 private Encoder encoder
;
35 shooter
= new CANTalon(Constants
.Shooter
.PORT
);
36 hood
= new DoubleSolenoid(Constants
.Shooter
.HOOD_FORWARD
,
37 Constants
.Shooter
.HOOD_REVERSE
);
38 punch
= new DoubleSolenoid(Constants
.Shooter
.PUNCH_FORWARD
,
39 Constants
.Shooter
.PUNCH_REVERSE
);
41 encoder
= new Encoder(Constants
.Shooter
.ENCODER_PORT_A
,
42 Constants
.Shooter
.ENCODER_PORT_B
, false, EncodingType
.k4X
);
44 lidar
= new Lidar(Constants
.Shooter
.LIDAR_I2C_PORT
);
48 * This method checks to see if the ball has successfully passed through the
49 * intake rollers and is inside.
51 * @return whether the presence of the ball is true or false and returns the
52 * state of the condition (true or false).
55 public boolean isBallInside() {
59 public void setSpeed(double speed
) {
64 // This getDistance() will return the distance using the lidar from the
65 // desired target during match. This distance is returned in units of
67 public double getDistance() {
68 return lidar
.getDistance();
75 public double getSpeed() {
76 return encoder
.getRate();
79 // Use negative # for decrement. Positive for increment.
81 public void changeSpeed(double change
) {
82 double newSpeed
= getSpeed() + change
;
88 punch
.set(Constants
.Shooter
.punch
);
91 public void retractPunch() {
92 punch
.set(Constants
.Shooter
.retract
);
95 public boolean isHoodOpen() {
96 return hood
.get() == Constants
.Shooter
.open
;
99 public void openHood() {
100 hood
.set(Constants
.Shooter
.open
);
103 public void closeHood() {
104 hood
.set(Constants
.Shooter
.closed
);
108 protected void initDefaultCommand() {
112 protected double returnPIDInput() {
113 return sensorFeedback();
117 protected void usePIDOutput(double output
) {
122 private double sensorFeedback() {
123 return this.getSpeed();
126 public void setShooterPID() {
128 this.setAbsoluteTolerance(encoderTolerance
);
129 this.setOutputRange(-1.0, 1.0);
130 this.setInputRange(-500.0, 500.0);
134 public void updatePID() {
135 this.getPIDController().setPID(sp
, si
, sd
);