Subsystem/ahrs

From PaparazziUAV
Jump to: navigation, search

AHRS subsystem

The Attitude and Heading Reference System subsystem specifies which attitude estimation filter you are using.

Currently possible AHRS subsystem types are:

Type Point type Firmwares Notes
int_cmpl_quat fixed all
float_cmpl floating all
float_dcm floating fixedwing
int_cmpl_euler fixed rotorcraft
float_mlkf floating rotorcraft
infrared fixedwing?

e.g. for the latest complementary filter:

File: conf/airframes/myplane.xml
  <firmware name="fixedwing or rotorcraft">
     ...
    <subsystem name="ahrs" type="int_cmpl_quat"/>
  </firmware>

Implementations

There is a test program ( sw/airborne/test/ahrs/compare_ahrs.py ) to compare different AHRS implementations on simple test cases.

Caution! Please also see issue 93 about proper handling of BODY_TO_IMU in all AHRS algorithms.


Complementary Quaternion (fixed point)

To measure attitude angles, gyrometers measurements are integrated. The result of integration is accurate for short term, but gyro bias is accumulated, which results in long term errors (drift). On the other hand, accelerometers can be used to measure angles directly, but they suffer from noise due to vibrations. The measurement is then only accurate when averaged over a long term. Also, accelerometers alone are unable to give accurate angles when the vehicle is accelerating. Complementary filter takes advantage of both sensors, using a low-pass filter on accelerometer readings and high pass filter on gyrometers readings, to estimate attitude angles.

  • No danger of gimbal lock, since quaternions are used.
  • The arithmetic is fixed point and is thus suitable if the processor (on your board) has no FPU.
  • Estimates the gyro bias.
  • For rotorcrafts: uses magnetometer for heading. Needs calibration!
    You can add <configure name="USE_MAGNETOMETER" value="TRUE"/> to be explicit about it.
  • Also suitable for fixedwings, but you need GPS.
    • Compensation of centrifugal force via GPS speed (to fly in circles with a fixedwing).
      Enabled with AHRS_GRAVITY_UPDATE_COORDINATED_TURN which is set by default for a fixedwing firmware.
    • Uses GPS course for heading estimation and disable magnetometer, add <configure name="USE_MAGNETOMETER" value="FALSE"/> if you want to be explicit.


Other flags of interest are:

  • AHRS_PROPAGATE_LOW_PASS_RATES : apply a low pass filter on rotational velocity
  • AHRS_MAG_UPDATE_ALL_AXES : use mag to also update roll/pitch and not only yaw (not recommended in most cases)
  • NEW since v5.1_devel-455-gb40da0a:
    • Proper scaling of corrections for 100Hz fixedwing or 500Hz for rotorcraft.
    • Allow tuning of the accel and mag correction natural freqency and damping.
    • Tunable gravity_heuristic_factor to reduce accelerometer influence only when the vehicle is accelerating (norm of ax,ay,az ~ 9,81 m/s2).
  • Flags of interest in master branch are:
    • AHRS_PROPAGATE_FREQUENCY: IMU gyrometer reading frequency ( Hz, depend on IMU subsystem used and its configuration)
    • AHRS_CORRECT_FREQUENCY: IMU accelerometer reading frequency (Hz)
    • AHRS_MAG_CORRECT_FREQUENCY: IMU magnetometer reading frequency (Hz)
    • AHRS_ACCEL_OMEGA: Complementary filter accelerometer cut-off frequency (rd/s). Default is 0.063 rd/s, the accelerometer reading are "averaged" over 100 seconds (= 2*pi/0.063) to correct gyro bias. Lower the cut-off frequency reduce the influence of accelerometers. WARNING: if ACCEL_OMEGA is set at a lower frequency, the gyro bias variations may not be corrected fast enough. As a result, the computed attitude may show significant static (or low frequency) errors. If accel_omega is set higher, the gyro bias will be well corrected and the static accuracy of the computed angle will be very good, but the dynamic error of the computed angle may be bad.
    • AHRS_ACCEL_ZETA: Complementary filter accelerometer damping. Default is 0.9
    • AHRS_MAG_OMEGA:Complementary filter magnetometer cut-off frequency (rd/s). Default is 0.04 rd/s. Acts the same as accelerometer but on the yaw axis.
    • AHRS_MAG_ZETA:Complementary filter magnetometer damping. Default is 0.9
    • AHRS_GRAVITY_HEURISTIC_FACTOR: Default is 30. Reduce accelerometer cut-off frequency when the vehicle is accelerating: norm(ax,ay,az) ~ 9,81 m/s2. WARNING: when the IMU is not well damped, the norm of accelerometers never equals to 9,81 m/s2. As a result, the GRAVITY_HEURISTIC_FACTOR will reduce the accelerometer bandwith even if the vehicle is not accelerating. Set AHRS_GRAVITY_HEURISTIC_FACTOR = 0 in case of vibrations.
