Difference between revisions of "ImuCalibration"

From PaparazziUAV
Jump to navigation Jump to search
(added short info on mag calibration)
m (Grammatical/Readability changes)
Line 1: Line 1:
== Theory ==
== 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.
Accelerometer and Magnetometer calibration is critical to AHRS performance and can be performed using no special hardware. For the magnetometer, it is very important that the calibration be performed in the fully assembled vehicle, with all systems powered on. This is called hard-iron calibration and will allow us to compensate for any constant parasitic magnetic fields generated by the vehicle.
The calibration process consist in finding a set of neutrals and scale factors for each sensor, such as  
The calibration process consists of finding a set of neutrals and scale factors for each sensor, such as  




Line 10: Line 10:




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.   
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.   


<math>
<math>
Line 25: Line 25:
</math>
</math>


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
We can then record an important number of measurements in different orientations and find the set of scale factors and neutrals giving the norm closest to 9.81


== calibration script installation==
== calibration script installation==
Line 33: Line 33:
  sw/tools/calibration/calibrate.py  
  sw/tools/calibration/calibrate.py  


For the application to work howver you need additional Python softere, a so called ''library''. If you already have the package '''paparazzi-dev''' installed, the needed libs were already installed as dependencies.
For the application to work, however, you need additional Python libraries. If you already have the package '''paparazzi-dev''' installed, the needed libraries were already installed as dependencies.
If this is not the case you need to install '''python-scipy''' and '''python-matplotlib'''. This can be done via Synaptic or vai the command line of Ubuntu.
If this is not the case you need to install '''python-scipy''' and '''python-matplotlib'''. This can be done via Synaptic Package Manager or via the command-line of Ubuntu.


  $ sudo apt-get install python-scipy
  $ sudo apt-get install python-scipy
Line 41: Line 41:
=== How to use it ===
=== How to use it ===


* Flash the normal ap firmware if not already on it.
* Flash the board with the normal AP firmware (if it is not already on it.)


* Switch to the "raw sensors" telemetry mode and launch "server" to record a log.  
* Switch to the "raw sensors" telemetry mode and launch "server" to record a log.


* You really need to get the min/max on each axis.
* You really need to get the min/max on each axis.
** To calibrate the accels turn the imu on all six sides of the cube ( upright, inverted, on nose, on tail, on right side, on left side ). You can also take some measurememts banking 45 degres.<br>Try to get an homogeneous distribution of your measurements. I find it better to let the quad rest while measuring.
** To calibrate the accelerometers turn the IMU on all six sides of the cube (upright, inverted, on the nose, on the tail, on the right side, and on the left side.) You can also take some measurements banking 45 degrees.<br>Try to get a homogeneous distribution of your measurements. I find it better to let the aircraft rest while measuring.
** The most crucial part for the mag calibration. You really need to get the min/max on each axis, so align the mag axes along the local magnetic field vector and not just take the same orientations as when calibrating the accels... you can plot the values to see you get the maximum.
** This is the most crucial part for the magnetometer calibration: you really need to get the min/max on each axis, so align the magnetometer axes along the local magnetic field vector (not just take the same orientations as when calibrating the accelerometer.) You can plot the values to see when you get the maximum on each axis.


* You can then run the python script to get your calibration coefficients, e.g. for accelerometer calibration:  
* 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>''
  ''sw/tools/calibration/calibrate.py -i <your_ac_id> -s ACCEL <path_to_data_file var/logs/xxxxxxx.data>''
Line 55: Line 55:
(To get the ac_id, just open the *.data file - second column)
(To get the ac_id, just open the *.data file - second column)


=== How it works ===
=== How It Works ===


* It first makes an initial guess using min and max, ie for each axis
* It first makes an initial guess using min and max, i.e. for each axis
** neutral = 0.5 * (max + min)
** neutral = 0.5 * (max + min)
** sensitivity = 0.5*(max-min)
** sensitivity = 0.5*(max-min)


