开源项目 Open Source

6-Axis AHRS

强大的六轴姿态航向参考系统 | 基于 Madgwick 融合算法与扩展卡尔曼滤波器

Robust 6-Axis Attitude and Heading Reference System | Madgwick Fusion & Extended Kalman Filter

Madgwick EKF ESP32 STM32
2
算法版本
Algorithms
6+
高级特性
Advanced Features
2
硬件平台
Hardware Platforms
MIT
开源协议
License

核心特性 Core Features

🎯

Madgwick 融合算法

Madgwick Fusion

基于 Sebastian Madgwick 博士论文,实现稳定可靠的四元数姿态估计

Based on Sebastian Madgwick's PhD thesis, stable quaternion-based attitude estimation

📡

Extended Kalman Filter

6状态 EKF,估计四元数和陀螺仪偏置,自适应滤波

6-state EKF estimates quaternion and gyro bias with adaptive filtering

冲击检测与恢复

Impact Detection & Recovery

检测高加速度事件,快速恢复姿态,适应机器人对抗场景

Detects high-acceleration events, rapid attitude recovery for robot competitions

📏

线性运动补偿

Linear Motion Compensation

检测并补偿线性加速度干扰,提高动态环境下精度

Detects and compensates linear acceleration interference in dynamic environments

🌊

浮沉估计 (Heave)

Heave Estimation

估计垂直方向的位移和速度,适用于船舶、平台稳定

Estimates vertical displacement and velocity for ship/platform stabilization

🔊

噪声分析

Noise Analysis

实时分析加速度计和陀螺仪噪声特性,动态调整滤波参数

Real-time noise analysis of IMU sensors, dynamic filter parameter adjustment

EKF 高级特性详解 EKF Advanced Features

运动状态检测 Motion State Detection

Motion State Detection

系统实时检测设备的三种运动状态:静止(STATIC)、稳定(STABLE)、动态(DYNAMIC),并根据状态自适应调整滤波器参数。

The system detects three motion states in real-time: STATIC, STABLE, and DYNAMIC, adaptively adjusting filter parameters based on the detected state.

01
IMU Data
02
噪声统计
Noise Stats
03
状态判断
State Decision
04
参数调整
Param Adjust
状态 State 描述 Description Acc Weight
STATIC 完全静止 Completely still 80-100%
STABLE 轻微运动 Slight motion 40-60%
DYNAMIC 剧烈运动 Intense motion 10-30%

冲击检测与恢复 Impact Detection & Recovery

Impact Detection & Recovery

检测机器人碰撞、跌落等高加速度事件,快速恢复姿态估计。适用于 RoboMaster 等对抗性机器人比赛。

Detects high-acceleration events like robot collisions and falls, rapidly recovering attitude estimation. Ideal for competitive robot competitions like RoboMaster.

Parameter 默认值 Default 描述 Description
impactAccThreshold 0.5g 加速度变化阈值 Acceleration change threshold
impactGyroThreshold 100°/s 角速度变化阈值 Gyro rate change threshold
impactRecoveryDuration 0.5s 恢复时间 Recovery duration
accWeightImpact 5% 冲击时加速度权重 Accel weight during impact

浮沉估计 Heave Estimation

Heave Estimation

通过高频滤波和偏置估计,实时估计设备在垂直方向的位移和速度。广泛应用于船舶稳定、平台姿态控制。

Real-time estimation of vertical displacement and velocity using high-pass filtering and bias estimation. Widely used in ship stabilization and platform attitude control.

C
// 获取浮沉估计结果
float heavePos = sys.heavePosition;  // 垂直位移 (m)
float heaveVel = sys.heaveVelocity;  // 垂直速度 (m/s)

// 初始化时设置截止频率
Tactical_Init(&sys, 100.0f, 0.1f);
                                //              ↑ 采样率  ↑ 浮沉截止频率

噪声分析 Noise Analysis

Noise Analysis

实时统计加速度计和陀螺仪的噪声特性(均值、方差),动态调整 EKF 的过程噪声和观测噪声参数,实现最优滤波效果。

Real-time statistics of IMU noise characteristics (mean, variance), dynamically adjusting EKF process and observation noise parameters for optimal filtering.

Field 描述 Description
accNoise 加速度计噪声估计 Accelerometer noise estimate
gyroNoise 陀螺仪噪声估计 Gyroscope noise estimate
accMagVar 加速度模值方差 Acceleration magnitude variance
gyroMagVar 陀螺仪模值方差 Gyroscope magnitude variance

版本选择 Version Selection

optimized_mcu
C语言风格,深度优化版本,适合资源受限的嵌入式系统
C-style, highly optimized for resource-constrained embedded systems
  • 极低的内存占用
  • Ultra low memory footprint
  • STM32 / ESP32
  • Madgwick 算法
  • Madgwick algorithm
readable_cpp
现代 C++17 实现,代码可读性好,适合学习
Modern C++17 OOP, great for learning
  • 清晰的类结构
  • Clear class structure
  • 详细的注释
  • Detailed comments
  • 适合教学研究
  • Great for teaching

快速使用 Quick Start

C / C++
// EKF Version - Recommended for high precision
#include "Tactical_Fusion.h"

TacticalSystem sys;

void main() {
    // Initialize: 100Hz sample rate, 0.1Hz heave cutoff
    Tactical_Init(&sys, 100.0f, 0.1f);

    while (1) {
        // Gyroscope data: deg/s
        FusionVector gyro = {gx, gy, gz};
        // Accelerometer data: g
        FusionVector acc = {ax, ay, az};

        // Update attitude estimation
        Tactical_Update(&sys, gyro, acc);

        // Get quaternion
        FusionQuaternion q = sys.quaternion;

        // Get Euler angles
        FusionEuler euler = FusionQuaternionToEuler(q);

        // Get heave (vertical motion)
        float heave = sys.heavePosition;
    }
}

应用场景 Applications

🤖

RoboMaster

东北大学 T-DT Lab 用于 2024 赛季超级对抗赛

T-DT Lab, NEU - Super Challenge 2024 Season

🚁

无人机

UAV

四轴/六轴飞行器的实时姿态估计

Real-time attitude estimation for quadcopters

🎮

VR/AR

低延迟头部姿态捕捉

Low-latency head tracking

🚢

船舶稳定

Ship Stabilization

浮沉估计用于船舶姿态控制

Heave estimation for ship motion control