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 coupling ratio #93

Open
thenetworkgrinch opened this issue Nov 10, 2023 · 6 comments
Open

Add coupling ratio #93

thenetworkgrinch opened this issue Nov 10, 2023 · 6 comments

Comments

@thenetworkgrinch
Copy link
Contributor

TBD on how to calculate it but apply using CTRE template base.

@thenetworkgrinch
Copy link
Contributor Author

https://www.chiefdelphi.com/t/ctre-start-of-2024-open-alpha-for-phoenix-6/441193/19

Theory is turns_encoder:turns_drive found empirically by rotating the module 360deg and marking the bottom center before and after. Theorhetically by encoder * 2nd * 3rd = wheel rot and encoder / 1st = drive rot

@thenetworkgrinch
Copy link
Contributor Author

  • Add glossary of coupling ratio's to docs

@thenetworkgrinch
Copy link
Contributor Author

rotate a few times for best measirement

@thenetworkgrinch
Copy link
Contributor Author

(if you use drive rotations as the basis instead of wheel rotations) is to lock the drive wheel in place, rotate the azimuth a few times, look at the number of rotations reported by the drive motor, drive rotations / azimuth rotations = coupling ratio

@thenetworkgrinch
Copy link
Contributor Author

thenetworkgrinch commented Oct 19, 2024

Taken from discord

(or other ctre folks)- I think there might be a mistake in the coupling correction code in phoenix 6's SwerveModule. Here's a derivation to help explain:

P_raw = drive motor position in rotations
P_comp = drive motor position, compensated for coupling error (ie, the true distance travelled by the wheel, in units of motor rotations)
V_raw = drive motor velocity in rotations per second
V_comp = drive motor velocity, compensated for coupling error (ie, the true velocity of the wheel, in units of motor rotations per second)
azimuth_rot = rotations of azimuth
azimuth_vel = velocity of azimuth in rotations per second
coupling_ratio = drive motor rotations per rotation of azimuth

P_comp = P_raw - (azimuth_rot * coupling_ratio)

We can extend this to velocity like so:

V_comp = V_raw - (azimuth_vel * coupling_ratio)

We then invert the function to solve for V_raw given V_comp (in the case of converting from a desired wheel speed to the necessary motor speed)

V_raw = V_comp + (azimuth_vel * coupling_ratio)

The first function matches the encoder correction implementation on line 250 of SwerveModule:

drive_rot -= angle_rot * m_couplingRatioDriveRotorToCANcoder;

However the inverse equation doesn't match the drive velocity correction implementation on line 324-327. Instead of adding the correction factor (azimuth_vel * coupling_ratio) to the desired speed V_comp, it is subtracted:

double azimuthTurnRps = m_steerVelocity.getValue();
/* Azimuth turn rate multiplied by coupling ratio provides back-out rps */
double driveRateBackOut = azimuthTurnRps * m_couplingRatioDriveRotorToCANcoder;
velocityToSet -= driveRateBackOut;

This would have the effect of doubling the coupling error when setting velocity.

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

No branches or pull requests

1 participant