mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-06 09:11:07 +08:00
c29c44b450dbbcbfca25e33a59f7978db73a09c7
matrix

A simple and efficient template based matrix library.
License
- (BSD) The Matrix library is licensed under a permissive 3-clause BSD license. Contributions must be made under the same license.
Features
- Compile time size checking.
- Euler angle (321), DCM, Quaternion conversion through constructors.
- High testing coverage.
Limitations
- No dynamically sized matrices.
Example
// define an euler angle (Body 3(yaw)-2(pitch)-1(roll) rotation)
float roll = 0.1f;
float pitch = 0.2f;
float yaw = 0.3f;
Eulerf euler(roll, pitch, yaw);
// convert to quaternion from euler
Quatf q_nb(euler);
// convert to DCM from quaternion
Dcmf dcm(q_nb);
// do some kalman filtering
const size_t n_x = 5;
const size_t n_y = 3;
// define matrix sizes
SquareMatrix<float, n_x> P;
Vector<float, n_x> x;
Vector<float, n_y> y;
Matrix<float, n_y, n_x> C;
SquareMatrix<float, n_y> R;
SquareMatrix<float, n_y> S;
Matrix<float, n_x, n_y> K;
// define measurement matrix
C = zero<float, n_y, n_x>(); // or C.setZero()
C(0,0) = 1;
C(1,1) = 2;
C(2,2) = 3;
// set x to zero
x = zero<float, n_x, 1>(); // or x.setZero()
// set P to identity * 0.01
P = eye<float, n_x>()*0.01;
// set R to identity * 0.1
R = eye<float, n_y>()*0.1;
// measurement
y(0) = 1;
y(1) = 2;
y(2) = 3;
// innovation
r = y - C*x;
// innovations variance
S = C*P*C.T() + R;
// Kalman gain matrix
K = P*C.T()*S.I();
// S.I() is the inverse, defined for SquareMatrix
// correction
x += K*r;
Description
No description provided
autonomousautopilotavoidanceddsdronedronecodedronesfixed-wingmavlinkmavrosmulticopterpixhawkpx4qgroundcontrolrosros2uasuavugv
Readme
BSD-3-Clause
1.9 GiB
0 Stars
1 Watchers
0 Forks
Languages
C++
49.7%
C
35.8%
Python
5.1%
CMake
4.4%
Linker Script
3.4%
Other
1.4%