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

Mag current calibration #346

Closed

Conversation

EwoudSmeur
Copy link
Member

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.

_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); \
Copy link
Member

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

@Drumettaz
Copy link
Contributor

Very interesting and usefull feature!
By the way, the magnetic perturbations are mostly generated by batteries and power wires that are closer to the IMU than motors.
This can be reduced by twisting the power wires together. The main idea is to avoid any loops between plus and minus wires. All cables should also be tightened to the frame: if they move, the perturbation changes.
Then, the remaining perturbation will be more efficiently corrected by current calibration.

@@ -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
Copy link
Member

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.

@flixr
Copy link
Member

flixr commented Jan 17, 2013

merged, thx

@flixr flixr closed this Jan 17, 2013
flixr pushed a commit to flixr/paparazzi that referenced this pull request Jan 17, 2013
dewagter pushed a commit to tudelft/paparazzi that referenced this pull request Feb 5, 2013
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.

None yet

3 participants