Completed
Push — master ( 0672dd...74c8db )
by John
33s
created

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

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
dl 0
loc 36
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A CyborgCommandDriveUntilError(Position) 0 3 1
A interrupted() 0 2 1
A initialize() 0 2 1
A isFinished() 0 6 2
A end() 0 2 1
A execute() 0 4 2
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;
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...
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));
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 20.0 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...
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();
0 ignored issues
show
Unused Code introduced by
Consider removing the unused local variable toReturn.
Loading history...
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
}