Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
ins_ekf2 module

simple INS and AHRS using EKF2 from PX4

No detailed description...

Example for airframe file

Add to your firmware section: This example contains all possible configuration options, not all of them are mandatory!

<module name="ins_ekf2">
b'<define name="INS_EKF2_OPTITRACK" value="false" />\n '
b'<define name="INS_EKF2_FUSION_MODE" value="(MASK_USE_GPS)" />\n '
b'<define name="INS_EKF2_VDIST_SENSOR_TYPE" value="VDIST_SENSOR_BARO" />\n '
b'<define name="INS_EKF2_GPS_CHECK_MASK" value="(MASK_GPS_NSATS | MASK_GPS_HACC | MASK_GPS_SACC)" />\n '
b'<define name="INS_EKF2_EVP_NOISE" value="0.1" />\n '
b'<define name="INS_EKF2_EVV_NOISE" value="1.0" />\n '
b'<define name="INS_EKF2_EVA_NOISE" value="0.05" />\n '
b'<define name="INS_EKF2_GPS_V_NOISE" value="0.3" />\n '
b'<define name="INS_EKF2_GPS_P_NOISE" value="0.5" />\n '
b'<define name="INS_EKF2_BARO_NOISE" value="3.5" />\n\n '
b'<define name="INS_EKF2_IMU_POS_X" value="0" />\n '
b'<define name="INS_EKF2_IMU_POS_Y" value="0" />\n '
b'<define name="INS_EKF2_IMU_POS_Z" value="0" />\n '
b'<define name="INS_EKF2_GPS_POS_X" value="0" />\n '
b'<define name="INS_EKF2_GPS_POS_Y" value="0" />\n '
b'<define name="INS_EKF2_GPS_POS_Z" value="0" />\n '
b'<define name="INS_EKF2_FLOW_POS_X" value="0" />\n '
b'<define name="INS_EKF2_FLOW_POS_Y" value="0" />\n '
b'<define name="INS_EKF2_FLOW_POS_Z" value="0" />\n\n '
b'<define name="INS_EKF2_SONAR_MIN_RANGE" value="0.05" />\n '
b'<define name="INS_EKF2_SONAR_MAX_RANGE" value="3" />\n '
b'<define name="INS_EKF2_RANGE_MAIN_AGL" value="1" />\n '
b'<define name="INS_EKF2_FLOW_SENSOR_DELAY" value="15" />\n '
b'<define name="INS_EKF2_MIN_FLOW_QUALITY" value="100" />\n '
b'<define name="INS_EKF2_MAX_FLOW_RATE" value="20" />\n '
b'<define name="INS_EKF2_FLOW_NOISE" value="0.01" />\n '
b'<define name="INS_EKF2_FLOW_NOISE_QMIN" value="0.03" />\n '
b'<define name="INS_EKF2_FLOW_INNOV_GATE" value="3" />\n '
b'<define name="INS_EKF2_AGL_ID" value="ABI_BROADCAST" />\n '
b'<define name="INS_EKF2_BARO_ID" value="ABI_BROADCAST" />\n '
b'<define name="INS_EKF2_GYRO_ID" value="ABI_BROADCAST" />\n '
b'<define name="INS_EKF2_ACCEL_ID" value="ABI_BROADCAST" />\n '
b'<define name="INS_EKF2_MAG_ID" value="ABI_BROADCAST" />\n '
b'<define name="INS_EKF2_GPS_ID" value="ABI_BROADCAST" />\n '
</module>

Module configuration options