* It then uses a datafit algorithm to optimise the initial guess
* It then uses a data fitting algorithm to optimize the initial guess.




Screenshot of scilab version.
Screenshot of Scilab version.
[[Image:calibAccel.png|240px]]
[[Image:calibAccel.png|240px]]




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.
Note for magnetometer: because the magnetic field changes depending on where you are in the world, you will have to recalibrate your magnetometer 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 [http://www.ngdc.noaa.gov/geomagmodels/IGRFWMM.jsp here]).
When you move the aircraft 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 [http://www.ngdc.noaa.gov/geomagmodels/IGRFWMM.jsp here]).


=== Normalised magnetic fields for int_cmpl_quat AHRS filter ===  
=== Normalised magnetic fields for int_cmpl_quat AHRS filter ===  
Line 90: Line 90:


===Magnetometer:===
===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.
A magnetometer measures the Earth's magnetic field. In the northern hemisphere, this points north and down and in  the Southern hemisphere north and up.


Thus in the Northern hemisphere:
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 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.
*When pitching the IMU down, 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
*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:
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 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.
*When pitching the IMU up, 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
*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:===
===Gyrometer:===
You need some turntable to calibrate the scale factors of your gyros. For signs, the definition of the frame give the following properties:
You need some turntable to calibrate the scale factors of your gyros. For signs, the definition of the frame gives the following properties:


*when rolling right, <math>p</math> should be positive
*When rolling right, <math>p</math> should be positive.
*When pitching up, <math>q</math> should be positive
*When pitching up, <math>q</math> should be positive.
*When yawing to the right, <math>r</math> should be positive
*When yawing to the right, <math>r</math> should be positive.


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


*bank righ should give positive phi  
*Bank right should give positive phi  
*pitch up should give positive theta
*Pitch up should give positive theta
*yaw right should give increasing psi
*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 value you'll see after letting the IMU rest will end up being the "measure" (that is accelerometer and magnetometer.) 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.
*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 and then stabilizing to something good after you stop moving, the problem is in your gyros.


==Body to IMU rotation ==
==Body to IMU Rotation ==
Provision is made within the software to physically locate supported IMUs in orientations with respect to the aircraft/rotorcraft frame which suit available mounting options.  
Provision is made within the software to physically locate supported IMUs in orientations with respect to the aircraft/rotorcraft frame which suit available mounting options.  


* The in-line, parallel mount example:   
* The in-line, parallel mount example:   
Line 149: Line 149:
}}  
}}  


* Another variation might include turning the IMU upside down in the parallel plane:
* Another variation might include turning the IMU upside-down in the parallel plane:


Configured as:
Configured as:

Revision as of 23:25, 5 April 2012

Theory

Accelerometer and Magnetometer calibration is critical to AHRS performance and can be performed using no special hardware. For the magnetometer, it is very important that the calibration be performed in the fully assembled vehicle, with all systems powered on. This is called hard-iron calibration and will allow us to compensate for any constant parasitic magnetic fields generated by the vehicle. The calibration process consists of 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 factors and neutrals giving the norm closest to 9.81

calibration script installation

Paparazzi comes with an application written in the Python language to calibrate the accelerometers and magnetometer. The application can be found in the Paparazzi directory under

sw/tools/calibration/calibrate.py 

For the application to work, however, you need additional Python libraries. If you already have the package paparazzi-dev installed, the needed libraries were already installed as dependencies. If this is not the case you need to install python-scipy and python-matplotlib. This can be done via Synaptic Package Manager or via the command-line of Ubuntu.

$ sudo apt-get install python-scipy
$ sudo apt-get install python-matplotlib

