Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add limit setters to SlewRateLimiter #7793

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_negativeRateLimit = rateLimit;
m_negativeRateLimit = -rateLimit;

You could also make the first sentence of the doc comment match the first sentence of the SlewRateLimit(double) doc comment, but that's up to you.

}
}
24 changes: 24 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,30 @@ 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_negativeRateLimit = rateLimit;
m_negativeRateLimit = -rateLimit;

Same as Java.

}

private:
Rate_t m_positiveRateLimit;
Rate_t m_negativeRateLimit;
Expand Down
Loading