-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Mag current calibration #346
Conversation
_imu.mag.z = ((_imu.mag_unscaled.z - _imu.mag_neutral.z) * IMU_MAG_Z_SIGN * IMU_MAG_Z_SENS_NUM) / IMU_MAG_Z_SENS_DEN; \ | ||
} | ||
struct Int32Vect3 _mag_correction; \ | ||
_mag_correction.x = BFP_OF_REAL((IMU_MAG_X_CURRENT_COEF * (float) electrical.current),0); \ |
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.
No need to use BFP_OF_REAL here, rather directly cast to int32_t
Very interesting and usefull feature! |
@@ -87,6 +87,12 @@ struct ImuFloat { | |||
#define IMU_GYRO_R_NEUTRAL 0 | |||
#endif | |||
|
|||
#if !defined IMU_MAG_X_CURRENT_COEF && !defined IMU_MAG_Y_CURRENT_COEF && !defined IMU_MAG_Z_CURRENT_COEF |
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.
This should also not be used/needed. Rather only do the mag correction below if you have these coefficients defined, otherwise use the previous macro without mag correction.
merged, thx |
I made a calibration script for the magnetometer, to calibrate for interference from currents in the wires. I tested it in my transition branch, there it works very well. At thrust settings where I would normally get 30 degrees deviation from the magnetic north, this is now only 3 degrees.
The calibration is done by slowly ramping up the motors with the uav held steady on the ground. It is done best without the control laws to avoid feedback on the heading which will then influence the magnetometer reading again.
Theoretically a better implementation would be to calibrate for each motor individually, but that would require separate calibration code to spin each motor up. This could be a next step.
I also flight tested with the correction in place and this resulted in a much better autonomous flight.