-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDriveManual.java
65 lines (52 loc) · 1.49 KB
/
DriveManual.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.team3925.frc2018.commands;
import com.team3925.frc2018.subsystems.Drivetrain;
import edu.wpi.first.wpilibj.command.Command;
public class DriveManual extends Command {
public interface DriveManualInput {
public abstract double getFwd();
public abstract double getLeft();
}
private final boolean doReverseWhenReversing;
private DriveManualInput input;
private double prelimLeft, prelimRight;
private double fwd, turn;
private double scale;
public DriveManual(DriveManualInput input) {
this.input = input;
doReverseWhenReversing = false;
requires(Drivetrain.getInstance());
}
@Override
protected void initialize() {
Drivetrain.getInstance().setRaw(0, 0);
}
@Override
protected void execute() {
fwd = input.getFwd();
turn = input.getLeft();
if (Math.abs(fwd) < 0.1)
fwd = 0;
if (doReverseWhenReversing && fwd != 0)
turn *= Math.signum(fwd);
prelimLeft = fwd + turn;
prelimRight = fwd - turn;
if (prelimLeft != 0 || prelimRight != 0) {
scale = Math.max(Math.abs(fwd), Math.abs(turn)) / Math.max(Math.abs(prelimLeft), Math.abs(prelimRight));
prelimLeft *= scale;
prelimRight *= scale;
}
Drivetrain.getInstance().setRaw(prelimLeft, prelimRight);
}
@Override
protected boolean isFinished() {
return false;
}
@Override
protected void end() {
Drivetrain.getInstance().setRaw(0, 0);
}
@Override
protected void interrupted() {
Drivetrain.getInstance().setRaw(0, 0);
}
}