Put all sensors in sensor package and update the import paths
[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.sensors.Lidar;
5
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.Subsystem;
11
12 /***
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.
17 *
18 * @author superuser
19 *
20 */
21
22 public class Shooter extends Subsystem {
23 private CANTalon shooter;
24 private CANTalon angleAdjuster;
25 private DoubleSolenoid hood, punch;
26 private Encoder encoder;
27 private Lidar lidar;
28
29 public Shooter() {
30 shooter = new CANTalon(Constants.Shooter.PORT);
31 angleAdjuster = new CANTalon(Constants.Shooter.ANGLE_ADJUSTER_PORT);
32 punch = new DoubleSolenoid(Constants.Shooter.PUNCH_FORWARD,
33 Constants.Shooter.PUNCH_REVERSE);
34
35 encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
36 Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
37 }
38
39 /***
40 * This method checks to see if the ball has successfully passed through the
41 * intake rollers and is inside.
42 *
43 * @return whether the presence of the ball is true or false and returns the
44 * state of the condition (true or false).
45 */
46
47 public boolean isBallInside() {
48 return true;
49 }
50
51 public void setSpeed(double speed) {
52 if (speed > 1.0)
53 shooter.set(1.0);
54 else if (speed < -1.0)
55 shooter.set(-1.0);
56 else
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 /*
69 * We are going to map a lidar distance to a shooter speed that will be set to
70 * the shooter. This function does not yet exist so we will just use y=x but
71 * when testing commences we shall create the function
72 */
73 public double getShooterSpeed() {
74 double distanceToGoal = lidar.getDistance();
75 double shooterSpeed = distanceToGoal; // Function to be determined
76 return shooterSpeed;
77 }
78
79 // Use negative # for decrement. Positive for increment.
80
81 public void changeSpeed(double change) {
82 double newSpeed = getSpeed() + change;
83 setSpeed(newSpeed);
84 }
85
86 // Punch Commands
87 public void extendPunch() {
88 punch.set(Constants.Shooter.punch);
89 }
90
91 public void retractPunch() {
92 punch.set(Constants.Shooter.retract);
93 }
94
95 @Override
96 protected void initDefaultCommand() {
97 }
98 }