org.usfirst.frc.team3695.robot.commands.CyborgCommandDriveUntilError   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 33
rs 10
c 3
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A CyborgCommandDriveUntilError() 0 2 1
A interrupted() 0 2 1
A initialize() 0 2 1
A isFinished() 0 5 2
A end() 0 3 1
A execute() 0 3 1
1
package org.usfirst.frc.team3695.robot.commands;
2
3
import edu.wpi.first.wpilibj.DriverStation;
4
import edu.wpi.first.wpilibj.command.Command;
5
import org.usfirst.frc.team3695.robot.Robot;
6
import org.usfirst.frc.team3695.robot.util.Util;
7
8
public class CyborgCommandDriveUntilError extends Command {
9
    public static final long ERROR_TIME = 500;
10
    public static final int TARGET_ERROR = 500;
11
12
    private long time = 0;
0 ignored issues
show
Best Practice introduced by
Exceptions generally should be immutable since they convey immutable data. Consider making the field time final.
Loading history...
13
14
    public CyborgCommandDriveUntilError() {
15
        requires(Robot.SUB_DRIVE);
16
    }
17
18
    protected void initialize() {
19
        time = System.currentTimeMillis() + ERROR_TIME;
20
    }
21
22
    protected void execute() {
23
        double speed = Util.getAndSetDouble("SPEED ERROR: Forward", -0.25);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 0.25 to a constant.

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.

Loading history...
24
        Robot.SUB_DRIVE.driveDirect(speed, speed);
25
    }
26
27
    protected boolean isFinished() {
28
        if(Math.abs(Robot.SUB_DRIVE.pid.getError()) < TARGET_ERROR) {
29
            time = System.currentTimeMillis() + ERROR_TIME;
30
        }
31
        return time < System.currentTimeMillis();
32
    }
33
34
    protected void end() {
35
        DriverStation.reportWarning("CyborgCommandDriveUntilError finished", false);
36
        Robot.SUB_DRIVE.driveDirect(0, 0);
37
    }
38
39
    protected void interrupted() {
40
        end();
41
    }
42
}