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

Conversation

katzuv
Copy link
Contributor

@katzuv katzuv commented Feb 16, 2025

This helps when the rate limit needs to be dynamically changed, such as when the drivetrain's acceleration is limited based on an elevator's height.

Not sure if it should be a setter or withLimit() so you can chain it (limiter.withLimit(newLimit).calculate(...)). Not sure about the C++ implementation. Feedback appreciated.

@katzuv katzuv requested a review from a team as a code owner February 16, 2025 17:45
@github-actions github-actions bot added the component: wpimath Math library label Feb 16, 2025
@katzuv
Copy link
Contributor Author

katzuv commented Feb 16, 2025

/format

@sciencewhiz
Copy link
Contributor

/format has been temporarily disabled. You'll have to run wpiformat yourself.

@katzuv

This comment has been minimized.

@katzuv katzuv force-pushed the slew-rate-limiter-rate-limits branch from 84f2278 to 173ae8f Compare February 16, 2025 20:03
Copy link
Contributor

@KangarooKoala KangarooKoala left a comment

Choose a reason for hiding this comment

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

Not sure if it should be a setter or withLimit() so you can chain it (limiter.withLimit(newLimit).calculate(...)).

Personally I think either having a setter or having optional parameters on calculate() would be good. A setter is good for when the calculation of what the limits should be happens in a different spot from where the limits are applied, while optional parameters on calculate() is good for when the limits are calculated where the limits are applied.

Using withLimit() also covers the second case, but my personal subjective feeling is that it's weird to use with[a-z]*() on reused objects that do more than carry configuration information. (That said, this is all subjective feeling and I'm fine with it going either way)

Not sure about the C++ implementation.

Aside from the comment that also applies to Java, it looks good to this local not-an-actual-WPILib-maintainer!

*/
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.

*/
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants