|
1
|
|
|
|
|
2
|
|
|
package org.usfirst.frc.team3695.robot.commands;
|
|
3
|
|
|
|
|
4
|
|
|
import edu.wpi.first.wpilibj.DriverStation;
|
|
5
|
|
|
import edu.wpi.first.wpilibj.command.Command;
|
|
6
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
|
7
|
|
|
|
|
8
|
|
|
import org.usfirst.frc.team3695.robot.Robot;
|
|
9
|
|
|
import org.usfirst.frc.team3695.robot.subsystems.SubsystemDrive.PID;
|
|
10
|
|
|
import org.usfirst.frc.team3695.robot.util.Util;
|
|
11
|
|
|
|
|
12
|
|
|
public class CyborgCommandDriveDistance extends Command {
|
|
13
|
|
|
|
|
14
|
|
|
public static final long TIME_WAIT = 1000;
|
|
15
|
|
|
public double inches;
|
|
16
|
|
|
private long time;
|
|
17
|
|
|
private boolean inRange;
|
|
18
|
|
|
|
|
19
|
|
|
public CyborgCommandDriveDistance(double inches) {
|
|
20
|
|
|
this.inches = inches;
|
|
21
|
|
|
requires(Robot.SUB_DRIVE);
|
|
22
|
|
|
|
|
23
|
|
|
}
|
|
24
|
|
|
|
|
25
|
|
|
protected void initialize() {
|
|
26
|
|
|
// Robot.SUB_DRIVE.pid.zeroEncoders(); Reset does this
|
|
27
|
|
|
inRange = false;
|
|
28
|
|
|
Robot.SUB_DRIVE.pid.reset();
|
|
29
|
|
|
time = System.currentTimeMillis() + TIME_WAIT;
|
|
30
|
|
|
inches = Util.getAndSetDouble("Drive Distance Inches", 10); // take out in final version
|
|
|
|
|
|
|
31
|
|
|
PID.setPIDF(Util.getAndSetDouble("P", .5),
|
|
|
|
|
|
|
32
|
|
|
Util.getAndSetDouble("I", 0),
|
|
33
|
|
|
Util.getAndSetDouble("D", 0),
|
|
34
|
|
|
Util.getAndSetDouble("F", 0));
|
|
35
|
|
|
inRange = Robot.SUB_DRIVE.driveDistance(inches, inches);
|
|
36
|
|
|
|
|
37
|
|
|
}
|
|
38
|
|
|
|
|
39
|
|
|
protected void execute() {
|
|
40
|
|
|
DriverStation.reportWarning("DRIVING " + inches + " INCHES", false);
|
|
41
|
|
|
SmartDashboard.putNumber("Left Encoder Inches", Robot.SUB_DRIVE.pid.getLeftInches());
|
|
42
|
|
|
SmartDashboard.putNumber("Right Encoder Inches", Robot.SUB_DRIVE.pid.getRightInches());
|
|
43
|
|
|
|
|
44
|
|
|
SmartDashboard.putNumber("Error", Robot.SUB_DRIVE.pid.getError());
|
|
45
|
|
|
}
|
|
46
|
|
|
|
|
47
|
|
|
protected boolean isFinished() {
|
|
48
|
|
|
if(!inRange) {
|
|
49
|
|
|
time = System.currentTimeMillis() + TIME_WAIT;
|
|
50
|
|
|
}
|
|
51
|
|
|
return time < System.currentTimeMillis();
|
|
52
|
|
|
}
|
|
53
|
|
|
|
|
54
|
|
|
protected void end() {
|
|
55
|
|
|
DriverStation.reportWarning("CyborgCommandDriveDistance finished", false);
|
|
56
|
|
|
Robot.SUB_DRIVE.driveDirect(0, 0);
|
|
57
|
|
|
}
|
|
58
|
|
|
|
|
59
|
|
|
protected void interrupted() {}
|
|
60
|
|
|
} |
Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.