SlewRateLimiter
#SlewRateLimiter
A SlewRateLimiter limits how fast a value can change per second. If the input jumps, the output follows it at no more than the allowed rate until it catches up.
It is useful for drivetrain commands, where a sudden change in joystick position would otherwise cause wheel slip or a tip-over, and for any mechanism that should not be commanded to change instantly.
#Creating a SlewRateLimiter
SlewRateLimiter limiter = new SlewRateLimiter(3.@);
SlewRateLimiter asymmetric = new SlewRateLimiter(3.@, -6.0, 0.0);| Parameter | Description |
|---|---|
rate | Maximum change per second in both directions. A value of 3.0 lets the output go from 0 to 1 in about a third of a second. |
positiveRate | Maximum increase per second. |
negativeRate | Maximum decrease per second. The sign is ignored, so 6.0 and -6.0 mean the same. |
initialValue | The starting output. The single-rate constructor uses 0.0. |
The single-rate constructor uses the same rate for increases and decreases. Only the size of each rate is used, so a negative positiveRate or a positive negativeRate works the same as the positive or negative value.
An asymmetric limiter is useful when a mechanism should speed up gradually but be allowed to stop quickly.
#Limiting a Value
double forwardThis overload measures the time since the previous call with System.nanoTime(). If you already know the loop time, pass it in seconds:
double forward = limiter.calculate(-gamepad1.left_stick_y, timer.getDt());
Each call moves the output toward the input by at most rate × dt, and returns the new output.
| Method | Description |
|---|---|
calculate(input) | Limits the change using the measured time since the previous call. |
calculate(input, dt) | Limits the change using the dt you provide, in seconds. |
getValue() | The current output. |
reset(value) | Sets the output to value. The next calculate(input) call does not move the output, because the timer starts again. |
The first call to calculate(input) does not move the output, because there is no earlier call to measure the time from. The output starts moving on the second call. With calculate(input, dt) you provide the time yourself, so the output moves on the first call as well. A negative dt is treated as 0.
Última atualização 2026-11-16