M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
presets.hpp File Reference

Board-specific AhrsController setup for M5Stack products with a built-in IMU, and for the GROVE units whose sensors need an axis remap. More...

Go to the source code of this file.

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Functions

bool m5::imu::presets::core2 (AhrsController &ahrs, m5::unit::UnitMPU6886 &mpu6886)
 M5Stack Core2's built-in MPU6886.
 
bool m5::imu::presets::coreS3 (AhrsController &ahrs, m5::unit::UnitBMI270 &bmi270)
 M5Stack CoreS3/CoreS3 SE/StackChan's built-in BMI270 (with AUX BMM150 magnetometer)
 
bool m5::imu::presets::atomS3R (AhrsController &ahrs, m5::unit::UnitBMI270 &bmi270)
 AtomS3R/AtomS3R CAM/AtomS3R Ext's built-in BMI270 (with AUX BMM150 magnetometer)
 
bool m5::imu::presets::stickS3 (AhrsController &ahrs, m5::unit::UnitBMI270 &bmi270)
 StickS3's built-in BMI270.
 
bool m5::imu::presets::m5stackCoreFire (AhrsController &ahrs, m5::unit::UnitMPU6886 &mpu6886, m5::unit::UnitBMM150 &bmm150)
 Classic M5Stack Core/Fire's built-in MPU6886 + discrete BMM150 magnetometer.
 
bool m5::imu::presets::m5stackCoreFire (AhrsController &ahrs, m5::unit::UnitSH200Q &sh200q, m5::unit::UnitBMM150 &bmm150)
 Fire 2019.7's built-in SH200Q + discrete BMM150 magnetometer.
 
bool m5::imu::presets::atomMatrix (AhrsController &ahrs, m5::unit::UnitMPU6886 &mpu6886)
 AtomMatrix's built-in MPU6886.
 
bool m5::imu::presets::atomMatrix (AhrsController &ahrs, m5::unit::UnitBMI270 &bmi270)
 ATOM Matrix v1.1's built-in BMI270 (the MPU6886 was replaced by a BMI270 at v1.1)
 
bool m5::imu::presets::mpu9250Ak8963 (AhrsController &ahrs, m5::unit::UnitAK8963 &ak8963)
 Original (MPU9250-based) classic M5Stack's built-in AK8963 magnetometer.
 
bool m5::imu::presets::unitDoF (AhrsController &ahrs, m5::unit::UnitBMI270 &bmi270, m5::unit::UnitBMM350 &bmm350)
 Unit DoF9 / DoF10's BMI270 + BMM350 pair (U229 / U230)
 
bool m5::imu::presets::unitBMM350 (AhrsController &ahrs, m5::unit::UnitBMM350 &bmm350)
 Unit BMM350's magnetometer (U231), e.g. paired with a UnitMiniIMU for 9-axis.
 

Detailed Description

Board-specific AhrsController setup for M5Stack products with a built-in IMU, and for the GROVE units whose sensors need an axis remap.

Each function below only registers the given unit(s) with an AhrsController and applies the axis remap M5Unified's IMU_Class::begin() hard-codes for that board. None of these functions call unit.begin() themselves – the caller must have already begun the unit(s) (I2C bus ready) – and none of them decide which board is running; callers pick which preset to call (e.g. via M5.getBoard()).

Function Documentation

◆ atomMatrix() [1/2]

bool m5::imu::presets::atomMatrix ( AhrsController & ahrs,
m5::unit::UnitBMI270 & bmi270 )

ATOM Matrix v1.1's built-in BMI270 (the MPU6886 was replaced by a BMI270 at v1.1)

Parameters
ahrsController to register bmi270 with
bmi270ATOM Matrix v1.1's built-in BMI270 (6-axis, no AUX magnetometer; must already be begin()'d)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin() gives the AtomMatrix BMI270 the same accel/gyro X/Z inversion as the original MPU6886 AtomMatrix (the board orientation is unchanged across the chip swap). Both capabilities come from the same source and need the identical correction, so this maps onto a single AhrsController::writeAxisOrder().

◆ atomMatrix() [2/2]

bool m5::imu::presets::atomMatrix ( AhrsController & ahrs,
m5::unit::UnitMPU6886 & mpu6886 )

