Sensor calibration details. Accuracy of calibration and what is calculated

Hi,

I am building my first quad with pixracer controller and PX4 software hoping to play with PX4 code some time later. I do firmware development at work, but not related to flight control.
I looked through PX4 code, but it is extensive and I cannot navigate efficiently throught it yet :slight_smile:
Maybe somebody can answer my questions or point me to the right place in the code.

What is actually calculated during quad sensor calibration procedure in PX4 + QGC ?
I am curios to know and also it might help to understand how sensitive the calibration procedure is.

  1. Gyro. QGC says hold the frame still so it is probably just reading gyro drift?
  2. Accelerometer. 6 different frame positions. I guess it can read the gravity vector values and maybe noise level, but how is it used later? Some parameters for EKF? Maybe just signal amplitude, i.e. max values for each axis…
  3. Magnetometer(s). I can see this one probably needs calibration more than other sensors. Maybe the code just reads max values during rotations or maybe it creates a more detailed map of coefficients for different positions…

How sensitive is the procedure to alignment errors ? Can you do it by just holding the frame in your hands? The frame is not exactly a cube with flat sides… it is not easy to hold the frame perfectly level when it is laying on one of the sides.
During magnetometer calibration, is it important to rotate the frame full 360 degrees for each position? Does it need to be well aligned (vertical or horisontal) during rotation?
i.e. is there any advantage in using some kind of turn table and vice that can hold the quad at eactly 0, 90, 180 degrees?

Thanks,
Mikhail

OK, it was not hard to find calibration code in src\modiles\commander and I now understand what is calculated - offsets for gyro (i.e. drift), offsets and scaling factors for each axis for accelerometers. Compass calibration actually builds something like a 3D map with multiple sample points (not just 0, 90, 180 degrees angles) and uses “least square fit” for approximation and then calculates pairs of offsets and scale factors for each axis. i.e. mag calibration result is also just 3 offsets and 3 scaling factors (similarly to accel).

I still cannot make any conclusions regarding sensitivity of the calibration procedure :slight_smile: After trying the calibration a few times rotating the quad in my hands, I see that calculated calibration values (offset/scale) were almost the same for all attempts. No idea how bad would it be to have a 0.05 error in accelerometer X offset or X scaling factor, for example.
The instruments in QGC show attitude accurately. i.e. errors are too small to notice visually on the instruments, but they can probably affect hovering to some extend.