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

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 11 1
A end() 0 3 1
A interrupted() 0 1 1
A execute() 0 6 1
A isFinished() 0 5 2
A CyborgCommandDriveDistance(double) 0 3 1
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
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number 10 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...
31
    	PID.setPIDF(Util.getAndSetDouble("P", .5),
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number .5 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...
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
}