11#include "units/time.h"
28 using Rate = units::compound_unit<Unit, units::inverse<units::seconds>>;
45 : m_positiveRateLimit{positiveRateLimit},
46 m_negativeRateLimit{negativeRateLimit},
47 m_prevVal{initialValue},
49 units::microsecond_t{
wpi::math::MathSharedStore::GetTimestamp()}} {}
69 units::second_t elapsedTime = currentTime - m_prevTime;
71 std::clamp(input - m_prevVal, m_negativeRateLimit * elapsedTime,
72 m_positiveRateLimit * elapsedTime);
73 m_prevTime = currentTime;
96 Rate_t m_positiveRateLimit;
97 Rate_t m_negativeRateLimit;
99 units::second_t m_prevTime;
A class that limits the rate of change of an input value.
Definition SlewRateLimiter.h:25
SlewRateLimiter(Rate_t rateLimit)
Creates a new SlewRateLimiter with the given positive rate limit and negative rate limit of -rateLimi...
Definition SlewRateLimiter.h:57
units::unit_t< Rate > Rate_t
Definition SlewRateLimiter.h:29
Unit_t LastValue() const
Returns the value last calculated by the SlewRateLimiter.
Definition SlewRateLimiter.h:82
Unit_t Calculate(Unit_t input)
Filters the input to limit its slew rate.
Definition SlewRateLimiter.h:67
units::compound_unit< Unit, units::inverse< units::seconds > > Rate
Definition SlewRateLimiter.h:28
units::unit_t< Unit > Unit_t
Definition SlewRateLimiter.h:27
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.h:43
void Reset(Unit_t value)
Resets the slew rate limiter to the specified value; ignores the rate limit when doing so.
Definition SlewRateLimiter.h:90
static units::second_t GetTimestamp()
Definition MathShared.h:65
Definition SystemServer.h:9
Definition ntcore_cpp.h:26