How to use it

  • Flash the board with the normal AP firmware (if it is not already on it.)
  • Switch to the "raw sensors" telemetry mode and launch "server" to record a log.
  • You really need to get the min/max on each axis.
    • To calibrate the accelerometers turn the IMU on all six sides of the cube (upright, inverted, on the nose, on the tail, on the right side, and on the left side.) You can also take some measurements banking 45 degrees.
      Try to get a homogeneous distribution of your measurements. I find it better to let the aircraft rest while measuring.
    • This is the most crucial part for the magnetometer calibration: you really need to get the min/max on each axis, so align the magnetometer axes along the local magnetic field vector (not just take the same orientations as when calibrating the accelerometer.) You can plot the values to see when you get the maximum on each axis.
  • 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>

(To get the ac_id, just open the *.data file - second column)

How It Works

  • It first makes an initial guess using min and max, i.e. for each axis
    • neutral = 0.5 * (max + min)
    • sensitivity = 0.5*(max-min)
  • It then uses a data fitting algorithm to optimize the initial guess.


Screenshot of Scilab version. CalibAccel.png


Note for magnetometer: because the magnetic field changes depending on where you are in the world, you will have to recalibrate your magnetometer to fly somewhere else. When you move the aircraft 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).

Normalised magnetic fields for int_cmpl_quat AHRS filter

See the Complementary Quaternion (fixed point) AHRS subsystem page for details.

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 Earth's magnetic field. 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 the IMU down, 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 the IMU up, 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 gives the following properties:

  • When rolling 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 right 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 magnetometer.) 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 and then stabilizing to something good after you stop moving, the problem is in your gyros.

Body to IMU Rotation

Provision is made within the software to physically locate supported IMUs in orientations with respect to the aircraft/rotorcraft frame which suit available mounting options.

  • The in-line, parallel mount example:

Quad-top.png

Configured as:

File: conf/airframes/myplane.xml
    <define name="BODY_TO_IMU_PHI"   value="RadOfDeg( 0. )"/>
    <define name="BODY_TO_IMU_THETA" value="RadOfDeg( 0. )"/>
    <define name="BODY_TO_IMU_PSI"   value="RadOfDeg( 0. )"/>

As noted further above, calibration and sign verification procedures are carried out relative to the IMU frame, hence defines should be left at zero until they are completed.

  • The positive 90 degree offset, parallel mount example:

Quad-top IMU-90.png

Configured as:

File: conf/airframes/myplane.xml
    <define name="BODY_TO_IMU_PHI"   value="RadOfDeg( 0, )"/>
    <define name="BODY_TO_IMU_THETA" value="RadOfDeg( 0. )"/>
    <define name="BODY_TO_IMU_PSI"   value="RadOfDeg( 90. )"/>
  • Another variation might include turning the IMU upside-down in the parallel plane:

Configured as:

File: conf/airframes/myplane.xml
    <define name="BODY_TO_IMU_PHI"   value="RadOfDeg( 180.)"/>
    <define name="BODY_TO_IMU_THETA" value="RadOfDeg( 0. )"/>
    <define name="BODY_TO_IMU_PSI"   value="RadOfDeg( 0. )"/>

In Flight Tuning

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

AHRS telemetry.png 90 degree positive offset example

  • Open a Real_time plotter from the paparazzi console tools tab and drag int32 body_phi and int32 body_theta into the plotter box.
  • Hover rotorcraft (preferably indoors) to record data.
  • Copy the (best fit) recorded values into the airframe BODY_TO_IMU defines:
File: conf/airframes/myplane.xml
    <define name="BODY_TO_IMU_PHI"   value="RadOfDeg( 1.5)"/>
    <define name="BODY_TO_IMU_THETA" value="RadOfDeg( -0.5 )"/>
    <define name="BODY_TO_IMU_PSI"   value="RadOfDeg( 90. )"/>
  • Ignore 'on the ground' resting values as depicted in the above image. They will change once the vehicle is in flight. The aim is to get the 'in flight' values of "int32 body_phi" & "int32 body_theta" as close to zero as possible.