Instantiate lidar objcet in Shooter class
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / subsystems / Shooter.java
1 package org.usfirst.frc.team3501.robot.subsystems;
2
3 import org.usfirst.frc.team3501.robot.Constants;
4 import org.usfirst.frc.team3501.robot.Lidar;
5 import org.usfirst.frc.team3501.robot.MathLib;
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.I2C;
12 import edu.wpi.first.wpilibj.command.Subsystem;
13
14 /***
15 * The Shooter consists of a platform and wheel, each controlled by separate
16 * motors. The piston controlling the platform pushes the ball onto the wheel.
17 * The wheel is controlled by a motor, which is running before the ball is
18 * pushed onto the wheel. The spinning wheel propels the ball.
19 *
20 * @author superuser
21 *
22 */
23
24 public class Shooter extends Subsystem {
25 private CANTalon shooter;
26 private DoubleSolenoid hood, punch;
27 private Encoder encoder;
28 private Lidar lidar;
29
30 public Shooter() {
31 shooter = new CANTalon(Constants.Shooter.PORT);
32 hood = new DoubleSolenoid(Constants.Shooter.HOOD_FORWARD,
33 Constants.Shooter.HOOD_REVERSE);
34 punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD,
35 Constants.Shooter.PUNCH_REVERSE);
36
37 encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
38 Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
39
40 lidar = new Lidar(I2C.Port.kMXP);
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 true;
53 }
54
55 public void setSpeed(double speed) {
56 speed = MathLib.constrain(speed, -1, 1);
57 shooter.set(speed);
58 }
59
60 public void stop() {
61 this.setSpeed(0.0);
62 }
63
64 public double getSpeed() {
65 return encoder.getRate();
66 }
67
68 // Use negative # for decrement. Positive for increment.
69
70 public void changeSpeed(double change) {
71 double newSpeed = getSpeed() + change;
72 setSpeed(newSpeed);
73 }
74
75 // Punch Commands
76 public void punch() {
77 punch.set(Constants.Shooter.punch);
78 }
79
80 public void retractPunch() {
81 punch.set(Constants.Shooter.retract);
82 }
83
84 public boolean isHoodOpen() {
85 return hood.get() == Constants.Shooter.open;
86 }
87
88 public void openHood() {
89 hood.set(Constants.Shooter.open);
90 }
91
92 public void closeHood() {
93 hood.set(Constants.Shooter.closed);
94 }
95
96 @Override
97 protected void initDefaultCommand() {
98 }
99 }