File: conf/airframes/myplane.xml
  <firmware name="fixedwing or rotorcraft">
     ...
    <subsystem name="ahrs" type="int_cmpl_quat"/>
  </firmware>
 
  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value=" 0.51562740288882"/>
    <define name="H_Y" value="-0.05707735220832"/>
    <define name="H_Z" value=" 0.85490967783446"/>
  </section>

Also see the Local Magnetic Field section.

To use int_cmpl_quat for fixedwings without magnetometer (GPS based heading estimation instead):

File: conf/airframes/myplane.xml
  <firmware name="fixedwing">
     ...
    <subsystem name="ahrs" type="int_cmpl_quat"/>
    <configure name="USE_MAGNETOMETER" value="FALSE"/>
  </firmware>


Complementary Quaternion/Rotation Matrix (floating point)

  • Estimates the gyro bias.
  • By default uses magnetometer for heading for rotorcrafts.
  • You need to define either AHRS_PROPAGATE_RMAT or AHRS_PROPAGATE_QUAT (select if the propagation is done in rotation matrix or quaternion representation).
  • For fixedwings:
    • Compensation of centrifugal force via GPS speed (to fly in circles with a fixedwing).
      Enabled with AHRS_GRAVITY_UPDATE_COORDINATED_TURN which is set by default for a fixedwing firmware.
    • GPS based heading estimation: https://github.com/paparazzi/paparazzi/issues/130

Other flags of interest are:

  • AHRS_PROPAGATE_LOW_PASS_RATES : apply a low pass filter on rotational velocity
  • AHRS_MAG_UPDATE_ALL_AXES : use mag to also update roll/pitch and not only yaw (not recommended in most cases)
  • AHRS_GRAVITY_UPDATE_NORM_HEURISTIC: lower the gain of the gravity update based on a acceleration norm heuristic (e.g. good for bungee takeoff)


File: conf/airframes/myplane.xml
  <firmware name="rotorcraft or fixedwing">
     ...
    <subsystem name="ahrs" type="float_cmpl_rmat">
      <define name="AHRS_PROPAGATE_QUAT"/>
    </subsystem>
  </firmware>
 
  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value=" 0.51562740288882"/>
    <define name="H_Y" value="-0.05707735220832"/>
    <define name="H_Z" value=" 0.85490967783446"/>
  </section>

Also see the Local Magnetic Field section.

No danger of gimbal lock, since quaternions are used.
Suitable for fixedwings. Needs GPS!
Suitable for rotorcraft if the magnetometer is calibrated.
The arithmetic is floating point and is thus not suitable if the processor (on your board) has no FPU.


DCM (floating point)

  • No direct gyro bias estimation, but also compensates for attitude drift.
  • Uses GPS speed for heading.
  • Compensation of centrifugal force via GPS speed (to fly in circles with a fixedwing).
  • Careful, it doesn't handle all BODY_TO_IMU rotations (mounting positions) correctly!

The algorithm was developed by William Premerlani and Paul Bizard. The theory can be found here: DCMDraft2.pdf The algorithm is also used in the AHRS systems of the AdruIMU. The name DCM for the algorithm is really a misnomer, as that just means that the orientation is represented as a DirectionCosineMatrix (rotation matrix). But since people already know it under that name, we kept it.

