-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRampMove.java
More file actions
51 lines (41 loc) · 1.36 KB
/
RampMove.java
File metadata and controls
51 lines (41 loc) · 1.36 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
48
49
50
51
package frc.robot.commands.ramp;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.constants.Constants;
import frc.robot.subsystems.LightStrip;
import frc.robot.subsystems.Ramp;
import frc.robot.utils.TimeoutCounter;
import java.util.function.DoubleSupplier;
public class RampMove extends Command {
private final Ramp ramp;
private final DoubleSupplier encoderValue;
private final TimeoutCounter timeoutCounter;
private final Timer timer = new Timer();
public RampMove(Ramp ramp, LightStrip lightStrip, DoubleSupplier encoderValue) {
this.ramp = ramp;
this.encoderValue = encoderValue;
this.timeoutCounter = new TimeoutCounter("RampMove", lightStrip);
addRequirements(this.ramp);
}
@Override
public void initialize() {
timer.restart();
ramp.setRampPos(encoderValue.getAsDouble());
}
@Override
public void execute() {
ramp.updateFF();
}
@Override
public void end(boolean interrupted) {
timer.stop();
}
@Override
public boolean isFinished() {
if (timer.hasElapsed(Constants.RAMP_MOVE_TIMEOUT)){
timeoutCounter.increaseTimeoutCount();
return true;
}
return Math.abs(ramp.getRampPos() - ramp.getDesiredPosition()) < Constants.RAMP_MOVE_THRESHOLD;
}
}