Skip to content

Commit

Permalink
Add limit setters to SlewRateLimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
katzuv committed Feb 16, 2025
1 parent 1362606 commit 84f2278
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* 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;

Expand Down Expand Up @@ -82,4 +82,28 @@ public void reset(double value) {
m_prevVal = value;
m_prevTime = MathSharedStore.getTimestamp();
}

/**
* Sets the rate-of-change limit.
*
* @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 in both directions.
*
* @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;
}
}
25 changes: 25 additions & 0 deletions wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ class SlewRateLimiter {
m_prevTime = wpi::math::MathSharedStore::GetTimestamp();
}

/**
* Sets the rate-of-change limit.
*
* @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 in both directions.
*
* @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;
Expand Down

0 comments on commit 84f2278

Please sign in to comment.