ImuCalibration

From PaparazziUAV
Jump to navigation Jump to search

Theory

Accelerometers and Magnetometers calibration is critical for AHRS performances and can be performed using no special hardware. For the magnetometer, it is even very important that the calibration be performed in the fully assembled vehicle, with all systems powered. This is the so-called hard-iron calibration and will allow us to compensate for any constant parasitic magnetic field generated by the vehicle. The calibration process consist in finding a set of neutrals and scale factors for each sensor, such as



The principle of the calibration is the following : An accelerometer, on a vehicle at rest measures a constant vector ( the opposite of gravity ) in the earth frame, expressed in the vehicle frame.


DCM is a rotation matrix that converts between earth frame and body frame. It will change when we change the orientation of the vehicle. Nevertheless, a rotation conserves the norm of a vector. We can thus obtain the following scalar equation that doesn't depend on the vehicle orientation :


We can then record an important number of measurements in different orientations and find the set of scale factor and neutral giving the norm closest to 9.81

calibration script

Paparazzi comes with a python script to perform this operation ( sw/tools/calibration/calibrate.py ). You need to install python-scipy and python-matplotlib if you don't already have so.

Here is the way to use it:

  • Switch to the "raw sensors" telemetry mode and launch "server" to record a log.
  • In the case of the I2C dependent b2_v1.2 imu (and possibly the aspirin imu) obtain the IMU_MAG_RAW data by executing the target "test_imu_b2_2" and associated "message" function.
  • Move the quad in different orientations ( upright, inverted, on nose, on tail, on right side, on left side ). You can also take some measurememts banking 45 degres.
    Try to get an homogeneous distribution of your measurements. I find it better to let the quad rest while measuring.
  • You can then run the python script to get your calibration coefficients, e.g. for accelerometer calibration:
sw/tools/calibration/calibrate.py -i <your_ac_id> -s ACCEL <path_to_data_file var/logs/xxxxxxx.data>


It works like this:

  • It first makes an initial guess using min and max, ie for each axis
    • neutral = 0.5 * (max + min)
    • sensitivity = 0.5*(max-min)
  • It then uses a datafit algorithm to optimise the initial guess


Screenshot of scilab version. CalibAccel.png


Note for magnetometer: Because the magnetic field changes depending where on the globe you are, you will have to recalibrate your mag to fly somewhere else. When you move the quad to different positions for logging make sure you align it along the direction of the magnetic field which will result in the maximum values for each axis ( or you can look up the inclination and declination of the magnetic field where you live here).

AHRS-integer complementary (ic) filter normalised magnetic X,Y,Z fields

To calculate the normalised fields insert the relevant location coordinates hereand calculate.


Screenshot of noaa page. Noaa mag data.png


Copy the north(x),east(y),vertical(z) component values into scilab and execute "X/norm(X)".


Screenshot of scilab page. Normalised mag fields.png

Update values in airframe file.

File: conf/airframes/myplane.xml
  <section name="AHRS" prefix="AHRS_">
    <define name="PROPAGATE_FREQUENCY" value="512"/>
    <define name="H_X" value=" 0.3726923"/>
    <define name="H_Y" value=" 0.1514007"/>
    <define name="H_Z" value="-0.9155208"/>
  </section>

Finding Signs

For supported IMUs, the correct default signs are already defined in the code. If using a new IMU or sign for yours are not in the code yet, here is the way to find them.

We're calibrating everything relative to the IMU frame - Paparazzi has a parameter to define the orientation of the IMU with respect to the body of the vehicle that we'll use later, once you'll have decided of a good mechanical mounting.

Paparazzi uses North East Down (NED) frame, that is positive x is pointing to the front, positive y to the right and positive z down.

Accelerometer:

An accelerometer measures the non gravitational acceleration, that is . is pointing down, so is pointing up. So stop moving, disregard earth rotation and you'll measure .

  • When your IMU is level you should see x=0 y=0 z=-9.81
  • When pitching up -g is aligning with x, so you should see x>0, y=0 and z<0
  • When banking left -g is aligning with y, so you should see x=0, y>0 and z<0

Magnetometer:

A magnetometer measures the Earths magnetic vector. In the Northern hemisphere this points North and down and in the Southern hemisphere North and up.

Thus in the Northern hemisphere:

  • When you align your IMU with the direction of north, you should see x>0, y=0, z>0
  • when pitching down the IMU, the magnetic vector is aligning with x, so x should increase and z should decrease to zero.
  • if yawing your IMU to the left, the magnetic vector is aligning with y, so y should be positive, x should decrease to zero and z stay positive

And in the Southern hemisphere:

  • When you align your IMU with the direction of north, you should see x>0, y=0, z<0
  • when pitching up the IMU, the magnetic vector is aligning with x, so x should increase and z should increase towards zero.
  • if yawing your IMU to the left, the magnetic vector is aligning with y, so y should be positive, x should decrease to zero and z stay negative

Gyrometer:

You need some turntable to calibrate the scale factors of your gyros. For signs, the definition of the frame give the following properties:

  • when banking right, should be positive
  • When pitching up, should be positive
  • When yawing to the right, should be positive

Verification:

Switch to AHRS telemetry mode and look for the fields that are prefixed with imu_

  • bank righ should give positive phi
  • pitch up should give positive theta
  • yaw right should give increasing psi
  • the value you'll see after letting the IMU rest will end up being the "measure" ( that is accelerometer and mag ). If those are wrong the problem is in the calibration of your sensors
  • the values you get while moving the IMU are influenced by the gyros. If what you see is the value going crazy when you move, then stabilizing to something good after you stop moving, the problem is in your gyros.

Body to IMU rotation

coming soon !