-
Notifications
You must be signed in to change notification settings - Fork 0
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
Issue #112 Robust Aimer, Fix Encoder Wrapping #162
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some ramblings from me here. TLDR: I think we can use the Set continuous input function of the PID and some unit circle math to solve our problem.
// return aimerRight.getPosition().getValueAsDouble() * 2.0 * Math.PI * (1.0 / 80.0); | ||
return encoder.getAbsolutePosition() * 2.0 * Math.PI - ScoringConstants.aimerEncoderOffset; | ||
return position * 2.0 * Math.PI - ScoringConstants.aimerEncoderOffset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually this position we want to zero out if it drops below 0.
Today we learned though that the mech team might make our resting position negative 🙃. So we'll actually want to create a Constants.java constant that can be used as the lower limit when the shooter drops below that value
encoderDiff = getEncoderPosition() - lastPosition; | ||
if (Math.abs(encoderDiff) > (ScoringConstants.aimerEncoderMaxValue)/2){ //checks if difference is ridiculous -> indicates wrapping | ||
if (encoderDiff < 0.0) | ||
encoderDiff = encoderDiff + ScoringConstants.aimerEncoderMaxValue; | ||
if (encoderDiff > 0.0) | ||
encoderDiff = encoderDiff - ScoringConstants.aimerEncoderMaxValue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your inclusion of the max encoder position made me think about this a bit differently than I had in the past.
We have the following known information:
- Our offset that sets the encoder output to 0 when the aimer is level. This is roughly the minimum value we should see before the encoder gets put into our coordinate frame
- A maximum angle we expect to read from the encoder, post transformation. In other words, we know the maximum angle the aimer can go from the 0 caused by the offset
Therefore, we should be able to determine the bounds of our sensor reading before the wrap. Then we could set continuous output mode on the PID with the correct values. It may be a good idea to draw this out and convince ourselves that this is a legit strategy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we find the maximum angle? Also controller.SetContinuous(); sets the PID to continuous output, no? The method sad in code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks like SetContinuous is actually not a good plan. But maybe the thing to do here is to identify when the encoder is out of bounds, clamp it to the bounds and disable motor output in the direction of "more out of bounds"
We do something similar for the climber - if it is above a "soft stop" we don't allow it to drive up anymore, but do allow it to drive down. So we could implement something similar for the aimer and its encoder here.
To determine the raw angular range, you will need the offset (a constant we already have) and a maximum throw of the arm (we may or may not have this constant already). Then the min raw angle is the offset, and the maximum raw angle is the offset + the throw, which then needs to be modulus 2 pi. Then we would check that the encoder value is inside the arc length between the two values (as treating the max as a pure max doesn't work if the max is wrapped to 0 or something)
No description provided.