-
Notifications
You must be signed in to change notification settings - Fork 0
Issue #112 Robust Aimer, Fix Encoder Wrapping #162
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| import com.ctre.phoenix6.controls.Follower; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import com.google.flatbuffers.Constants; | ||
|
|
||
| import edu.wpi.first.math.MathUtil; | ||
| import edu.wpi.first.math.controller.ArmFeedforward; | ||
| import edu.wpi.first.math.controller.PIDController; | ||
|
|
@@ -57,6 +59,8 @@ public class AimerIORoboRio implements AimerIO { | |
| double lastPosition = 0.0; | ||
| double lastTime = Utils.getCurrentTimeSeconds(); | ||
|
|
||
| double encoderDiff = 0.0; | ||
|
|
||
| public AimerIORoboRio() { | ||
| aimerLeft.setControl(new Follower(ScoringConstants.aimRightMotorId, true)); | ||
|
|
||
|
|
@@ -152,8 +156,11 @@ public void setBrakeMode(boolean brake) { | |
| } | ||
|
|
||
| private double getEncoderPosition() { | ||
| double position = encoder.getAbsolutePosition(); | ||
| if (position < 0.0) | ||
| position = 0.0; | ||
| // 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; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -178,6 +185,14 @@ public void updateInputs(AimerIOInputs inputs) { | |
| feedforward.calculate(controlSetpoint, velocitySetpoint) + controllerVolts; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
||
|
|
||
| appliedVolts = MathUtil.clamp(appliedVolts, -12.0, 12.0); | ||
| aimerRight.setVoltage(appliedVolts); | ||
|
|
||
|
|
@@ -189,8 +204,8 @@ public void updateInputs(AimerIOInputs inputs) { | |
| double diffTime = currentTime - lastTime; | ||
| lastTime = currentTime; | ||
|
|
||
| inputs.aimVelocityRadPerSec = (getEncoderPosition() - lastPosition) / diffTime; | ||
| velocity = (getEncoderPosition() - lastPosition) / diffTime; | ||
| inputs.aimVelocityRadPerSec = encoderDiff / diffTime; | ||
| velocity = encoderDiff / diffTime; | ||
| lastPosition = getEncoderPosition(); | ||
|
|
||
| inputs.aimAppliedVolts = appliedVolts; | ||
|
|
||
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