INSLIB README

项目的 README,来自 github.com/jnz/INSLIB。合并为一个 markdown 文件:README.md。

INSLIB

CI codecov Release License: AGPL-3.0 C11

INSLIB Logo

A portable C library for 3D navigation state estimation. Mail: [email protected]

In action, fusing IMU measurements with Galileo HAS-corrected GPS/GNSS inputs:

Galileo HAS

Test coverage of the core library (src/):

Metric Coverage
C0 (Line) 99.4% (4688/4714)
C1 (Branch) 91.7% (3100/3379)
MC/DC 91.6% (3073/3354)

Worst-case stack usage in bytes, deepest call chain including KFCore and the C library, from static analysis (make stack):

Entry point x86_64-linux-gnu, GCC 14.2.0
nav_suite_update() 13184
ins_update() 11776
ahrs_update() 8240
baro_alt_update() 7936
nav_suite_init() 3792
ins_init() 3776

Example Video

Dead Reckoning

Example video of pure inertial tracking with a TDK ICM-45686 low-cost Inertial Measurement Unit (IMU)

Overview

INSLIB is a portable C library for 3D navigation state estimation. Its core is a set of Kalman filters fusing measurements from an inertial measurement unit (IMU) with GNSS/GPS measurements, barometer, magnetometer, local position references, absolute yaw references (GNSS compassing), scalar ground speed (wheel thicks) and zero-velocity / zero-rotation information.

Typical use cases:

The core library is written in pure C (C11), has no external dependencies and is optimized for embedded microcontrollers. A useful collection of Python helper programs and GUI apps are included in this repository. The Python binding is on PyPI: pip install inslib (see the Python tutorial).

Features

Post Processing Quickstart

Post processing GUI screenshot

inspostgui.py is a GUI to post-process measurements: open a dataset's config YAML (contains filter settings and points to the .csv files), tweak its settings, and replay it. A forward-/backward smoothing can be done in post-processing to improve the solution quality ("RTS smoother").

Windows, no Python needed: download inspostgui-<version>-windows-x64.zip from the latest release, unzip it (keep the folder together) and start inspostgui.exe. Windows may show a SmartScreen warning, the code is not signed. Otherwise run the Python source directly:

sh python/setup_venv.sh               # one-time (also runs `make pylib`)
. env.sh                              # activate the venv (POSIX/git-bash, any OS)
python3 tools/inspostgui.py datasets/fog

.csv Data Format

The input format is plain CSV, one file per sensor. First item is a common t_us timestamp in microseconds. IMU (gyroscope and accelerometer) example in the Front/Right/Down (FRD) body coordinate system:

# t_us, gyr_frd_x[rad/s], gyr_frd_y[rad/s], gyr_frd_z[rad/s], acc_frd_x[m/s^2], acc_frd_y[m/s^2], acc_frd_z[m/s^2]
0,      -0.0016,          0.0000,           -0.0003,          -0.1149,          0.1915,           -9.8450
5000,   -0.0014,          0.0020,           -0.0001,          -0.1231,          0.2316,           -9.8221
10000,  -0.0003,         -0.0003,            0.0008,          -0.0862,          0.2490,           -9.7588

Body frame FRD with rotation directions

GNSS/magnetometer/barometer/speed .csv files follow the same pattern. Example files:

config.yaml

A dataset directory with CSV files contains a configuration file (config.yaml) that tells the filter how to run, which modes are active, tuning settings and options. Two examples to start from: doc/example_conf/config_basic.yaml (GNSS+IMU+baro+mag) and doc/example_conf/config_local_inertial.yaml (GNSS-free, pure inertial dead-reckoning). The keys are documented in doc/INSLIB_manual.pdf, section "Dataset configuration: config.yaml".

replay.py Command Line Post-Processing Version

replay.py is the command line (CLI) version of the inspostgui.py Python GUI above.

sh python/setup_venv.sh               # one-time (also runs `make pylib`)
. env.sh                              # activate the venv (POSIX/git-bash, any OS)
python3 tools/replay.py datasets/fog --plot --plot-out /tmp/plots.pdf

