mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-13 06:03:34 +08:00
Added filtering test.
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ set(CMAKE_CXX_FLAGS
|
||||
-Wall
|
||||
-Weffc++
|
||||
-Werror
|
||||
-Wfatal-errors
|
||||
#-Wfatal-errors
|
||||
)
|
||||
|
||||
if (COVERALLS)
|
||||
|
||||
@@ -209,6 +209,15 @@ SquareMatrix<Type, M> eye() {
|
||||
return m;
|
||||
}
|
||||
|
||||
template<typename Type, size_t M>
|
||||
SquareMatrix<Type, M> diag(Vector<Type, M> d) {
|
||||
SquareMatrix<Type, M> m;
|
||||
for (size_t i=0; i<M; i++) {
|
||||
m(i,i) = d(i);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
}; // namespace matrix
|
||||
|
||||
/* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
|
||||
|
||||
@@ -25,6 +25,16 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Vector(const Vector<Type, M> & other) :
|
||||
Matrix<Type, M, 1>(other)
|
||||
{
|
||||
}
|
||||
|
||||
Vector(const Matrix<Type, M, 1> & other) :
|
||||
Matrix<Type, M, 1>(other)
|
||||
{
|
||||
}
|
||||
|
||||
inline Type operator()(size_t i) const
|
||||
{
|
||||
const Matrix<Type, M, 1> &v = *this;
|
||||
|
||||
@@ -2,17 +2,21 @@
|
||||
|
||||
#include "matrix.hpp"
|
||||
|
||||
namespace matrix {
|
||||
|
||||
template<typename Type, size_t M, size_t N>
|
||||
void kalman_correct(
|
||||
const Matrix<Type, M, M> & P,
|
||||
const Matrix<Type, N, N> & R,
|
||||
const Matrix<Type, N, M> & C,
|
||||
const Matrix<Type, N, N> & R,
|
||||
const Vector<Type, N> &r,
|
||||
Vector<Type, M> & dx,
|
||||
float beta
|
||||
float & beta
|
||||
)
|
||||
{
|
||||
SuareMatrix<Type, N> S_I = SquarMatrix<Type, N>(C*P*C.T() + R).I();
|
||||
SquareMatrix<Type, N> S_I = SquareMatrix<Type, N>(C*P*C.T() + R).I();
|
||||
dx = P*C.T()*S_I*r;
|
||||
beta = Scalar(r.T()*S_I*r);
|
||||
beta = Scalar<Type>(r.T()*S_I*r);
|
||||
}
|
||||
|
||||
}; // namespace matrix
|
||||
@@ -11,6 +11,7 @@ set(tests
|
||||
vector
|
||||
vector3
|
||||
euler
|
||||
filter
|
||||
)
|
||||
|
||||
foreach(test ${tests})
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "filter.hpp"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace matrix;
|
||||
|
||||
template class Vector<float, 5>;
|
||||
|
||||
int main()
|
||||
{
|
||||
const size_t n_x = 6;
|
||||
const size_t n_y = 5;
|
||||
SquareMatrix<float, n_x> P = eye<float, n_x>()*0.1;
|
||||
SquareMatrix<float, n_y> R = eye<float, n_y>()*0.1;
|
||||
Matrix<float, n_y, n_x> C;
|
||||
C(0,0) = 1;
|
||||
Vector<float, n_y> r;
|
||||
r.setZero();
|
||||
r(0) = 1;
|
||||
|
||||
Vector<float, n_x> dx;
|
||||
float beta = 0;
|
||||
kalman_correct<float, 6, 5>(P, C, R, r, dx, beta);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
|
||||
@@ -18,6 +18,12 @@ int main()
|
||||
assert(q(2) == 0);
|
||||
assert(q(3) == 0);
|
||||
|
||||
q = Quatf(1,2,3,4);
|
||||
assert(q(0) == 1);
|
||||
assert(q(1) == 2);
|
||||
assert(q(2) == 3);
|
||||
assert(q(3) == 4);
|
||||
|
||||
q = Quatf(0.1825742f, 0.3651484f, 0.5477226f, 0.7302967f);
|
||||
assert(q(0) == 0.1825742f);
|
||||
assert(q(1) == 0.3651484f);
|
||||
|
||||
Reference in New Issue
Block a user