mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpimath] Add limit setters to SlewRateLimiter (#8581)
This is just #7793 with requested changes applied.
This commit is contained in:
@@ -14,8 +14,8 @@ import edu.wpi.first.math.MathUtil;
|
||||
* edu.wpi.first.math.trajectory.TrapezoidProfile} instead.
|
||||
*/
|
||||
public class SlewRateLimiter {
|
||||
private final double m_positiveRateLimit;
|
||||
private final double m_negativeRateLimit;
|
||||
private double m_positiveRateLimit;
|
||||
private double m_negativeRateLimit;
|
||||
private double m_prevVal;
|
||||
private double m_prevTime;
|
||||
|
||||
@@ -82,4 +82,29 @@ public class SlewRateLimiter {
|
||||
m_prevVal = value;
|
||||
m_prevTime = MathSharedStore.getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rate-of-change limit to the given positive and negative rate limits.
|
||||
*
|
||||
* @param positiveRateLimit The rate-of-change limit in the positive direction, in units per
|
||||
* second. This is expected to be positive.
|
||||
* @param negativeRateLimit The rate-of-change limit in the negative direction, in units per
|
||||
* second. This is expected to be negative.
|
||||
*/
|
||||
public void setLimit(double positiveRateLimit, double negativeRateLimit) {
|
||||
m_positiveRateLimit = positiveRateLimit;
|
||||
m_negativeRateLimit = negativeRateLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rate-of-change limit to the given positive rate limit and negative rate limit of
|
||||
* -rateLimit.
|
||||
*
|
||||
* @param rateLimit The rate-of-change limit in both directions, in units per second. This is
|
||||
* expected to be positive.
|
||||
*/
|
||||
public void setLimit(double rateLimit) {
|
||||
m_positiveRateLimit = rateLimit;
|
||||
m_negativeRateLimit = -rateLimit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,32 @@ class SlewRateLimiter {
|
||||
m_prevTime = wpi::math::MathSharedStore::GetTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rate-of-change limit to the given positive and negative rate
|
||||
* limits.
|
||||
*
|
||||
* @param positiveRateLimit The rate-of-change limit in the positive
|
||||
* direction, in units per second. This is expected to be positive.
|
||||
* @param negativeRateLimit The rate-of-change limit in the negative
|
||||
* direction, in units per second. This is expected to be negative.
|
||||
*/
|
||||
void SetLimit(Rate_t positiveRateLimit, Rate_t negativeRateLimit) {
|
||||
m_positiveRateLimit = positiveRateLimit;
|
||||
m_negativeRateLimit = negativeRateLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rate-of-change limit to the given positive rate limit and negative
|
||||
* rate limit of -rateLimit.
|
||||
*
|
||||
* @param rateLimit The rate-of-change limit in both directions, in units per
|
||||
* second. This is expected to be positive.
|
||||
*/
|
||||
void SetLimit(Rate_t rateLimit) {
|
||||
m_positiveRateLimit = rateLimit;
|
||||
m_negativeRateLimit = -rateLimit;
|
||||
}
|
||||
|
||||
private:
|
||||
Rate_t m_positiveRateLimit;
|
||||
Rate_t m_negativeRateLimit;
|
||||
|
||||
Reference in New Issue
Block a user