isFinished()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
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 edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
6
import org.usfirst.frc.team3695.robot.Constants;
7
import org.usfirst.frc.team3695.robot.Robot;
8
import org.usfirst.frc.team3695.robot.util.Util;
9
10
public class CyborgCommandRotateDegrees extends Command {
11
    public static final double SCALAR = (Constants.DISTANCE_BETWEEN_WHEELS * Math.PI) / 360;
12
    public static final long TIME_WAIT = 500;
13
14
    private boolean inRange;
15
    private long time;
16
    public double inches;
17
18
    public CyborgCommandRotateDegrees(double degrees) {
19
        inches = degrees * SCALAR;
20
        requires(Robot.SUB_DRIVE);
21
    }
22
23
    protected void initialize() {
24
    	DriverStation.reportWarning("ROTATING " + (inches / SCALAR) + " DEGREES" + ((inches > 0) ? "CW" : "CCW"), false);
25
        time = System.currentTimeMillis() + TIME_WAIT;
26
        inRange = false;
27
        Robot.SUB_DRIVE.pid.reset();
28
        time = System.currentTimeMillis() + TIME_WAIT;
29
        inches = Util.getAndSetDouble("Rotate Degrees", 0) * SCALAR;
30
        Robot.SUB_DRIVE.pid.setPIDF(Util.getAndSetDouble("P", .11),
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number .11 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
                Util.getAndSetDouble("I", 0),
32
                Util.getAndSetDouble("D", 0),
33
                Util.getAndSetDouble("F", 0));
34
        inRange = Robot.SUB_DRIVE.driveDistance(inches, -1* inches);
35
    }
36
37
    protected void execute() {
38
        DriverStation.reportWarning("ROTATING " + (inches / SCALAR) + " DEGREES" + ((inches > 0) ? "CW" : "CCW"), false);
39
        SmartDashboard.putNumber("Left Encoder Inches", Robot.SUB_DRIVE.pid.getLeftInches());
40
        SmartDashboard.putNumber("Right Encoder Inches", Robot.SUB_DRIVE.pid.getRightInches());
41
        SmartDashboard.putNumber("Error", Robot.SUB_DRIVE.pid.getError());
42
    }
43
44
    protected boolean isFinished() {
45
    	DriverStation.reportWarning("DONE ROTATING", false);
46
        if(!inRange) {
47
            time = System.currentTimeMillis() + TIME_WAIT;
48
        }
49
        return time < System.currentTimeMillis();
50
    }
51
52
    protected void end() {
53
        DriverStation.reportWarning("CyborgCommandRotateDegrees finished", false);
54
        Robot.SUB_DRIVE.driveDirect(0, 0);
55
    }
56
57
    protected void interrupted() {
58
        end();
59
    }
60
}