Skip to content

Commit 84f2278

Browse files
committed
Add limit setters to SlewRateLimiter
1 parent 1362606 commit 84f2278

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

wpimath/src/main/java/edu/wpi/first/math/filter/SlewRateLimiter.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* edu.wpi.first.math.trajectory.TrapezoidProfile} instead.
1515
*/
1616
public class SlewRateLimiter {
17-
private final double m_positiveRateLimit;
18-
private final double m_negativeRateLimit;
17+
private double m_positiveRateLimit;
18+
private double m_negativeRateLimit;
1919
private double m_prevVal;
2020
private double m_prevTime;
2121

@@ -82,4 +82,28 @@ public void reset(double value) {
8282
m_prevVal = value;
8383
m_prevTime = MathSharedStore.getTimestamp();
8484
}
85+
86+
/**
87+
* Sets the rate-of-change limit.
88+
*
89+
* @param positiveRateLimit The rate-of-change limit in the positive direction, in units per
90+
* second. This is expected to be positive.
91+
* @param negativeRateLimit The rate-of-change limit in the negative direction, in units per
92+
* second. This is expected to be negative.
93+
*/
94+
public void setLimit(double positiveRateLimit, double negativeRateLimit) {
95+
m_positiveRateLimit = positiveRateLimit;
96+
m_negativeRateLimit = negativeRateLimit;
97+
}
98+
99+
/**
100+
* Sets the rate-of-change limit in both directions.
101+
*
102+
* @param rateLimit The rate-of-change limit in both directions, in units per second. This is
103+
* expected to be positive.
104+
*/
105+
public void setLimit(double rateLimit) {
106+
m_positiveRateLimit = rateLimit;
107+
m_negativeRateLimit = rateLimit;
108+
}
85109
}

wpimath/src/main/native/include/frc/filter/SlewRateLimiter.h

+25
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@ class SlewRateLimiter {
9292
m_prevTime = wpi::math::MathSharedStore::GetTimestamp();
9393
}
9494

95+
/**
96+
* Sets the rate-of-change limit.
97+
*
98+
* @param positiveRateLimit The rate-of-change limit in the positive direction, in units per
99+
* second. This is expected to be positive.
100+
* @param negativeRateLimit The rate-of-change limit in the negative direction, in units per
101+
* second. This is expected to be negative.
102+
*/
103+
void SetLimit(Rate_t positiveRateLimit, Rate_t negativeRateLimit) {
104+
m_positiveRateLimit = positiveRateLimit;
105+
m_negativeRateLimit = negativeRateLimit;
106+
}
107+
108+
/**
109+
* Sets the rate-of-change limit in both directions.
110+
*
111+
* @param rateLimit The rate-of-change limit in both directions, in units per second. This is
112+
* expected to be positive.
113+
*/
114+
void SetLimit(Rate_t rateLimit) {
115+
m_positiveRateLimit = rateLimit;
116+
m_negativeRateLimit = rateLimit;
117+
}
118+
119+
95120
private:
96121
Rate_t m_positiveRateLimit;
97122
Rate_t m_negativeRateLimit;

0 commit comments

Comments
 (0)