sta-peak/README.md
2024-11-09 00:03:15 +00:00

77 lines
2.6 KiB
Markdown

# Performant Embedded Algebra Kit (PEAK)
## Description
The Performant Embedded Algebra Kit (PEAK) is a lightweight, easy-to-use library for performing various algebraic operations. This library is built on Lukas Freiheit's matrix structures and linear algebra code, originally developed for Aquila Maris' [caput firmware](https://git.intern.spaceteamaachen.de/AQUILA_MARIS/caput_firmware/src/branch/main/caput).
## Features
- Matrix operations: Perform matrix addition, subtraction, multiplication, and inversion.
- Kalman Filter implementations
- basic Kalman Filter
- Dynamic Kalman Filter, with variable delta t (WIP)
## Usage
### Basics
The following example demonstrates the creation of matrices and basic operations on them.
```cpp
#include <sta/math/linalg/matrix.hpp>
#include <sta/math/linalg/linalg.hpp>
// Create a 3x2 matrix with every entry initialized to 0:
sta::math::matrix m_0 = sta::math::matrix::zeros(3,2);
// Set specific entries in the matrix:
m_0.set(0, 1, 4); // set the entry in the first column and second column to 0
m_0.set(1, 0, 5);
//m_0.set(2, 2, 99); -> Column index out of range
// Display the matrix:
m_0.show_serial();
// Output:
// Matrix shape: (3 x 2)
// | 0.000000 | 4.000000 |
// | 5.000000 | 0.000000 |
// | 0.000000 | 0.000000 |
// Create a 3x2 matrix with every entry initialized to 10:
sta::math::matrix m_10 = sta::math::matrix::full(3,2,10);
// Matrices of the same shape can be added together using the + operator:
sta::math::matrix m_a = m_0 + m_10;
// m_a:
// | 10.000000 | 14.000000 |
// | 15.000000 | 10.000000 |
// | 10.000000 | 10.000000 |
// Create an identity matrix of size 3 and multiply it by 5:
sta::math::matrix m_i = sta::math::matrix::eye(3) * 5;
// Set a specific entry in the identity matrix:
m_i.set(0, 2, 0.5);
// m_i:
// | 5.000000 | 0.000000 | 0.500000 |
// | 0.000000 | 5.000000 | 0.000000 |
// | 0.000000 | 0.000000 | 5.000000 |
// Matrices of the appropriate shape can be multiplied together using the * operator:
sta::math::matrix m_res = m_i * m_a;
// m_res:
// | 55.000000 | 75.000000 |
// | 75.000000 | 50.000000 |
// | 50.000000 | 50.000000 |
```
### Kalman Filters
Every Kalman filter object requires a measurement matrix *H* and a measurement covariance matrix *R*. These matrices will be used when the `correct` method is called with only the current state and a measurement value. If you are using multiple sensors, you can also pass new *H* and *R* matrices directly, which will then be used instead. This also allows you to handle changes in measurement uncertainty over time.
## Limitations
As of now, only matrices with no more than 256 elements are supported.