AtomMatrix's built-in MPU6886.

Parameters
ahrsController to register mpu6886 with
mpu6886AtomMatrix's built-in MPU6886 (must already be begin()'d)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin(): for board_M5AtomMatrix, accel and gyro both get X and Z inverted ("IMU is oriented differently"). Both capabilities come from the same MPU6886 source and need the identical correction, so this maps cleanly onto AhrsController::writeAxisOrder() (one AxisOrder for the whole source).

◆ atomS3R()

bool m5::imu::presets::atomS3R ( AhrsController & ahrs,
m5::unit::UnitBMI270 & bmi270 )

AtomS3R/AtomS3R CAM/AtomS3R Ext's built-in BMI270 (with AUX BMM150 magnetometer)

Parameters
ahrsController to register bmi270 with
bmi270AtomS3R's built-in BMI270, with the AUX BMM150 probed and enabled (detected by UnitBMI270AuxBMM150 on start)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin(): for board_M5AtomS3R / board_M5AtomS3RCam / board_M5AtomS3RExt, accel/gyro get X/Y swapped plus Y inverted (axis_order_yxz | axis_invert_y), while mag gets X and Z inverted instead (axis_invert_x | axis_invert_z) – two different corrections from the same chip. This function applies the accel/gyro correction (AxisPermutation::YXZ, invert_y) via AhrsController::writeAxisOrder(), and the independent mag correction (invert_x | invert_z) via AhrsController::writeMagAxisOrder().

◆ core2()

bool m5::imu::presets::core2 ( AhrsController & ahrs,
m5::unit::UnitMPU6886 & mpu6886 )

M5Stack Core2's built-in MPU6886.

Parameters
ahrsController to register mpu6886 with
mpu6886Core2's built-in MPU6886 (must already be begin()'d)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin() has no case for board_M5StackCore2 in its axis-order switch (IMU_Class), i.e. the identity transform is already correct here. AhrsController::add() defaults every newly added source to the identity AxisOrder, so this function does not call writeAxisOrder().

◆ coreS3()

bool m5::imu::presets::coreS3 ( AhrsController & ahrs,
m5::unit::UnitBMI270 & bmi270 )

M5Stack CoreS3/CoreS3 SE/StackChan's built-in BMI270 (with AUX BMM150 magnetometer)

Parameters
ahrsController to register bmi270 with
bmi270CoreS3's built-in BMI270 at address 0x69, with the AUX BMM150 probed and detected by UnitBMI270AuxBMM150 on start
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin(): for board_M5StackCoreS3 / board_M5StackChan with the BMI270 at address 0x69, only the magnetometer's Y and Z axes are inverted (accel/gyro are left as identity). accel/gyro keep the default identity AxisOrder; only the AUX BMM150's Mag samples get the Y/Z inversion, via AhrsController::writeMagAxisOrder().

◆ m5stackCoreFire() [1/2]

bool m5::imu::presets::m5stackCoreFire ( AhrsController & ahrs,
m5::unit::UnitMPU6886 & mpu6886,
m5::unit::UnitBMM150 & bmm150 )

Classic M5Stack Core/Fire's built-in MPU6886 + discrete BMM150 magnetometer.

Parameters
ahrsController to register mpu6886 and bmm150 with
mpu6886The board's built-in MPU6886 (must already be begin()'d)
bmm150The board's built-in, separately-wired BMM150 (must already be begin()'d)
Returns
False if either add() call fails (see AhrsController::add())

M5Unified's IMU_Class::begin(): for board_M5Stack with an MPU6886 + BMM150 combination, the magnetometer's X and Z axes are inverted. mpu6886 and bmm150 are two independent IMUDataSource instances here, so this maps cleanly onto AhrsController::writeAxisOrder() – mpu6886 keeps the identity transform, only bmm150 gets the correction.

◆ m5stackCoreFire() [2/2]

bool m5::imu::presets::m5stackCoreFire ( AhrsController & ahrs,
m5::unit::UnitSH200Q & sh200q,
m5::unit::UnitBMM150 & bmm150 )

Fire 2019.7's built-in SH200Q + discrete BMM150 magnetometer.