Example PDF plot output from replay.py:

PDF Plots

Google Earth .kml output is also possible with --kml output.kml.

Google Earth KML/KMZ Output

GNSS Latency Estimation

GNSS Latency Estimation

GNSS receivers report data with some latency (transmission, internal processing, filtering) but this is receiver and configuration dependent. inspostgui.py and replay.py measure the real value for a specific configuration: IMU + barometric altitude has near-zero latency, cross-correlating its vertical velocity against the GNSS-reported vertical velocity around a real climb/descent results in a lag with a sharp correlation peak (see the plot above).

Example for a u-blox X20P receiver delay estimation:

python3 tools/replay.py datasets/pedestrian/07_outdoor_only/ --estimate-gnss-delay

Live Data Quickstart

Live data flow

insrcv listens for UDP packets with sensor measurements. This custom packet format (extending the UBX format) is documented in tools/inslib_protocol.md. Any process that sends this protocol format can feed it on UDP port 29800 (default). Output goes to PlotJuggler (UDP :9870, JSON) and optionally in MAVLink format (UDP :14550).

make insrcv
./build/insrcv --mavlink   # run and wait for UDP sensor input

Tutorials

Documentation

GNSS inputs

Supported sensors

Real world data sets

(Not all datasets have an absolute ground truth available, e.g. the ArduPilot dataset is comparing the INSLIB solution with the ArduPilot solution)

INSLIB benchmark and validation

The measurements of the KF-GINS authors (awesome-gins-datasets) with five different IMUs and a ground truth is used.

IMU Description Vendor Gyro Bias Instability [°/h]
ICM20602 consumer-grade chip TDK / InvenSense 10.0
ADIS16460 industrial-grade module Analog Devices 8.0
ADIS16465 industrial-grade module Analog Devices 2.0
HGuide-i300 industrial-grade module Honeywell 3.0
Leador A15 navigation-grade FOG IMU Leador 0.03

The car trajectory with those five IMUs and RTK-GNSS positions and a ground truth, processed by INSLIB and by KF-GINS (commit 8291a93) are compared.

Error RMS vs. ground truth: INSLIB / KF-GINS (smaller is better):

IMU Horizontal [m] (INSLIB / KF-GINS) Vertical [m] (INSLIB / KF-GINS) Roll [°] (INSLIB / KF-GINS) Pitch [°] (INSLIB / KF-GINS) Yaw [°] (INSLIB / KF-GINS)
ICM20602 0.019m / 0.020m 0.063m / 0.058m 0.024° / 0.032° 0.025° / 0.026° 0.179° / 0.182°
ADIS16460 0.021m / 0.031m 0.029m / 0.031m 0.027° / 0.046° 0.051° / 0.099° 0.219° / 0.241°
ADIS16465 0.017m / 0.017m 0.024m / 0.026m 0.014° / 0.014° 0.015° / 0.013° 0.106° / 0.089°
i300 0.016m / 0.017m 0.030m / 0.028m 0.012° / 0.011° 0.012° / 0.011° 0.068° / 0.070°
Leador A15 0.009m / 0.012m 0.009m / 0.009m 0.001° / 0.001° 0.001° / 0.001° 0.016° / 0.018°

Results from INSLIB v1.3.0. The Leador A15 dataset is part of this repository (datasets/kfgins). The other trials are not in the repo, but the INSLIB config.yaml and the respective KF-GINS kf-gins.yaml are in the subdirectories of datasets/kfgins for replication.

INSLIB and ArduPilot EKF3

