1
|
|
|
package org.usfirst.frc.team3695.robot.commands; |
2
|
|
|
|
3
|
|
|
import org.usfirst.frc.team3695.robot.Robot; |
4
|
|
|
import org.usfirst.frc.team3695.robot.enumeration.Position; |
5
|
|
|
import org.usfirst.frc.team3695.robot.subsystems.SubsystemDrive; |
6
|
|
|
|
7
|
|
|
import org.usfirst.frc.team3695.robot.util.Util; |
8
|
|
|
|
9
|
|
|
import edu.wpi.first.wpilibj.command.Command; |
10
|
|
|
|
11
|
|
|
public class CyborgCommandDriveUntilError extends Command { |
12
|
|
|
public static final long ERROR_TIME = 500; |
13
|
|
|
public static final int TARGET_ERROR = 500; |
14
|
|
|
|
15
|
|
|
private final Position position; |
16
|
|
|
private long time = 0; |
|
|
|
|
17
|
|
|
|
18
|
|
|
public CyborgCommandDriveUntilError(Position position) { |
19
|
|
|
requires(Robot.SUB_DRIVE); |
20
|
|
|
this.position = position; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected void initialize() { |
24
|
|
|
time = System.currentTimeMillis() + ERROR_TIME; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected void execute() { |
28
|
|
|
double speed = SubsystemDrive.ips2rpm(Util.getAndSetDouble("SPEED ERROR: Forward", 20.0)); |
|
|
|
|
29
|
|
|
if(position == Position.BACKWARD) speed *= -1; |
30
|
|
|
Robot.SUB_DRIVE.driveDirect(speed, speed); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected boolean isFinished() { |
34
|
|
|
if(Math.abs(Robot.SUB_DRIVE.getError()) < TARGET_ERROR) { |
35
|
|
|
time = System.currentTimeMillis() + ERROR_TIME; |
36
|
|
|
} |
37
|
|
|
boolean toReturn = time < System.currentTimeMillis(); |
|
|
|
|
38
|
|
|
return time < System.currentTimeMillis(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected void end() { |
42
|
|
|
Robot.SUB_DRIVE.driveDirect(0, 0); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected void interrupted() { |
46
|
|
|
end(); |
47
|
|
|
} |
48
|
|
|
} |