e54ca7269297423eaa89db06463b8c4118298b21
[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.DoubleSolenoid.Value;
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 hood, punch;
26 private Encoder encoder;
27 private Lidar lidar;
28
29 public Shooter() {
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);
35
36 encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
37 Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
38 }
39
40 /***
41 * This method checks to see if the ball has successfully passed through the
42 * intake rollers and is inside.
43 *
44 * @return whether the presence of the ball is true or false and returns the
45 * state of the condition (true or false).
46 */
47
48 public boolean isBallInside() {
49 return true;
50 }
51
52 public void setSpeed(double speed) {
53 if (speed > 1.0)
54 shooter.set(1.0);
55 else if (speed < -1.0)
56 shooter.set(-1.0);
57 else
58 shooter.set(speed);
59 }
60
61 public void stop() {
62 this.setSpeed(0.0);
63 }
64
65 public double getSpeed() {
66 return encoder.getRate();
67 }
68
69 /*
70 * We are going to map a lidar distance to a shooter speed that will be set to
71 * the shooter. This function does not yet exist so we will just use y=x but
72 * when testing commences we shall create the function
73 */
74 public double getShooterSpeed() {
75 double distanceToGoal = lidar.getDistance();
76 double shooterSpeed = distanceToGoal; // Function to be determined
77 return shooterSpeed;
78 }
79
80 // Use negative # for decrement. Positive for increment.
81
82 public void changeSpeed(double change) {
83 double newSpeed = getSpeed() + change;
84 setSpeed(newSpeed);
85 }
86
87 // Punch Commands
88 public void extendPunch() {
89 punch.set(Constants.Shooter.punch);
90 }
91
92 public void retractPunch() {
93 punch.set(Constants.Shooter.retract);
94 }
95
96 public void raiseHood() {
97 hood.set(Constants.Shooter.open);
98 }
99
100 public void lowerHood() {
101 hood.set(Constants.Shooter.closed);
102 }
103
104 public boolean isHoodDown() {
105 if (hood.get() == Value.kReverse)
106 return true;
107 return false;
108 }
109
110 @Override
111 protected void initDefaultCommand() {
112 }
113 }