-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveCommand.java
More file actions
47 lines (37 loc) · 1.34 KB
/
DriveCommand.java
File metadata and controls
47 lines (37 loc) · 1.34 KB
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
package frc.robot.commands;
import java.util.function.DoubleSupplier;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.subsystems.Drivetrain;
public class DriveCommand extends Command {
Drivetrain drivetrain;
DoubleSupplier xSupplier;
DoubleSupplier ySupplier;
DoubleSupplier omegaSupplier;
DoubleSupplier triggerSupplier;
/** drive robot according to the x and y of the drive controller, drive at half speed by default, increase by half the value of the drive trigger (0-1)**/
public DriveCommand(Drivetrain drivetrain, DoubleSupplier xSupplier, DoubleSupplier ySupplier,
DoubleSupplier omegaSupplier, DoubleSupplier triggerSupplier) {
addRequirements(drivetrain);
this.drivetrain = drivetrain;
this.xSupplier = xSupplier;
this.ySupplier = ySupplier;
this.omegaSupplier = omegaSupplier;
this.triggerSupplier = triggerSupplier;
}
@Override
public void initialize() {
}
@Override
public void execute() {
double scaleFactor = triggerSupplier.getAsDouble() * 0.5 + 0.5;
drivetrain.drive(ySupplier.getAsDouble() * scaleFactor, xSupplier.getAsDouble() * scaleFactor, omegaSupplier.getAsDouble());
}
@Override
public void end(boolean interrupted) {
drivetrain.drive(0.0, 0.0, 0.0);
}
@Override
public boolean isFinished() {
return false;
}
}