forked from PX4/PX4-Autopilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only keep moving filter for orientation.
- Loading branch information
jonas
committed
Oct 20, 2024
1 parent
23dcda0
commit b2bcc0c
Showing
13 changed files
with
62 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,37 +34,33 @@ | |
// TODO: rename to KF_position and clean up comments | ||
|
||
/** | ||
* @file KF_position_moving.cpp | ||
* @brief Filter to estimate the pose of moving targets. State: [pos_rel, vel_uav, bias, acc_target, vel_target] | ||
* @file KF_orientation.cpp | ||
* @brief Filter to estimate the orientation of moving targets. State: [yaw, yaw_rate] | ||
* | ||
* @author Jonas Perolini <[email protected]> | ||
* | ||
*/ | ||
|
||
#include "KF_orientation_unified.h" | ||
#include "python_derivation/generated/syncState.h" | ||
#include "python_derivation/generated/predictState.h" | ||
#include "python_derivation/generated/predictCov.h" | ||
#include "python_derivation/generated/computeInnovCov.h" | ||
|
||
namespace vision_target_estimator | ||
{ | ||
|
||
void KF_orientation_unified::predictState(float dt) | ||
{ | ||
matrix::Vector<float, vtest::State::size> state_updated; | ||
sym::Predictstate(dt, _state, &state_updated); | ||
|
||
for (int i = 0; i < vtest::State::size; i++) { | ||
_state(i) = matrix::wrap_pi(state_updated(i)); | ||
matrix::SquareMatrix<float, 2> phi = getPhi(dt); | ||
_state = phi * _state; | ||
|
||
for (int i = 0; i < State::size; i++) { | ||
_state(i) = matrix::wrap_pi(_state(i)); | ||
} | ||
} | ||
|
||
void KF_orientation_unified::predictCov(float dt) | ||
{ | ||
matrix::Matrix<float, vtest::State::size, vtest::State::size> cov_updated; | ||
sym::Predictcov(dt, _state_covariance, &cov_updated); | ||
_state_covariance = cov_updated; | ||
matrix::SquareMatrix<float, 2> phi = getPhi(dt); | ||
_state_covariance = phi * _state_covariance * phi.transpose(); | ||
} | ||
|
||
|
||
|
@@ -82,11 +78,11 @@ bool KF_orientation_unified::update() | |
return false; | ||
} | ||
|
||
const matrix::Matrix<float, vtest::State::size, 1> kalmanGain = _state_covariance * _meas_matrix_row_vect / _innov_cov; | ||
const matrix::Matrix<float, 2, 1> kalmanGain = _state_covariance * _meas_matrix_row_vect / _innov_cov; | ||
|
||
_state = _state + kalmanGain * _innov; | ||
|
||
for (int i = 0; i < vtest::State::size; i++) { | ||
for (int i = 0; i < 2; i++) { | ||
_state(i) = matrix::wrap_pi(_state(i)); | ||
} | ||
|
||
|
@@ -98,20 +94,17 @@ bool KF_orientation_unified::update() | |
void KF_orientation_unified::syncState(float dt) | ||
{ | ||
|
||
matrix::Vector<float, vtest::State::size> synced_state; | ||
sym::Syncstate(dt, _state, &synced_state); | ||
matrix::SquareMatrix<float, 2> phi = getPhi(dt); | ||
_sync_state = matrix::inv(phi) * _state; | ||
|
||
for (int i = 0; i < vtest::State::size; i++) { | ||
_sync_state(i) = matrix::wrap_pi(synced_state(i)); | ||
for (int i = 0; i < 2; i++) { | ||
_sync_state(i) = matrix::wrap_pi(_sync_state(i)); | ||
} | ||
} | ||
|
||
float KF_orientation_unified::computeInnovCov(float meas_unc) | ||
{ | ||
float innov_cov_updated; | ||
sym::Computeinnovcov(meas_unc, _state_covariance, _meas_matrix_row_vect.transpose(), &innov_cov_updated); | ||
_innov_cov = innov_cov_updated; | ||
|
||
_innov_cov = (_meas_matrix_row_vect.transpose() * _state_covariance * _meas_matrix_row_vect)(0, 0) + meas_unc; | ||
return _innov_cov; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,8 @@ | |
// TODO: rename to KF_position and clean up comments | ||
|
||
/** | ||
* @file KF_position_moving.h | ||
* @brief Filter to estimate the pose of moving targets. State: [r, vd, b, at, vt] | ||
* @file KF_orientation.h | ||
* @brief Filter to estimate the orientation of moving targets. State: [yaw, yaw_rate] | ||
* | ||
* @author Jonas Perolini <[email protected]> | ||
* | ||
|
@@ -45,12 +45,19 @@ | |
#include <mathlib/mathlib.h> | ||
#include <matrix/Matrix.hpp> | ||
#include <matrix/Vector.hpp> | ||
#include "python_derivation/generated/state.h" | ||
|
||
#pragma once | ||
|
||
namespace vision_target_estimator | ||
{ | ||
|
||
namespace State | ||
{ | ||
static constexpr uint8_t yaw{0}; | ||
static constexpr uint8_t yaw_rate{1}; | ||
static constexpr uint8_t size{2}; | ||
}; | ||
|
||
class KF_orientation_unified | ||
{ | ||
public: | ||
|
@@ -71,20 +78,20 @@ class KF_orientation_unified | |
// Backwards state prediciton | ||
void syncState(float dt); | ||
|
||
void setH(const matrix::Vector<float, vtest::State::size> &h_meas) {_meas_matrix_row_vect = h_meas;} | ||
void setH(const matrix::Vector<float, State::size> &h_meas) {_meas_matrix_row_vect = h_meas;} | ||
|
||
void setState(const matrix::Vector<float, vtest::State::size> &state) {_state = state;} | ||
void setState(const matrix::Vector<float, State::size> &state) {_state = state;} | ||
|
||
void setStateVar(const matrix::Vector<float, vtest::State::size> &var) | ||
void setStateVar(const matrix::Vector<float, State::size> &var) | ||
{ | ||
const matrix::SquareMatrix<float, vtest::State::size> var_mat = diag(var); | ||
const matrix::SquareMatrix<float, State::size> var_mat = diag(var); | ||
_state_covariance = var_mat; | ||
}; | ||
|
||
matrix::Vector<float, vtest::State::size> getState() { return _state;} | ||
matrix::Vector<float, vtest::State::size> getStateVar() | ||
matrix::Vector<float, State::size> getState() { return _state;} | ||
matrix::Vector<float, State::size> getStateVar() | ||
{ | ||
const matrix::SquareMatrix<float, vtest::State::size> var_mat = _state_covariance; | ||
const matrix::SquareMatrix<float, State::size> var_mat = _state_covariance; | ||
return var_mat.diag(); | ||
}; | ||
|
||
|
@@ -99,13 +106,24 @@ class KF_orientation_unified | |
|
||
private: | ||
|
||
matrix::Vector<float, vtest::State::size> _state; | ||
matrix::SquareMatrix<float, State::size> getPhi(float dt) | ||
{ | ||
|
||
float data[State::size * State::size] = { | ||
1, dt, | ||
0, 1 | ||
}; | ||
|
||
return matrix::SquareMatrix<float, State::size>(data); | ||
} | ||
|
||
matrix::Vector<float, State::size> _state; | ||
|
||
matrix::Vector<float, vtest::State::size> _sync_state; | ||
matrix::Vector<float, State::size> _sync_state; | ||
|
||
matrix::Vector<float, vtest::State::size> _meas_matrix_row_vect; | ||
matrix::Vector<float, State::size> _meas_matrix_row_vect; | ||
|
||
matrix::Matrix<float, vtest::State::size, vtest::State::size> _state_covariance; | ||
matrix::Matrix<float, State::size, State::size> _state_covariance; | ||
|
||
float _innov{0.0f}; // residual of last measurement update | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 0 additions & 150 deletions
150
src/modules/vision_target_estimator/Orientation/python_derivation/KF_unified.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.