Other flags of interest are:

  • USE_MAGNETOMETER : use magnetometer to update yaw (UNTESTED. The magnetometer code has to be improved, since ferromagnetic materials affect the magnetic field. This is currently not implemented.)
File: conf/airframes/myplane.xml
  <firmware name="fixedwing">
     ...
    <subsystem name="ahrs" type="float_dcm"/>
  </firmware>


Complementary Euler (fixed point)

  • Not recommended for fixedwings, as this filter doesn't compensate for centrifugal force when flying turns.
  • Magnetometer is always only used for heading (yaw).
  • Does not handle the accel and mag updates correctly if BODY_TO_IMU is used for more than just adjustment by a few degrees.
  • In general, rather use int_cmpl_quat

Optional flags/defines are:

  • FACE_REINJ_1 : defaults to 1024
  • IMU_MAG_OFFSET : offset to subtract from the heading calculated by the magnetometer
  • USE_NOISE_FILTER : apply a simple filter on the rate and accel inputs
  • USE_NOISE_CUT : cut rate input at 1 rad/s and accel input at 20m/s²


File: conf/airframes/myplane.xml
  <firmware name="rotorcraft">
     ...
    <subsystem name="ahrs" type="int_cmpl_euler"/>
  </firmware>
 
  <section name="MISC">
    <define name="FACE_REINJ_1" value="1024"/> <!-- optional, defaults to 1024 -->
  </section>

Possible danger of gimbal lock, since quaternions are not used.
Repeat from above: Not suitable for fixedwings.
Suitable for rotorcraft. The magnetometer is used to determine the yaw and needs to be calibrated. Recommended replacement: int_cmpl_quat
The arithmetic is fixed point and is thus suitable if the processor (on your board) has no FPU.


Kalman Filter Quaternion

Multiplicative Linearized Kalman Filter in quaternion formulation.

  • Available in v5.0 and later
  • Estimates the gyro bias.
  • Uses magnetometer to update all 3 axes.
File: conf/airframes/myplane.xml
  <firmware name="rotorcraft">
     ...
    <subsystem name="ahrs" type="float_mlkf"/>
  </firmware>
 
  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value=" 0.51562740288882"/>
    <define name="H_Y" value="-0.05707735220832"/>
    <define name="H_Z" value=" 0.85490967783446"/>
  </section>

Also see the Local Magnetic Field section.

No danger of gimbal lock, since quaternions are used.
Not suitable for fixedwings!
Suitable for rotorcraft. The magnetometer is used and needs to be well calibrated. Estimates attitude and heading. Does not use GPS.
The arithmetic is floating point and is thus not suitable if the processor (on your board) has no FPU.

Infrared

For use with infrared sensors that detect aircraft attitude and the infrared module.

Local Magnetic Field

Screenshot of noaa page
Screenshot of scilab page

This is needed if the magnetometer should be used !
Take also a look at magnetometer calibration which should be done to increase accuracy !

First the values of the local magnetic field vector are needed. They can be found at the states geological institute.

USA ngdc.noaa.gov

Needed values are:

  • north component (x)
  • east component (y)
  • vertical component (z)

The vector components are in nanotesla (nT) but AHRS needs these values as a unit vector (the length of a unit vector is 1), so they need to be normalized.

Convert them:

Copy the north(x), east(y), and vertical(z) component values into scilab and execute "X/norm(X)" or run this in ipython:

import numpy as np
x = np.array([20875.1, 8480.2, -51279.8])
x/np.linalg.norm(x)

or enter this into Wolfram Alpha:

Normalize[{20875.1, 8480.2, -51279.8}]

Lastly, enter the results into your airframe file as H_X, H_Y, and H_Z:

File: conf/airframes/myplane.xml
  <section name="AHRS" prefix="AHRS_">
    <define name="H_X" value="0.372692"/>
    <define name="H_Y" value="0.151401"/>
    <define name="H_Z" value="-0.915521"/>
  </section>

Update geomagnetic field vector based on GPS

You can also add the geo_mag.xml module, which will update the normalized magnetic field at startup using GPS fix:

File: conf/airframes/myplane.xml
  <modules>
    <load name="geo_mag.xml"/>
  </modules>