Define Options

  • name: INS_EKF2_OPTITRACK value: false
    Description: Easy configuration of full optitrack (position- and yaw fusion, height, init origin)
  • name: INS_EKF2_FUSION_MODE value: (MASK_USE_GPS)
    Description: The sensor that are used for position fusion
  • name: INS_EKF2_VDIST_SENSOR_TYPE value: VDIST_SENSOR_BARO
    Description: Primary sensor used for vertical distance
  • name: INS_EKF2_GPS_CHECK_MASK value: (MASK_GPS_NSATS | MASK_GPS_HACC | MASK_GPS_SACC)
    Description: GPS checks enabled before initialization of the global positioning
  • name: INS_EKF2_EVP_NOISE value: 0.1
    Description: External vision position noise [m]
  • name: INS_EKF2_EVV_NOISE value: 1.0
    Description: External vision velocity noise [m/s]
  • name: INS_EKF2_EVA_NOISE value: 0.05
    Description: External vision angle noise [rad]
  • name: INS_EKF2_GPS_V_NOISE value: 0.3
    Description: GPS measurement noise for horizontal velocity [m/s]
  • name: INS_EKF2_GPS_P_NOISE value: 0.5
    Description: GPS measurement position noise [m]
  • name: INS_EKF2_BARO_NOISE value: 3.5
    Description: Barometric measurement noise for altitude [m]
  • name: INS_EKF2_IMU_POS_X value: 0
    Description: IMU X offset from CoG position [m]
  • name: INS_EKF2_IMU_POS_Y value: 0
    Description: IMU Y offset from CoG position [m]
  • name: INS_EKF2_IMU_POS_Z value: 0
    Description: IMU Z offset from CoG position [m]
  • name: INS_EKF2_GPS_POS_X value: 0
    Description: GPS X offset from CoG position [m]
  • name: INS_EKF2_GPS_POS_Y value: 0
    Description: GPS Y offset from CoG position [m]
  • name: INS_EKF2_GPS_POS_Z value: 0
    Description: GPS Z offset from CoG position [m]
  • name: INS_EKF2_FLOW_POS_X value: 0
    Description: Flow sensor X offset from CoG position [m]
  • name: INS_EKF2_FLOW_POS_Y value: 0
    Description: Flow sensor Y offset from CoG position [m]
  • name: INS_EKF2_FLOW_POS_Z value: 0
    Description: Flow sensor Z offset from CoG position [m]
  • name: INS_EKF2_SONAR_MIN_RANGE value: 0.05
    Description: AGL sensor minimum range [m]
  • name: INS_EKF2_SONAR_MAX_RANGE value: 3
    Description: AGL sensor maximum range [m]
  • name: INS_EKF2_RANGE_MAIN_AGL value: 1
    Description: If enabled uses radar sensor as primary AGL source, if possible
  • name: INS_EKF2_FLOW_SENSOR_DELAY value: 15
    Description: flow/radar message delay [ms]
  • name: INS_EKF2_MIN_FLOW_QUALITY value: 100
    Description: Minimum quality of the optical flow message accepted [0-255]
  • name: INS_EKF2_MAX_FLOW_RATE value: 20
    Description: Maximum flow rate the sensor can perceive [rad/sec]]
  • name: INS_EKF2_FLOW_NOISE value: 0.01
    Description: Flow sensor noise [rad/sec]
  • name: INS_EKF2_FLOW_NOISE_QMIN value: 0.03
    Description: Flow sensor noise when quality is minimum [rad/sec]
  • name: INS_EKF2_FLOW_INNOV_GATE value: 3
    Description: Flow sensor innovation gate [STD]
  • name: INS_EKF2_AGL_ID value: ABI_BROADCAST
    Description: ABI sensor ID used as input for AGL measurements
  • name: INS_EKF2_BARO_ID value: ABI_BROADCAST
    Description: ABI sensor ID used ad input for Barometric measurements
  • name: INS_EKF2_GYRO_ID value: ABI_BROADCAST
    Description: ABI sensor ID used as input for gyro measurements
  • name: INS_EKF2_ACCEL_ID value: ABI_BROADCAST
    Description: ABI sensor ID used ad input for acceleration measurements
  • name: INS_EKF2_MAG_ID value: ABI_BROADCAST
    Description: ABI sensor ID used as input for magnetic measurements
  • name: INS_EKF2_GPS_ID value: ABI_BROADCAST
    Description: ABI sensor ID used ad input for GPS measurements

Module functions

Init Functions

These initialization functions are called once on startup.

Periodic Functions

These functions are called periodically at the specified frequency from the module periodic loop.

  • ins_ekf2_update()
    • Running at maximum module frequency.
    • Autorun: TRUE
      Periodic function automatically starts after init.

Datalink Functions

Whenever the specified datalink message is received, the corresponing handler function is called.

  • on message EXTERNAL_POSE call ins_ekf2_parse_EXTERNAL_POSE(buf)
  • on message EXTERNAL_POSE_SMALL call ins_ekf2_parse_EXTERNAL_POSE_SMALL(buf)

Files

Header Files

The following headers are automatically included in modules.h

Source Files

  • modules/ins/ins.c
  • modules/ins/ins_ekf2.cpp
  • ecl/geo/geo.cpp
  • ecl/geo_lookup/geo_mag_declination.cpp
  • ecl/EKF/airspeed_fusion.cpp
  • ecl/EKF/control.cpp
  • ecl/EKF/mag_control.cpp
  • ecl/EKF/covariance.cpp
  • ecl/EKF/drag_fusion.cpp
  • ecl/EKF/ekf.cpp
  • ecl/EKF/ekf_helper.cpp
  • ecl/EKF/estimator_interface.cpp
  • ecl/EKF/gps_checks.cpp
  • ecl/EKF/mag_fusion.cpp
  • ecl/EKF/optflow_fusion.cpp
  • ecl/EKF/sideslip_fusion.cpp
  • ecl/EKF/terrain_estimator.cpp
  • ecl/EKF/vel_pos_fusion.cpp
  • ecl/EKF/gps_yaw_fusion.cpp
  • ecl/EKF/imu_down_sampler.cpp
  • ecl/EKF/EKFGSF_yaw.cpp
  • ecl/EKF/sensor_range_finder.cpp
  • ecl/EKF/utils.cpp