To also test EKF3 from ArduPilot, the same awesome-gins-datasets are used but with a synthetic GNSS velocity added (ArduPilot's EKF3 requires a GNSS velocity to work). EKF3 is ArduPilot 4.8.0-dev (6fb4ba5185) through its log replay tool, configured as ground vehicle with the Rover parameters, with GPS height and velocity and no magnetometer. Yaw source is none (EK3_SRC1_YAW=0), the EKF3 GSF yaw estimator submodule is used to align yaw in EKF3.

Error RMS vs. ground truth, horizontal [m] / yaw [°], smaller is better:

IMU INSLIB KF-GINS ArduPilot EKF3
ICM20602 0.019m / 0.177° 0.020m / 0.182° 0.078m / 0.951°
ADIS16460 0.021m / 0.220° 0.031m / 0.241° 0.064m / 0.305°
ADIS16465 0.017m / 0.106° 0.017m / 0.089° 0.066m / 0.788°
i300 0.016m / 0.068° 0.017m / 0.070° 0.067m / 0.232°
Leador A15 (FOG) 0.009m / 0.016° 0.012m / 0.018° 0.060m / 0.148°

GNSS/IMU fusion accuracy: horizontal and yaw RMS error vs. ground truth for INSLIB, KF-GINS and ArduPilot EKF3

Roll / pitch error RMS [°] of the same runs (smaller is better):

IMU INSLIB KF-GINS ArduPilot EKF3
ICM20602 0.024° / 0.025° 0.032° / 0.026° 0.073° / 0.082°
ADIS16460 0.027° / 0.050° 0.046° / 0.099° 0.049° / 0.055°
ADIS16465 0.014° / 0.016° 0.014° / 0.013° 0.055° / 0.068°
i300 0.012° / 0.012° 0.011° / 0.011° 0.056° / 0.034°
Leador A15 (FOG) 0.001° / 0.001° 0.001° / 0.001° 0.078° / 0.048°

With simulated GNSS outages of 60 s every 300 s. 3D position error when GNSS returns, mean / max over the outages (smaller is better):

IMU INSLIB INSLIB + NHC¹ KF-GINS ArduPilot EKF3
ICM20602 56.9m / 152m 9.9m / 16.4m 55.2m / 149m 69.5m / 156m
ADIS16460 12.2m / 25.1m 6.4m / 16.0m 18.6m / 27.5m 14.5m / 23.2m
ADIS16465 8.5m / 13.3m 3.2m / 5.7m 8.0m / 14.1m 11.4m / 28.9m
i300 5.5m / 6.6m 3.6m / 4.3m 4.4m / 7.3m 11.7m / 21.1m
Leador A15 0.70m / 1.11m 1.46m / 7.16m 0.58m / 0.87m 15.6m / 39.2m

¹ Enabled non-holonomic (NHC) automotive lateral constraint (automotive_lateral_constraint).

INSLIB with faulty GNSS measurements

The following comparison is injecting faults into GNSS measurements: one fault type per run, the same errors are applied for every filter. INSLIB runs with its default outlier handling (chi2 on) and for comparison without it. KF-GINS fuses every fix, EKF3 has its innovation gates and GPS glitch reset.

The runs are the five car trials from above (all five IMUs). Mean error over all events of all five IMUs / median time until the error stays below 0.3 m again (smaller is better):

Fault INSLIB INSLIB, no outlier test KF-GINS EKF3
spike: single fixes 5 to 50 m off 0.068m / 0.0s 38.9m / 21.0s 29.7m / > 30s 0.726m / 1.1s
multipath: 3 to 15 m for 5 to 30 s, 1 m reported 1.94m / 7.0s 4.81m / 9.0s 6.79m / 1.0s 11.0m / 21.1s
degraded: 1 m noise for 30 s, honestly reported 0.688m / 4.0s 0.688m / 4.0s 0.940m / 1.0s 1.67m / 3.7s
gross: 2 or 3 single fixes 500 m off within 30 s 0.071m / 0.0s 534m / > 30s 493m / > 30s 9.48m / 0.0s

GNSS outlier handling: mean position error for single fixes 5 to 50 m off and for 2 to 3 fixes 500 m off, INSLIB vs. KF-GINS and ArduPilot EKF3

Setup

This repository uses the KFCore git submodule. Clone it recursively:

git clone --recursive <repo-url>

If you already cloned without --recursive, fetch the submodule with:

git submodule update --init --recursive

The core C library only needs a C11 compiler and make (see Quickstart above). The Python bindings, plotting and reference-board tools additionally need a virtual environment:

sh python/setup_venv.sh      # one-time (Windows: python\setup_venv.bat)
. env.sh                     # activate the venv (POSIX/git-bash, any OS)

make check-all (see coding_style.md) additionally wants clang-format, cppcheck, clang-tidy, lcov and doxygen.

Integration: Required Source Files

INSLIB has no build system requirement. Just add the files you need to your project. All files are portable without dependencies.

Which variant do I need?

Variant What it does Inputs Outputs Pick it if
ARS (ahrs.c, AHRS_MODE_ARS) 5-state roll/pitch filter. Yaw is only integrated from the gyro and drifts (directional gyro) IMU roll, pitch, free-running yaw, gyro bias You only need the horizon (e.g. stabilization), no absolute heading, no magnetometer
AHRS (ahrs.c, AHRS_MODE_AHRS) 6-state roll/pitch/yaw filter, yaw stabilized by the magnetometer (true north via the built-in WMM once a position is given) IMU, magnetometer roll, pitch, yaw, gyro bias You need a drift-free heading but no position or velocity
INS (ins.c) Full 15-state error-state Kalman filter (18 with magnetometer hard-iron bias) IMU plus any of GNSS, magnetometer, barometer, local position, GNSS compass, ground speed position, velocity, attitude, sensor biases You need a 3D navigation solution
baro_alt (baro_alt.c) 3-state barometer/accelerometer vertical filter (height, vertical velocity, accel correction), plus a 1-state baro/GNSS height offset filter accelerometer, barometer, attitude from any source smooth height, vertical velocity You only need a good altitude and climb rate, or want it to keep working during a GNSS outage
nav_suite (nav_suite.c) Wrapper running INS, ARS, AHRS and baro_alt in parallel from one measurement stream. Arbitrates the best attitude and height source and aligns the vertical datum everything above everything above, always the best available one You want the full system and no manual glue code
File Full suite INS only ARS only AHRS baro_alt only
src/nav_suite.c/.h x
src/ins.c/.h x x
src/ahrs.c/.h x x x
src/baro_alt.c/.h x x
src/magnetic_model.c/.h x x x
src/wmm_lut.h x x x
src/geodetic_toolbox.c/.h x x x x x
src/sensor_defaults.h x x x x x
KFCore/c/kalman_udu.c/.h x x x x x
KFCore/c/linalg.c/.h x x x x x
KFCore/c/miniblas.c/.h x x x x x
src/log.c/.h x x x x x

Notes:

Directory Structure

📂 inslib/
├── Makefile              # Build: make test, make insrcv, ...
├── src/                  # Core library (.c/.h)
│   └── nav_suite.h       # Main header: INS + AHRS + baro_alt wrapper
├── KFCore/               # Submodule: linear algebra, Kalman UDU filter
├── tests/                # Unit/integration tests
├── datasets/             # Real-world + simulated replay datasets
├── tools/                # Command line programs: insrcv, replay (C and Python), post-processing GUI, calibration, receiver setup, protocol
├── python/               # Python package INSLIB (ctypes binding) and its tests
├── magneticmodel/        # WMM lookup table
├── doc/                  # Documentation, Doxygen, images
└── tutorial/             # Minimal C + Python usage examples

Library Architecture Block Diagram

Block diagram

Reference Hardware

The live receiver insrcv (tools/) speaks an open (UBX-based) protocol, documented in tools/inslib_protocol.md.

The reference board is a low-cost and ready-to-use development module (IMU, u-blox GNSS receiver, magnetometer, barometer) for running INSLIB on real hardware with pre-calibrated sensors. It implements the protocol above and is ready to use out of the box. Its firmware and the host tools that come with it (serial hub, control GUI, configuration, calibration window) are not public, get in touch if you're interested in a collaboration with my university institute or in getting a unit.

Image of reference hardware

Building your own sensor suite is also possible, an example conf (2026/2027 sensor landscape):

Sensor Example part Notes
IMU TDK InvenSense ICM-45686, Bosch BMI563/BMI570, Analog Devices ADIS16505 or Murata SCH16T-K10
Magnetometer MEMSIC MMC5603NJ or ST LIS3MDL
Barometer Bosch BMP581 or TE MS5611
GNSS receiver u-blox F9P or X20 X20-series has L1/L2/L5 support and Galileo HAS decoding

Reference Board Calibration GUI

Calibration GUI

IMU/Magnetometer-Calibration + Housing-Alignment, user-friendly GUI for the reference board. The GUI allows an easy calibration of the sensor hardware for bias, scale and misalignment without the need for an expensive calibration environment like robotic arms, except for a controlled temperature environment. The sensor must be placed still for a few seconds in a variety of different orientations on a stable surface:

Calibration

Sensor Management GUI

Live-Control center for reference INS board

Screenshot

Screenshot 2

Command Line Tools

Common Pitfalls

IMU sensor processing is unforgiving: it is not enough to get one thing right, the whole chain (timestamps, axis conventions, calibration, filtering, etc.) has to line up properly. A list of common mistakes:

AI Use

References

Citation

If you use INSLIB in academic work, please cite it (see CITATION.cff, also picked up by GitHub's "Cite this repository" button):

@software{zwiener_inslib,
  author = {Zwiener, Jan},
  title  = {{INSLIB: A Portable C Library for 3D Navigation State Estimation}},
  url    = {https://github.com/jnz/INSLIB},
  year   = {2026}
}

INSLIB (jnz/INSLIB)

正在搜索数据库…

这是什么?INSLIB 是一个可移植的 C 语言库,用于 3D 导航状态估计,通过卡尔曼滤波将 IMU 数据与 GNSS/GPS、气压计、磁力计等传感器融合,应用于无人机、机器人、汽车和航空航天项目。
这是开箱即用的应用还是需要编译进我自己项目的库?它是一个纯 C11 库,无堆分配、无操作系统依赖、无外部依赖,适合编译进固件或桌面程序;同时附带用于后处理和标定的 Python 辅助脚本和 GUI 应用。
怎么把它跑起来?用 C11 编译器和 make 构建核心库,然后用 inspostgui.py 图形界面或 replay.py 命令行工具,处理由各传感器 CSV 文件和一个 config.yaml 组成的数据集。
使用这些工具需要安装 Python 吗?核心 C 库本身零依赖,但 Python 绑定、绘图工具和参考板卡工具需要 Python 虚拟环境。
接传感器时最大的坑是什么?IMU 处理毫不留情:未标定的磁力计、不匹配的坐标系、非单调的时间戳,或未设置的 GNSS 天线杆臂,都会悄悄破坏解算结果;README 列出了十几条这类常见错误。
它只能在单片机上运行,还是也能在桌面上运行?两者都可以——代码没有操作系统依赖,也没有堆分配,因此既能跑在裸机嵌入式目标上,也能跑在普通台式电脑上,并使用 32 位浮点运算来避免对双精度 FPU 的需求。
用这个库 GNSS 定位精度能达到多少?通过 NTRIP/RTCM 使用 RTK 可以达到约 1 厘米精度,u-blox SPARTN/PointPerfect 能达到 3-6 厘米,而在兼容的 u-blox X20 接收机上,Galileo HAS 无需任何改正订阅就能达到 10 厘米以内的精度。
代码是 AI 写的吗?不是,核心库和 KFCore 滤波器由一位在该领域有 20 年经验的工程师设计和编写;只有部分文档看起来涉及 AI 辅助。
它支持哪些传感器和数据输入?它融合 IMU 加速度计/陀螺仪数据、GNSS/GPS 接收机、双天线 GNSS 罗盘、磁力计、气压计、动作捕捉系统、OBD-II 里程计和零速/零转检测器,可通过 UDP 接收实时数据或读取录制的 CSV 日志。
我可以用真实的飞行或行车数据来验证结果吗?可以,仓库链接了真实世界的数据集(带动捕真值的 Crazyflie 无人机、旋翼机 MEMS 与 FOG 对比、汽车 GNSS 中断日志、行人试验),以及与 ArduPilot 的 EKF3、武汉大学的 kfgins 和 MATLAB Navigation Toolbox 的对比。
作者
jnz
大小
136.4 MB
星标
677
时长
2个月
提交 · 90 天