10#include "wpi/units/time.hpp"
25 using Unit_t = wpi::units::unit_t<Unit>;
27 wpi::units::compound_unit<Unit, wpi::units::inverse<wpi::units::seconds>>;
28 using Rate_t = wpi::units::unit_t<Rate>;
44 : m_positiveRateLimit{positiveRateLimit},
45 m_negativeRateLimit{negativeRateLimit},
46 m_prevVal{initialValue},
47 m_prevTime{
wpi::units::microsecond_t{
67 wpi::units::second_t currentTime =
69 wpi::units::second_t elapsedTime = currentTime - m_prevTime;
71 std::clamp(input - m_prevVal, m_negativeRateLimit * elapsedTime,
72 m_positiveRateLimit * elapsedTime);
73 m_prevTime = currentTime;
105 m_positiveRateLimit = positiveRateLimit;
106 m_negativeRateLimit = negativeRateLimit;
117 m_positiveRateLimit = rateLimit;
118 m_negativeRateLimit = -rateLimit;
122 Rate_t m_positiveRateLimit;
123 Rate_t m_negativeRateLimit;
125 wpi::units::second_t m_prevTime;
Definition MathShared.hpp:37
static wpi::units::second_t GetTimestamp()
Definition MathShared.hpp:65
wpi::units::compound_unit< Unit, wpi::units::inverse< wpi::units::seconds > > Rate
Definition SlewRateLimiter.hpp:26
SlewRateLimiter(Rate_t positiveRateLimit, Rate_t negativeRateLimit, Unit_t initialValue=Unit_t{0})
Creates a new SlewRateLimiter with the given positive and negative rate limits and initial value.
Definition SlewRateLimiter.hpp:42
Unit_t LastValue() const
Returns the value last calculated by the SlewRateLimiter.
Definition SlewRateLimiter.hpp:82
void SetLimit(Rate_t positiveRateLimit, Rate_t negativeRateLimit)
Sets the rate-of-change limit to the given positive and negative rate limits.
Definition SlewRateLimiter.hpp:104
void Reset(Unit_t value)
Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.
Definition SlewRateLimiter.hpp:90
Unit_t Calculate(Unit_t input)
Filters the input to limit its slew rate.
Definition SlewRateLimiter.hpp:66
wpi::units::unit_t< Rate > Rate_t
Definition SlewRateLimiter.hpp:28
void SetLimit(Rate_t rateLimit)
Sets the rate-of-change limit to the given positive rate limit and negative rate limit of -rateLimit.
Definition SlewRateLimiter.hpp:116
wpi::units::unit_t< Unit > Unit_t
Definition SlewRateLimiter.hpp:25
SlewRateLimiter(Rate_t rateLimit)
Creates a new SlewRateLimiter with the given positive rate limit and negative rate limit of -rateLimi...
Definition SlewRateLimiter.hpp:56
Definition LinearSystem.hpp:20
Definition CvSource.hpp:15