809609c9 |
1 | package org.usfirst.frc.team3501.robot.commands.shooter; |
2 | |
414d5638 |
3 | import org.usfirst.frc.team3501.robot.Robot; |
6d1b404a |
4 | import org.usfirst.frc.team3501.robot.subsystems.HallEffectSensor; |
414d5638 |
5 | |
6d1b404a |
6 | import edu.wpi.first.wpilibj.Counter; |
414d5638 |
7 | import edu.wpi.first.wpilibj.Timer; |
809609c9 |
8 | import edu.wpi.first.wpilibj.command.Command; |
9 | |
10 | /** |
973f0ac4 |
11 | * This command runs the fly wheel at a given speed for a given time. The fly |
12 | * wheel is intended to shoot balls fed by the intake wheel. |
809609c9 |
13 | * |
973f0ac4 |
14 | * @author Shaina |
809609c9 |
15 | */ |
16 | public class RunFlyWheel extends Command { |
414d5638 |
17 | Timer timer; |
6d1b404a |
18 | HallEffectSensor hallSource; |
19 | Counter hall; |
493a4f87 |
20 | private double motorVal; |
21 | private double time; |
6d1b404a |
22 | private int bufferLength = 15; |
23 | private int hallChannel = 0; // hallChannel=DIO channeL |
493a4f87 |
24 | |
b7ef589a |
25 | /** |
26 | * See JavaDoc comment in class for details |
27 | * |
28 | * @param motorVal |
29 | * value range from -1 to 1 |
30 | * @param time |
31 | * in seconds, amount of time to run fly wheel motor |
32 | */ |
493a4f87 |
33 | public RunFlyWheel(double motorVal, double time) { |
414d5638 |
34 | requires(Robot.getShooter()); |
35 | |
36 | timer = new Timer(); |
493a4f87 |
37 | this.motorVal = motorVal; |
38 | this.time = time; |
6d1b404a |
39 | |
40 | hall = new Counter(hallChannel); |
41 | hall.setMaxPeriod(1); |
42 | |
43 | hallSource = new HallEffectSensor(hall, bufferLength); |
493a4f87 |
44 | } |
45 | |
46 | // Called just before this Command runs the first time |
47 | @Override |
48 | protected void initialize() { |
414d5638 |
49 | timer.start(); |
50 | Robot.getShooter().setFlyWheelMotorVal(motorVal); |
493a4f87 |
51 | } |
52 | |
53 | // Called repeatedly when this Command is scheduled to run |
54 | @Override |
55 | protected void execute() { |
6d1b404a |
56 | double rotVel = hallSource.getRPS(); |
57 | |
493a4f87 |
58 | } |
59 | |
60 | // Called once after isFinished returns true |
61 | @Override |
62 | protected void end() { |
414d5638 |
63 | Robot.getShooter().stopFlyWheel(); |
493a4f87 |
64 | } |
65 | |
66 | // Called when another command which requires one or more of the same |
67 | // subsystems is scheduled to run |
68 | @Override |
69 | protected void interrupted() { |
414d5638 |
70 | end(); |
493a4f87 |
71 | } |
72 | |
73 | @Override |
74 | protected boolean isFinished() { |
414d5638 |
75 | return timer.get() >= time; |
493a4f87 |
76 | } |
809609c9 |
77 | |
78 | } |