![]() |
Hummingbird Flight Software
Flight software for the Hummingbird FCU quadcopter flight controller. Designed to run on the Teensy 4.1. Developed with VSCode+PlatformIO.
|
#include <Arduino.h>
#include <math.h>
#include "hummingbird_config.h"
#include "maths/math_functs.h"
#include "maths/matrices.h"
#include "maths/vectors.h"
Go to the source code of this file.
Functions | |
void | VectorfFill (float *vec, float fill, size_t n) |
USES SINGLE-PRECISION FLOATS! More... | |
void | VectorfAdd (float *c, float *a, float *b, size_t n) |
Add two vectors together and output result to a new vector. More... | |
void | VectorfAccumulate (float *a, float *b, size_t n) |
a <- a + b. More... | |
void | VectorfSubtract (float *c, float *a, float *b, size_t n) |
Subtract two vectors and output result to a new vector. More... | |
void | MatrixFill (float fill, float *A, size_t rows, size_t cols) |
Fill a matrix with a specified value. More... | |
void | MatrixTranspose (float *A, float *At, size_t arows, size_t acols) |
Compute the transpose of a matrix and output it to another one. More... | |
void | MatrixTransposeSquare (float *A, size_t n) |
Compute the transpose of a SQUARE (n, n) matrix in-place. More... | |
void | MatrixAdd (float *C, float *A, float *B, size_t rows, size_t cols) |
C <- A + B. More... | |
void | MatrixAddIdentity (float *A, size_t rows, size_t cols) |
A <- I + A. More... | |
void | MatrixAccumulate (float *A, float *B, size_t rows, size_t cols) |
A <- A + B. More... | |
void | MatrixSubtract (float *C, float *A, float *B, size_t rows, size_t cols) |
C <- A - B. More... | |
void | MatrixSubtractIdentity (float *A, size_t rows, size_t cols) |
A <- I - A. More... | |
void | MatrixSubAccumulate (float *A, float *B, size_t rows, size_t cols) |
A <- A - B. More... | |
void | MatrixNegate (float *A, size_t rows, size_t cols) |
Multiply all elements in a matrix by -1. More... | |
void | MatrixVectorfMult (float *outVec, float *A, float *b, size_t rows, size_t cols) |
c <- A * b. More... | |
void | MatrixMultiply (float *C, float *A, float *B, size_t aRows, size_t aCols, size_t bRows, size_t bCols) |
C <- A * B. More... | |
void | MatrixMultiply_ABt (float *C, float *A, float *B, size_t arows, size_t acols, size_t brows) |
C <- A * B^T. More... | |
bool | MatrixInverseCholesky (float *A, size_t n) |
Compute the inverse of matrix A via Cholesky decomposition. More... | |
bool | _MatrixCholeskyDecomp (float *A, size_t n) |
Perform Cholesky decomposition on a square, symmetric, positive definite matrix. More... | |
bool | _MatrixLowerTriangularInverse (float *A, size_t n) |
Compute the inverse of a lower triangular matrix. More... | |
bool _MatrixCholeskyDecomp | ( | float * | A, |
size_t | n | ||
) |
Perform Cholesky decomposition on a square, symmetric, positive definite matrix.
Used in the MatrixInverseCholesky() routine. Original code can be found at: http://www.mymathlib.com/matrices/
bool _MatrixLowerTriangularInverse | ( | float * | A, |
size_t | n | ||
) |
Compute the inverse of a lower triangular matrix.
Used in the MatrixInverseCholesky() function. Original code can be found at: http://www.mymathlib.com/matrices/
void MatrixAccumulate | ( | float * | A, |
float * | B, | ||
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixAdd | ( | float * | C, |
float * | A, | ||
float * | B, | ||
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixAddIdentity | ( | float * | A, |
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixFill | ( | float | fill, |
float * | A, | ||
size_t | rows, | ||
size_t | cols | ||
) |
Fill a matrix with a specified value.
Use this to initialize arrays before they're used.
fill | Value to fill array with |
A | Matrix of interest |
r | Rows |
c | Columns |
bool MatrixInverseCholesky | ( | float * | A, |
size_t | n | ||
) |
Compute the inverse of matrix A via Cholesky decomposition.
This algorithm outputs replaces the input matrix with it's inverse. Note that Cholesky decomposition only works for square, symmetric, positive definite matrices. The original algorithm cab be found at: http://www.mymathlib.com/c_source/matrices/linearsystems/choleski.c
A | Input matrix, SPD |
n | Rows /columns of the square matrix |
void MatrixMultiply | ( | float * | C, |
float * | A, | ||
float * | B, | ||
size_t | aRows, | ||
size_t | aCols, | ||
size_t | bRows, | ||
size_t | bCols | ||
) |
C <- A * B.
Perform matrix multiplication for two matrices. Outputs result to a new array C. MAKE SURE A COLUMNS EQUAL B ROWS. OUTPUT DIMENSION SHOULD BE (A_ROWS, B_COLS).
A | First matrix |
B | Second matrix |
C | Output array |
aRows | Rows of A |
aCols | Columns of A |
bRows | Rows of B |
bCols | Columns of B |
void MatrixMultiply_ABt | ( | float * | C, |
float * | A, | ||
float * | B, | ||
size_t | arows, | ||
size_t | acols, | ||
size_t | brows | ||
) |
void MatrixNegate | ( | float * | A, |
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixSubAccumulate | ( | float * | A, |
float * | B, | ||
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixSubtract | ( | float * | C, |
float * | A, | ||
float * | B, | ||
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixSubtractIdentity | ( | float * | A, |
size_t | rows, | ||
size_t | cols | ||
) |
void MatrixTranspose | ( | float * | A, |
float * | At, | ||
size_t | arows, | ||
size_t | acols | ||
) |
Compute the transpose of a matrix and output it to another one.
Matrix "A" has dimensions (r, c) and the transpose "At" has dimensions (c, r). See the following link for original source code: http://www.mymathlib.com/c_source/matrices/datamovement/transpose_matrix.c
void MatrixTransposeSquare | ( | float * | A, |
size_t | n | ||
) |
Compute the transpose of a SQUARE (n, n) matrix in-place.
See the following link for original source code: http://www.mymathlib.com/c_source/matrices/datamovement/transpose_square_matrix.c
A | Original matrix |
n | Rows/columns of the square matrix |
void MatrixVectorfMult | ( | float * | outVec, |
float * | A, | ||
float * | b, | ||
size_t | rows, | ||
size_t | cols | ||
) |
void VectorfAccumulate | ( | float * | a, |
float * | b, | ||
size_t | n | ||
) |
a <- a + b.
Add two vectors in-place and output result to vector a. Assumes vectors have similar dimensions.
a | Pointer to first vector |
b | Pointer to second vector |
n | Length of vector |
void VectorfAdd | ( | float * | c, |
float * | a, | ||
float * | b, | ||
size_t | n | ||
) |
Add two vectors together and output result to a new vector.
Assumes vectors have similar dimensions. c <- a + b
a | Pointer to first vector |
b | Pointer to second vector |
c | Pointer to output vector |
n | Length of vector |
void VectorfFill | ( | float * | vec, |
float | fill, | ||
size_t | n | ||
) |
USES SINGLE-PRECISION FLOATS!
The library assumes the 2D array is one long dynamic array in memory (row major). The array indexing may be a bit strange, but since we allocated one long array in memory, it sould help a bit with cache performance. See below for an example of this.
I give the following site credit for the matrix math algorithms. It was a significant inspiration and resource for algorithms! http://www.mymathlib.com/matrices/
Vectorf operations include:
Matrix operations include:
How to Allocate and Access a 1D Array (vector):
float *b = new float[rows]; // Allocate 1D aray/vector
for (size_t i = 0; i < rows; i++)
How to Allocate and Access a 2D Array:
float *A = new float[rows * cols]; // Allocate 2D array
for (size_t i = 0; i < rows; i++) // Set value for (size_t j = 0; j < cols; j++)
https://www.techiedelight.com/dynamic-memory-allocation-in-c-for-2d-3d-array/ https://eli.thegreenplace.net/2015/memory-layout-of-multi-dimensional-arrays
The library assumes the 2D array is one long dynamic array in memory (row major). The array indexing may be a bit strange, but since we allocated one long array in memory, it sould help a bit with cache performance. See below for an example of this.
I give the following site credit for the matrix math algorithms. It was a significant inspiration and resource for algorithms! http://www.mymathlib.com/matrices/
Vectorf operations include:
Matrix operations include:
How to Allocate and Access a 1D Array (vector):
float *b = new float[rows]; // Allocate 1D aray/vector
for (size_t i = 0; i < rows; i++)
How to Allocate and Access a 2D Array:
float *A = new float[rows * cols]; // Allocate 2D array
for (size_t i = 0; i < rows; i++) // Set value for (size_t j = 0; j < cols; j++)
https://www.techiedelight.com/dynamic-memory-allocation-in-c-for-2d-3d-array/ https://eli.thegreenplace.net/2015/memory-layout-of-multi-dimensional-arrays Fill a vector with a specified value. Use this to initialize arrays before they're used.
fill | Value to fill array with |
a | Vectorf of interest |
n | Size/length of vector |
void VectorfSubtract | ( | float * | c, |
float * | a, | ||
float * | b, | ||
size_t | n | ||
) |
Subtract two vectors and output result to a new vector.
Assumes vectors have similar dimensions. c <- a - b
a | Pointer to first vector |
b | Pointer to second vector |
c | Pointer to output vector |
n | Length of vector |