18#ifndef M5_UNIT_IMU_IMU_AHRS_IMU_HPP
19#define M5_UNIT_IMU_IMU_AHRS_IMU_HPP
93 inline bool getAccel(
float*
const ax,
float*
const ay,
float*
const az)
const
115 inline bool getGyro(
float*
const gx,
float*
const gy,
float*
const gz)
const
137 inline bool getMag(
float*
const mx,
float*
const my,
float*
const mz)
const
173 if (data ==
nullptr) {
178 data->accel.x = s.
accel[0];
179 data->accel.y = s.
accel[1];
180 data->accel.z = s.
accel[2];
181 data->gyro.x = s.
gyro[0];
182 data->gyro.y = s.
gyro[1];
183 data->gyro.z = s.
gyro[2];
184 data->mag.x = s.
mag[0];
185 data->mag.y = s.
mag[1];
186 data->mag.z = s.
mag[2];
208 inline void getAhrsData(
float*
const pitch,
float*
const roll,
float*
const yaw)
const
210 float roll_deg{}, pitch_deg{}, yaw_deg{};
211 euler(roll_deg, pitch_deg, yaw_deg);
212 if (pitch !=
nullptr) {
215 if (roll !=
nullptr) {
218 if (yaw !=
nullptr) {
224 inline bool getAccelData(
float*
const ax,
float*
const ay,
float*
const az)
const
230 inline bool getGyroData(
float*
const gx,
float*
const gy,
float*
const gz)
const
236 inline bool getGyroMag(
float*
const mx,
float*
const my,
float*
const mz)
const
238 return getMag(mx, my, mz);
257 inline void setCalibration(
const uint8_t accel_strength,
const uint8_t gyro_strength,
const uint8_t mag_strength)
285 const uint8_t idx[3] = {
286 static_cast<uint8_t
>(axis0 >> 1),
287 static_cast<uint8_t
>(axis1 >> 1),
288 static_cast<uint8_t
>(axis2 >> 1),
290 if (idx[0] > 2 || idx[1] > 2 || idx[2] > 2 || idx[0] == idx[1] || idx[1] == idx[2] || idx[0] == idx[2]) {
311 return setAxisOrder(axis0, axis1, getAxis2(axis0, axis1));
331 uint8_t axis2 =
static_cast<uint8_t
>(((1 << (axis0 >> 1)) | (1 << (axis1 >> 1))) ^ 0x07);
332 axis2 =
static_cast<uint8_t
>(axis2 & 0x06);
333 const uint8_t ax0 = axis2 ?
static_cast<uint8_t
>(axis2 - 2) : 4;
334 axis2 =
static_cast<uint8_t
>(axis2 + (((axis0 & 0x06) == ax0) == ((axis0 & 1) == (axis1 & 1))));
335 return static_cast<axis_t>(axis2);
338 imu_data_t _compat_data{};
Layer-2 AHRS controller: merges IMUDataSource capabilities and drives an AhrsFilterBase.
AxisPermutation permutation_from_indices(const uint8_t(&p)[3])
Map a source-axis index triplet back to an AxisPermutation.
Definition axis_order.hpp:123
Merges up to 4 IMUDataSource instances by capability and fuses their samples into an attitude estimat...
Definition ahrs_controller.hpp:58
bool hasAccel() const
Whether an accelerometer source has been registered (see add())
Definition ahrs_controller.hpp:367
unsigned long lastMicros() const
Microsecond timestamp of the most recent self-clocked update()
Definition ahrs_controller.hpp:401
void writeAutoCalibration(const uint8_t accel, const uint8_t gyro, const uint8_t mag)
Enable/disable continuous background auto-calibration per capability.
Definition ahrs_controller.cpp:271
const imu_physical_data_t & latest() const
Most recently fused physical-unit sample.
Definition ahrs_controller.hpp:361
bool hasGyro() const
Whether a gyroscope source has been registered (see add())
Definition ahrs_controller.hpp:373
bool writeCalibration(const calibration_data_t &data)
Overwrite every capability's auto-calibration offset from a snapshot.
Definition ahrs_controller.cpp:363
void euler(float &roll_deg, float &pitch_deg, float &yaw_deg) const
Current fused attitude as aerospace ZYX Euler angles.
Definition ahrs_controller.cpp:446
bool hasTemp() const
Whether a temperature source has been registered (see add())
Definition ahrs_controller.hpp:379
void writeUserAxisOrder(const AxisOrder &order)
Set a global user axis remap composed on top of every source's fixed order.
Definition ahrs_controller.cpp:223
bool hasValidMag() const
Whether at least one valid magnetometer sample has been seen.
Definition ahrs_controller.hpp:390
AhrsController plus an M5Unified IMU_Class-compatible API.
Definition ahrs_imu.hpp:38
const imu_data_t & getImuData()
Latest accel/gyro/mag sample, by const reference.
Definition ahrs_imu.hpp:193
bool isEnabled() const
Whether accelerometer and gyroscope sources are both registered.
Definition ahrs_imu.hpp:245
void clearOffsetData()
Zero every capability's auto-calibration offset.
Definition ahrs_imu.hpp:268
void setCalibration(const uint8_t accel_strength, const uint8_t gyro_strength, const uint8_t mag_strength)
Set per-capability auto-calibration strength (0 = off, 1-255 = adjustment speed)
Definition ahrs_imu.hpp:257
bool getTemp(float *const t) const
Latest temperature reading (degC)
Definition ahrs_imu.hpp:157
void getImuData(imu_data_t *const data) const
Copy the latest accel/gyro/mag sample into an imu_data_t.
Definition ahrs_imu.hpp:171
bool getGyro(float *const gx, float *const gy, float *const gz) const
Latest gyroscope reading (dps)
Definition ahrs_imu.hpp:115
bool getAccel(float *const ax, float *const ay, float *const az) const
Latest accelerometer reading (G)
Definition ahrs_imu.hpp:93
bool setAxisOrder(const axis_t axis0, const axis_t axis1, const axis_t axis2)
Assign which signed source axis feeds each output slot.
Definition ahrs_imu.hpp:283
void getAhrsData(float *const pitch, float *const roll, float *const yaw) const
Current fused attitude as aerospace Euler angles (degrees)
Definition ahrs_imu.hpp:208
bool getMag(float *const mx, float *const my, float *const mz) const
Latest magnetometer reading (uT)
Definition ahrs_imu.hpp:137
bool setAxisOrderRightHanded(const axis_t axis0, const axis_t axis1)
Assign the first two output axes; derive the third as a right-handed frame.
Definition ahrs_imu.hpp:309
bool getAccelData(float *const ax, float *const ay, float *const az) const
Alias for getAccel()
Definition ahrs_imu.hpp:224
bool setAxisOrderLeftHanded(const axis_t axis0, const axis_t axis1)
Assign the first two output axes; derive the third as a left-handed frame.
Definition ahrs_imu.hpp:322
bool getGyroData(float *const gx, float *const gy, float *const gz) const
Alias for getGyro()
Definition ahrs_imu.hpp:230
bool getGyroMag(float *const mx, float *const my, float *const mz) const
Alias for getMag() (name mirrors m5::IMU_Class::getGyroMag)
Definition ahrs_imu.hpp:236
axis_t
A source axis with a sign, layout-compatible with m5::IMU_Class::axis_t.
Definition ahrs_imu.hpp:77
@ axis_z_neg
-Z
Definition ahrs_imu.hpp:83
@ axis_z_pos
+Z
Definition ahrs_imu.hpp:82
@ axis_x_neg
-X
Definition ahrs_imu.hpp:79
@ axis_x_pos
+X
Definition ahrs_imu.hpp:78
@ axis_y_neg
-Y
Definition ahrs_imu.hpp:81
@ axis_y_pos
+Y
Definition ahrs_imu.hpp:80
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26
Exportable/importable snapshot of every capability's auto-calibration offset.
Definition ahrs_controller.hpp:66
3-axis float vector, layout-compatible with m5::IMU_Class::imu_3d_t
Definition ahrs_imu.hpp:44
Merged accel/gyro/mag sample, layout-compatible with m5::IMU_Class::imu_data_t.
Definition ahrs_imu.hpp:59
uint32_t usec
Timestamp of the sample's update() call (microseconds)
Definition ahrs_imu.hpp:60
Chip-frame-to-body-frame axis remap: a permutation plus a per-output-axis sign flip.
Definition axis_order.hpp:43
bool invert_y
Negate output Y after permutation.
Definition axis_order.hpp:46
AxisPermutation permutation
Axis permutation.
Definition axis_order.hpp:44
bool invert_z
Negate output Z after permutation.
Definition axis_order.hpp:47
bool invert_x
Negate output X after permutation.
Definition axis_order.hpp:45
Merged, converted physical-unit IMU sample (AhrsController::latest())
Definition imu_types.hpp:81
float gyro[3]
Gyroscope X/Y/Z (dps)
Definition imu_types.hpp:83
float accel[3]
Accelerometer X/Y/Z (G)
Definition imu_types.hpp:82
float temp
Temperature (degC)
Definition imu_types.hpp:85
float mag[3]
Magnetometer X/Y/Z (uT)
Definition imu_types.hpp:84