Parameters
ahrsController to register sh200q and bmm150 with
sh200qThe board's built-in SH200Q (must already be begin()'d)
bmm150The board's built-in, separately-wired BMM150 (must already be begin()'d)
Returns
False if either add() call fails (see AhrsController::add())

The BMM150's X/Z inversion is a board-mounting property of board_M5Stack (M5Unified gates it on the board, not on the accel chip), so the same mag correction as the MPU6886 generation applies. The SH200Q accel/gyro stay at identity: no M5Unified reference table exists for it and field reports suggest its accel and gyro axis systems may disagree – confirm on 2019.7 hardware before committing a correction (see the IMU orientation wiki page).

◆ mpu9250Ak8963()

bool m5::imu::presets::mpu9250Ak8963 ( AhrsController & ahrs,
m5::unit::UnitAK8963 & ak8963 )

Original (MPU9250-based) classic M5Stack's built-in AK8963 magnetometer.

Parameters
ahrsController to register ak8963 with
ak8963The MPU9250-internal AK8963 (must already be begin()'d; the MPU9250 bypass must already be open – see m5::unit::imu::enableAuxBypass)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin(): for an MPU9250-internal AK8963 (gated on the accel/gyro being an MPU9250, not on board id), the magnetometer's X/Y axes are swapped and Z inverted (axis_order_yxz | axis_invert_z). AK8963 is a pure-Mag source, so the correction is applied via AhrsController::writeMagAxisOrder() (the mag remap path).

◆ stickS3()

bool m5::imu::presets::stickS3 ( AhrsController & ahrs,
m5::unit::UnitBMI270 & bmi270 )

StickS3's built-in BMI270.

Parameters
ahrsController to register bmi270 with
bmi270StickS3's built-in BMI270 (6-axis, no AUX magnetometer; must already be begin()'d)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified's IMU_Class::begin(): for board_M5StickS3, accel/gyro get X/Y swapped plus Y inverted (axis_order_yxz | axis_invert_y), the same correction as AtomS3R. The result is X toward the right side (screen facing you, USB-C at the bottom), Y away from the USB-C end, Z out of the screen. The official orientation diagram shows the chip's own axes instead (X toward USB-C, Y right, Z up).

◆ unitBMM350()

bool m5::imu::presets::unitBMM350 ( AhrsController & ahrs,
m5::unit::UnitBMM350 & bmm350 )

Unit BMM350's magnetometer (U231), e.g. paired with a UnitMiniIMU for 9-axis.

Parameters
ahrsController to register bmm350 with
bmm350The GROVE Unit BMM350 (must already be begin()'d)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

Determined on hardware; M5Stack's own U171 library never fuses its magnetometer, so there is no upstream mapping to transcribe for the GROVE magnetometers. The correction is the same 180-degree rotation about X that the DoF boards need (see unitDoF()):

body = (mag_x, -mag_y, -mag_z)

Add the accel/gyro partner separately – a UnitMiniIMU needs no correction, its frame already matches this unit's (label up, GROVE connector nearest: +X right, +Y away from the connector, +Z out of the label face). Orient both units the same way, or apply the difference with AhrsController::writeUserAxisOrder().

◆ unitDoF()

bool m5::imu::presets::unitDoF ( AhrsController & ahrs,
m5::unit::UnitBMI270 & bmi270,
m5::unit::UnitBMM350 & bmm350 )

Unit DoF9 / DoF10's BMI270 + BMM350 pair (U229 / U230)

Parameters
ahrsController to register both sources with
bmi270UnitDoF9::imu() / UnitDoF10::imu() (must already be begin()'d)
bmm350UnitDoF9::mag() / UnitDoF10::mag() (must already be begin()'d)
Returns
False if ahrs already holds the maximum number of sources (see AhrsController::add())

M5Unified has no case for these units, so unlike the other presets here this one was determined on hardware. The BMI270 keeps the identity transform (its frame matches UnitMiniIMU); only the BMM350 needs a correction, a 180-degree rotation about X applied through the mag remap path: body = (mag_x, -mag_y, -mag_z). DoF6 (U228) is a bare BMI270 and needs no preset.