Class DynamicSlewRateLimiter

java.lang.Object
com.marswars.util.DynamicSlewRateLimiter

public class DynamicSlewRateLimiter extends Object
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

    Constructors
    Constructor
    Description
    DynamicSlewRateLimiter(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 Type
    Method
    Description
    double
    calculate(double input)
    Filters the input to limit its slew rate.
    double
    Gets the current rate limit.
    void
    reset(double value)
    Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.
    void
    setRateLimit(double rate_limit)
    Sets the rate limit.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.