M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
fusion.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_IMU_IMU_FILTER_FUSION_HPP
11#define M5_UNIT_IMU_IMU_FILTER_FUSION_HPP
12
13#include "filter_base.hpp"
14
15// The vendored sources are plain C (see src/imu/filter/third_party/fusion, MIT license,
16// unmodified from https://github.com/xioTechnologies/Fusion) and FusionAhrs.h itself has
17// no extern "C" guard of its own, so this adapter supplies one at the include site to
18// give FusionAhrs.c's symbols C linkage when called from this C++ translation unit.
19extern "C" {
20#include "third_party/fusion/FusionAhrs.h"
21}
22
23namespace m5 {
24namespace imu {
25
63public:
65
66 virtual void reset() override;
67 virtual void update(const float dt, const float accel[3], const float gyro[3], const float* mag) override;
68 virtual void quaternion(float& w, float& x, float& y, float& z) const override;
69
77 bool writeGain(const float gain);
79 inline float readGain() const
80 {
81 return _settings.gain;
82 }
83
92 bool startupInProgress() const;
93
105 bool writeQuaternion(const float w, const float x, const float y, const float z);
106
107private:
108 ::FusionAhrsSettings _settings{}; // Cached settings (Fusion keeps its own copy internally too)
109 ::FusionAhrs _ahrs{}; // Fusion's AHRS state (quaternion + internal feedback state)
110};
111
112} // namespace imu
113} // namespace m5
114#endif
Framework-independent contract shared by every AHRS attitude filter.
Definition filter_base.hpp:81
Adapter around the vendored x-io Fusion AHRS algorithm (x-io Technologies, MIT license; see src/imu/f...
Definition fusion.hpp:62
virtual void reset() override
Reset the internal attitude estimate (and any filter state) to identity.
Definition fusion.cpp:31
bool writeGain(const float gain)
Set the AHRS feedback gain (FusionAhrsSettings.gain)
Definition fusion.cpp:84
virtual void update(const float dt, const float accel[3], const float gyro[3], const float *mag) override
Fuse one IMU sample into the attitude estimate.
Definition fusion.cpp:38
virtual void quaternion(float &w, float &x, float &y, float &z) const override
Current fused attitude.
Definition fusion.cpp:70
bool startupInProgress() const
Whether Fusion's startup ramp is still in progress.
Definition fusion.cpp:79
bool writeQuaternion(const float w, const float x, const float y, const float z)
Overwrite the current attitude estimate directly.
Definition fusion.cpp:94
float readGain() const
Current feedback gain.
Definition fusion.hpp:79
Common contract for AHRS attitude filters.
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26