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

Minimal fixed-size matrix arithmetic (framework independent) More...

#include <array>
#include <cmath>
#include <cstddef>

Go to the source code of this file.

Classes

class  m5::math::Matrix< R, C >
 Fixed-size (R rows x C columns) float matrix, std::array backed (no heap allocation) More...
 

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Functions

bool m5::math::invert3x3 (const Matrix< 3, 3 > &m, Matrix< 3, 3 > &out)
 Closed-form inverse of a 3x3 matrix.
 
template<std::size_t N>
bool m5::math::cholesky_solve (const Matrix< N, N > &a, const Matrix< N, 1 > &b, Matrix< N, 1 > &x)
 Solve A*x = b for a symmetric positive-definite A via Cholesky decomposition.
 

Variables

constexpr float m5::math::MATRIX_ZERO_EPSILON {1e-9f}
 Magnitudes below this are treated as singular/non-positive-definite (matrix safety)
 

Detailed Description

Minimal fixed-size matrix arithmetic (framework independent)

Header-only, heap-free (std::array backed) fixed-size matrix type, providing only what src/imu/filter/ekf.hpp needs: element access, addition, subtraction, scalar and matrix multiplication, transpose, and identity for square matrices. General NxN inversion is intentionally not provided; instead two narrow numerical primitives are exposed as free functions:

  • invert3x3(): closed-form 3x3 inverse, for a single 3-axis observation update (e.g. accel, then mag as a separate sequential step)
  • cholesky_solve(): solves A*x = b for a symmetric positive-definite A of any fixed size via Cholesky decomposition, for callers that prefer a single combined observation update (e.g. a 6x6 accel+mag innovation covariance) instead of two sequential 3x3 updates

Function Documentation

◆ cholesky_solve()

template<std::size_t N>
bool m5::math::cholesky_solve ( const Matrix< N, N > & a,
const Matrix< N, 1 > & b,
Matrix< N, 1 > & x )
inline

Solve A*x = b for a symmetric positive-definite A via Cholesky decomposition.

Parameters
aSymmetric positive-definite matrix (only the lower triangle, row >= col, is read)
bRight-hand side column vector
[out]xSolution; only written on success
Returns
False if a is not (numerically) positive-definite, leaving x unwritten

◆ invert3x3()

bool m5::math::invert3x3 ( const Matrix< 3, 3 > & m,
Matrix< 3, 3 > & out )
inline

Closed-form inverse of a 3x3 matrix.

Parameters
mMatrix to invert
[out]outInverse of m; only written on success
Returns
False if m is (near) singular (determinant magnitude below MATRIX_ZERO_EPSILON), leaving out unwritten
Note
The singularity threshold MATRIX_ZERO_EPSILON is 1e-9 (absolute determinant magnitude). Matrices with very small scale (e.g., condition number > 1e9) will be treated as singular; the caller should handle failure gracefully by skipping the update (as in EKFFilter::apply_axis3_update()), which is safe because the Kalman gain computation is optional for each observation.