Package com.marswars.util
Class DynamicSlewRateLimiter
java.lang.Object
com.marswars.util.DynamicSlewRateLimiter
A slew rate limiter that allows the rate limit to be changed dynamically without losing state.
This is based on WPILib's SlewRateLimiter but exposes methods to update the rate limit.
-
Constructor Summary
ConstructorsConstructorDescriptionDynamicSlewRateLimiter(double rate_limit) Creates a new DynamicSlewRateLimiter with the given rate limit.DynamicSlewRateLimiter(double rate_limit, double initial_value) Creates a new DynamicSlewRateLimiter with the given rate limit and initial value. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculate(double input) Filters the input to limit its slew rate.doubleGets the current rate limit.voidreset(double value) Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.voidsetRateLimit(double rate_limit) Sets the rate limit.
-
Constructor Details
-
DynamicSlewRateLimiter
public DynamicSlewRateLimiter(double rate_limit) Creates a new DynamicSlewRateLimiter with the given rate limit.- Parameters:
rate_limit- The rate-of-change limit, in units per second.
-
DynamicSlewRateLimiter
public DynamicSlewRateLimiter(double rate_limit, double initial_value) Creates a new DynamicSlewRateLimiter with the given rate limit and initial value.- Parameters:
rate_limit- The rate-of-change limit, in units per second.initial_value- The initial value of the input.
-
-
Method Details
-
calculate
public double calculate(double input) 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.
-
reset
public void reset(double value) Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.- Parameters:
value- The value to reset to.
-
setRateLimit
public void setRateLimit(double rate_limit) Sets the rate limit.- Parameters:
rate_limit- The new rate-of-change limit, in units per second.
-
getRateLimit
public double getRateLimit()Gets the current rate limit.- Returns:
- The current rate-of-change limit, in units per second.
-