Raw ins_ekf2.xml file:

<!DOCTYPE module SYSTEM "module.dtd">
<module name="ins_ekf2" dir="ins" task="estimation">
<doc>
<description>
simple INS and AHRS using EKF2 from PX4
</description>
<define name="INS_EKF2_OPTITRACK" value="false" description="Easy configuration of full optitrack (position- and yaw fusion, height, init origin)"/>
<define name="INS_EKF2_FUSION_MODE" value="(MASK_USE_GPS)" description="The sensor that are used for position fusion"/>
<define name="INS_EKF2_VDIST_SENSOR_TYPE" value="VDIST_SENSOR_BARO" description="Primary sensor used for vertical distance"/>
<define name="INS_EKF2_GPS_CHECK_MASK" value="(MASK_GPS_NSATS | MASK_GPS_HACC | MASK_GPS_SACC)" description="GPS checks enabled before initialization of the global positioning"/>
<define name="INS_EKF2_EVP_NOISE" value="0.1" description="External vision position noise [m]"/>
<define name="INS_EKF2_EVV_NOISE" value="1.0" description="External vision velocity noise [m/s]"/>
<define name="INS_EKF2_EVA_NOISE" value="0.05" description="External vision angle noise [rad]"/>
<define name="INS_EKF2_GPS_V_NOISE" value="0.3" description="GPS measurement noise for horizontal velocity [m/s]"/>
<define name="INS_EKF2_GPS_P_NOISE" value="0.5" description="GPS measurement position noise [m]"/>
<define name="INS_EKF2_BARO_NOISE" value="3.5" description="Barometric measurement noise for altitude [m]"/>
<define name="INS_EKF2_IMU_POS_X" value="0" description="IMU X offset from CoG position [m]"/>
<define name="INS_EKF2_IMU_POS_Y" value="0" description="IMU Y offset from CoG position [m]"/>
<define name="INS_EKF2_IMU_POS_Z" value="0" description="IMU Z offset from CoG position [m]"/>
<define name="INS_EKF2_GPS_POS_X" value="0" description="GPS X offset from CoG position [m]"/>
<define name="INS_EKF2_GPS_POS_Y" value="0" description="GPS Y offset from CoG position [m]"/>
<define name="INS_EKF2_GPS_POS_Z" value="0" description="GPS Z offset from CoG position [m]"/>
<define name="INS_EKF2_FLOW_POS_X" value="0" description="Flow sensor X offset from CoG position [m]"/>
<define name="INS_EKF2_FLOW_POS_Y" value="0" description="Flow sensor Y offset from CoG position [m]"/>
<define name="INS_EKF2_FLOW_POS_Z" value="0" description="Flow sensor Z offset from CoG position [m]"/>
<define name="INS_EKF2_SONAR_MIN_RANGE" value="0.05" description="AGL sensor minimum range [m]"/>
<define name="INS_EKF2_SONAR_MAX_RANGE" value="3" description="AGL sensor maximum range [m]"/>
<define name="INS_EKF2_RANGE_MAIN_AGL" value="1" description="If enabled uses radar sensor as primary AGL source, if possible"/>
<define name="INS_EKF2_FLOW_SENSOR_DELAY" value="15" description="flow/radar message delay [ms]"/>
<define name="INS_EKF2_MIN_FLOW_QUALITY" value="100" description="Minimum quality of the optical flow message accepted [0-255]"/>
<define name="INS_EKF2_MAX_FLOW_RATE" value="20" description="Maximum flow rate the sensor can perceive [rad/sec]]"/>
<define name="INS_EKF2_FLOW_NOISE" value="0.01" description="Flow sensor noise [rad/sec]"/>
<define name="INS_EKF2_FLOW_NOISE_QMIN" value="0.03" description="Flow sensor noise when quality is minimum [rad/sec]"/>
<define name="INS_EKF2_FLOW_INNOV_GATE" value="3" description="Flow sensor innovation gate [STD]"/>
<define name="INS_EKF2_AGL_ID" value="ABI_BROADCAST" description="ABI sensor ID used as input for AGL measurements"/>
<define name="INS_EKF2_BARO_ID" value="ABI_BROADCAST" description="ABI sensor ID used ad input for Barometric measurements"/>
<define name="INS_EKF2_GYRO_ID" value="ABI_BROADCAST" description="ABI sensor ID used as input for gyro measurements"/>
<define name="INS_EKF2_ACCEL_ID" value="ABI_BROADCAST" description="ABI sensor ID used ad input for acceleration measurements"/>
<define name="INS_EKF2_MAG_ID" value="ABI_BROADCAST" description="ABI sensor ID used as input for magnetic measurements"/>
<define name="INS_EKF2_GPS_ID" value="ABI_BROADCAST" description="ABI sensor ID used ad input for GPS measurements"/>
</doc>
<settings>
<dl_settings NAME="INS">
<!-- EKF2 Configuration parameters -->
<dl_settings name="ekf2">
<dl_setting var="ekf2.qnh" min="500" step="0.1" max="1500" shortname="QNH"/>
<dl_setting var="ekf2.temp" min="-50" step="0.1" max="80" shortname="temperature"/>
<dl_setting var="ekf2.mag_fusion_type" min="0" step="1" max="5" shortname="mag_fusion" values="AUTO|HEADING|3D|AUTOFW|INDOOR|NONE" module="modules/ins/ins_ekf2" handler="change_param"/>
<dl_setting var="ekf2.fusion_mode" min="0" max="1" step="1" shortname="remove_gps" values="FALSE|TRUE" module="modules/ins/ins_ekf2" handler="remove_gps" type="bool"/>
</dl_settings>
</dl_settings>
</settings>
<dep>
<depends>@gps,@mag,@imu</depends>
<provides>ins,ahrs</provides>
</dep>
<header>
<file name="ins_ekf2.h"/>
</header>
<init fun="ins_ekf2_init()"/>
<periodic fun="ins_ekf2_update()" autorun="TRUE"/>
<datalink message="EXTERNAL_POSE" fun="ins_ekf2_parse_EXTERNAL_POSE(buf)"/>
<datalink message="EXTERNAL_POSE_SMALL" fun="ins_ekf2_parse_EXTERNAL_POSE_SMALL(buf)"/>
<makefile target="ap|nps">
<configure name="CXXSTANDARD" value="-std=c++14"/>
<flag name="CXXFLAGS" value="Wno-unused-but-set-variable"/>
<flag name="CXXFLAGS" value="Wno-unused-variable"/>
<!-- EKF2 files -->
<define name="INS_TYPE_H" value="modules/ins/ins_ekf2.h" type="string"/>
<file name="ins.c"/>
<file name="ins_ekf2.cpp"/>
<!-- Include the ecl and matrix libraries from ext -->
<include name="$(PAPARAZZI_SRC)/sw/ext/ecl/"/>
<include name="$(PAPARAZZI_SRC)/sw/ext/matrix/"/>
<define name="__PAPARAZZI" value="TRUE"/>
<define name="ECL_STANDALONE" value="TRUE"/>
<define name="IMU_INTEGRATION" value="TRUE"/> <!-- Needed to enable IMU integration -->
<define name="USE_ALT_LLA_WAYPOINTS" value="TRUE"/>
<!-- Compile needed ecl files -->
<file name="geo.cpp" dir="ecl/geo"/>
<file name="geo_mag_declination.cpp" dir="ecl/geo_lookup"/>
<file name="airspeed_fusion.cpp" dir="ecl/EKF"/>
<file name="control.cpp" dir="ecl/EKF"/>
<file name="mag_control.cpp" dir="ecl/EKF"/>
<file name="covariance.cpp" dir="ecl/EKF"/>
<file name="drag_fusion.cpp" dir="ecl/EKF"/>
<file name="ekf.cpp" dir="ecl/EKF"/>
<file name="ekf_helper.cpp" dir="ecl/EKF"/>
<file name="estimator_interface.cpp" dir="ecl/EKF"/>
<file name="gps_checks.cpp" dir="ecl/EKF"/>
<file name="mag_fusion.cpp" dir="ecl/EKF"/>
<file name="optflow_fusion.cpp" dir="ecl/EKF"/>
<file name="sideslip_fusion.cpp" dir="ecl/EKF"/>
<file name="terrain_estimator.cpp" dir="ecl/EKF"/>
<file name="vel_pos_fusion.cpp" dir="ecl/EKF"/>
<file name="gps_yaw_fusion.cpp" dir="ecl/EKF"/>
<file name="imu_down_sampler.cpp" dir="ecl/EKF"/>
<file name="EKFGSF_yaw.cpp" dir="ecl/EKF"/>
<file name="sensor_range_finder.cpp" dir="ecl/EKF"/>
<file name="utils.cpp" dir="ecl/EKF"/>
</makefile>
</module>