Clean Up Code for FRC 3501-Spark Code: Restructure codebase
[3501/2015-FRC-Spark] / src / org / usfirst / frc3501 / RiceCatRobot / commands / DriveFor.java
CommitLineData
f11ce98e
KZ
1package org.usfirst.frc3501.RiceCatRobot.commands;
2
3import org.usfirst.frc3501.RiceCatRobot.Robot;
4import org.usfirst.frc3501.RiceCatRobot.RobotMap.Direction;
5
6import edu.wpi.first.wpilibj.Timer;
7import edu.wpi.first.wpilibj.command.Command;
8
9/**
10 * This command takes a time in seconds which is how long it should run
11 *
12 */
13public class DriveFor extends Command {
14 private double seconds;
15 private Timer timer;
16 private Direction direction;
17
18 public DriveFor(double seconds, Direction direction) {
19 this.seconds = seconds;
20 this.direction = direction;
21
22 }
23
24 @Override
25 protected void initialize() {
26 timer = new Timer();
27 timer.reset();
28 timer.start();
29 }
30
31 @Override
32 protected void execute() {
33 System.out.println(timer.get());
34 if (direction == Direction.FORWARD) {
35 if (timer.get() < seconds * 0.2) { // for the first 20% of time, run
36 // the robot at -.5 speed
37 Robot.driveTrain.arcadeDrive(-0.3, 0);
38 } else if (timer.get() >= seconds * 0.2
39 && timer.get() <= seconds * 0.8) { // for the +20% - 75%
40 // time, move the robot
41 // at -.3 speed.
42 Robot.driveTrain.arcadeDrive(-0.5, 0);
43 } else if (timer.get() < seconds) {
44 Robot.driveTrain.arcadeDrive(-0.25, 0);
45 } else {
46 Robot.driveTrain.arcadeDrive(0, 0);
47 }
48 } else if (direction == Direction.BACKWARD) {
49 if (timer.get() < seconds * 0.2) {
50 Robot.driveTrain.arcadeDrive(0.3, 0);
51 } else if (timer.get() >= seconds * 0.2
52 && timer.get() <= seconds * 0.8) {
53 Robot.driveTrain.arcadeDrive(0.5, 0);
54 } else if (timer.get() < seconds) {
55 Robot.driveTrain.arcadeDrive(0.25, 0);
56 } else {
57 Robot.driveTrain.arcadeDrive(0, 0);
58 }
59 }
60 }
61
62 @Override
63 protected boolean isFinished() {
64 return timer.get() > seconds;
65 }
66
67 @Override
68 protected void end() {
69 Robot.driveTrain.arcadeDrive(0, 0);
70 }
71
72 @Override
73 protected void interrupted() {
74 end();
75 }
76
77}