Package edu.wpi.first.math.filter
Class SlewRateLimiter
java.lang.Object
edu.wpi.first.math.filter.SlewRateLimiter
A class that limits the rate of change of an input value. Useful for implementing voltage,
setpoint, and/or output ramps. A slew-rate limit is most appropriate when the quantity being
controlled is a velocity or a voltage; when controlling a position, consider using a
TrapezoidProfile instead.-
Constructor Summary
ConstructorsConstructorDescriptionSlewRateLimiter(double rateLimit) Creates a new SlewRateLimiter with the given positive rate limit and negative rate limit of -rateLimit.SlewRateLimiter(double positiveRateLimit, double negativeRateLimit, double initialValue) Creates a new SlewRateLimiter with the given positive and negative rate limits and initial value. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculate(double input) Filters the input to limit its slew rate.doubleReturns the value last calculated by the SlewRateLimiter.voidreset(double value) Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.voidsetLimit(double rateLimit) Sets the rate-of-change limit to the given positive rate limit and negative rate limit of -rateLimit.voidsetLimit(double positiveRateLimit, double negativeRateLimit) Sets the rate-of-change limit to the given positive and negative rate limits.
-
Constructor Details
-
SlewRateLimiter
Creates a new SlewRateLimiter with the given positive and negative rate limits and initial value.- Parameters:
positiveRateLimit- The rate-of-change limit in the positive direction, in units per second. This is expected to be positive.negativeRateLimit- The rate-of-change limit in the negative direction, in units per second. This is expected to be negative.initialValue- The initial value of the input.
-
SlewRateLimiter
Creates a new SlewRateLimiter with the given positive rate limit and negative rate limit of -rateLimit.- Parameters:
rateLimit- The rate-of-change limit, in units per second.
-
-
Method Details
-
calculate
Filters the input to limit its slew rate.- Parameters:
input- The input value whose slew rate is to be limited.- Returns:
- The filtered value, which will not change faster than the slew rate.
-
lastValue
Returns the value last calculated by the SlewRateLimiter.- Returns:
- The last value.
-
reset
Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.- Parameters:
value- The value to reset to.
-
setLimit
Sets the rate-of-change limit to the given positive and negative rate limits.- Parameters:
positiveRateLimit- The rate-of-change limit in the positive direction, in units per second. This is expected to be positive.negativeRateLimit- The rate-of-change limit in the negative direction, in units per second. This is expected to be negative.
-
setLimit
Sets the rate-of-change limit to the given positive rate limit and negative rate limit of -rateLimit.- Parameters:
rateLimit- The rate-of-change limit in both directions, in units per second. This is expected to be positive.
-