3b91bfe03c451333cdcdd8ef2035071b71a6af3a
1 package org
.usfirst
.frc
.team3501
.robot
.subsystems
;
3 import org
.usfirst
.frc
.team3501
.robot
.Constants
;
4 import org
.usfirst
.frc
.team3501
.robot
.Lidar
;
5 import org
.usfirst
.frc
.team3501
.robot
.MathLib
;
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
;
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.
23 public class Shooter
extends Subsystem
{
24 private CANTalon shooter
;
25 private DoubleSolenoid hood
, punch
;
26 private Encoder encoder
;
30 shooter
= new CANTalon(Constants
.Shooter
.PORT
);
31 hood
= new DoubleSolenoid(Constants
.Shooter
.HOOD_FORWARD
,
32 Constants
.Shooter
.HOOD_REVERSE
);
33 punch
= new DoubleSolenoid(Constants
.Shooter
.PUNCH_FORWARD
,
34 Constants
.Shooter
.PUNCH_REVERSE
);
36 encoder
= new Encoder(Constants
.Shooter
.ENCODER_PORT_A
,
37 Constants
.Shooter
.ENCODER_PORT_B
, false, EncodingType
.k4X
);
39 lidar
= new Lidar(Constants
.Shooter
.LIDAR_I2C_PORT
);
43 * This method checks to see if the ball has successfully passed through the
44 * intake rollers and is inside.
46 * @return whether the presence of the ball is true or false and returns the
47 * state of the condition (true or false).
50 public boolean isBallInside() {
54 public void setSpeed(double speed
) {
55 speed
= MathLib
.constrain(speed
, -1, 1);
59 // This getDistance() will return the distance using the lidar from the
60 // desired target during match. This distance is returned in units of
62 public double getDistance() {
63 return lidar
.getDistance();
70 public double getSpeed() {
71 return encoder
.getRate();
74 // Use negative # for decrement. Positive for increment.
76 public void changeSpeed(double change
) {
77 double newSpeed
= getSpeed() + change
;
83 punch
.set(Constants
.Shooter
.punch
);
86 public void retractPunch() {
87 punch
.set(Constants
.Shooter
.retract
);
90 public boolean isHoodOpen() {
91 return hood
.get() == Constants
.Shooter
.open
;
94 public void openHood() {
95 hood
.set(Constants
.Shooter
.open
);
98 public void closeHood() {
99 hood
.set(Constants
.Shooter
.closed
);
103 protected void initDefaultCommand() {