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

create PID helper class for running PID loops in a Mechanism's run method #50

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dejabot
Copy link
Contributor

@dejabot dejabot commented Feb 23, 2024

Description

Thought exercise to simplify running PID loops in a Mechanism's run method.
PIDRunner handles:

  • calling a Motor's set method iff this is the first call, if the setpoint, slot, or feedforward have changed.
  • uses functional interfaces to get the setpoint, output, slot, or feedforward. makes it simple for callers to specify them, eg via method references
  • provides default implementations for common approaches to picking the slot, computing feedforward

How Has This Been Tested?

Needs to be tested. Sending for early feedback.

  • Unit tests: [Add your description here]
  • Simulator testing: [Add your description here]
  • On-robot bench testing: [Add your description here]
  • On-robot field testing: [Add your description here]

@dejabot dejabot requested a review from rcahoon February 23, 2024 13:32
src/main/java/com/team766/controllers/PIDRunner.java Outdated Show resolved Hide resolved
// changed, set the setpoint.
if (first
|| prevSetPoint != currentSetPoint
|| prevArbitraryFeedForward != currentArbitraryFeedForward
Copy link
Member

Choose a reason for hiding this comment

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

FYI, for arbitraryFeedForward strategies based on sensors (e.g. cosineArbitraryFeedForward), the value will likely change on every evaluation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx! q - wouldn't it stop once the mechanism stopped moving? or would there be unintended micromovements, eg from vibrations, etc.

in that case, wdyt of using a minimum change threshold?

Copy link
Member

@rcahoon rcahoon Mar 6, 2024

Choose a reason for hiding this comment

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

yes. in addition, many sensors will have signal noise that results in different measurements, even if the mechanism is perfectly still.

a change threshold is probably fine. i would think at most 0.01, unless you want to make it configurable

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

Successfully merging this pull request may close these issues.

2 participants