Skip to content

Commit 0e8d69d

Browse files
remipchRemi Peuchot
andauthored
Allow direct process model (#63)
* Add 'NotUsedIntegrator' placeholder to express that the integrator is not needed when process model is implemented directly (instead of derivative process model) * Allow to implement direct process model instead of derivative process model --------- Co-authored-by: Remi Peuchot <remi.peuchot@ecorobotix.com>
1 parent 3b667e8 commit 0e8d69d

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

include/UKF/Core.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SOFTWARE.
2727
#include <Eigen/Geometry>
2828
#include "UKF/Types.h"
2929
#include "UKF/StateVector.h"
30+
#include <type_traits>
3031

3132
namespace UKF {
3233

@@ -45,7 +46,7 @@ The attitude-related code makes use of the MRP method described in the paper
4546
"Unscented Filtering for Spacecraft Attitude Estimation" by John L. Crassidis
4647
and F. Landis Markley.
4748
*/
48-
template <typename StateVectorType, typename MeasurementVectorType, typename IntegratorType>
49+
template <typename StateVectorType, typename MeasurementVectorType, typename IntegratorType=NotUsedIntegrator>
4950
class Core {
5051
protected:
5152
typename StateVectorType::SigmaPointDistribution sigma_points;
@@ -111,8 +112,13 @@ class Core {
111112

112113
/* Propagate the sigma points through the process model. */
113114
for(std::size_t i = 0; i < StateVectorType::num_sigma(); i++) {
114-
sigma_points.col(i) <<
115-
StateVectorType(sigma_points.col(i)).template process_model<IntegratorType>(delta, input...);
115+
if (std::is_same_v<IntegratorType, NotUsedIntegrator>) {
116+
sigma_points.col(i) << StateVectorType(sigma_points.col(i)).process_model(delta, input...);
117+
}
118+
else {
119+
sigma_points.col(i) << StateVectorType(sigma_points.col(i))
120+
.template process_model<IntegratorType>(delta, input...);
121+
}
116122
}
117123

118124
/* Calculate the a priori estimate mean, deltas and covariance. */

include/UKF/Integrator.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ SOFTWARE.
2727

2828
namespace UKF {
2929

30+
/* When we want a direct process model (avoid to integrate the process model derivative). */
31+
class NotUsedIntegrator {
32+
public:
33+
template <typename S, typename... U>
34+
static S integrate(real_t delta, const S& state, const U&... input) {
35+
throw std::runtime_error("NotUsedIntegrator is not supposed to be used");
36+
}
37+
};
38+
3039
/* Fourth-order integrator. */
3140
class IntegratorRK4 {
3241
public:

include/UKF/StateVector.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ class StateVector : public StateVectorBaseType<typename Fields::type...> {
428428
This function calculates the derivative of the state vector. The
429429
derivative can be a function of the current state and any number of user-
430430
supplied non-state inputs.
431+
It must be implemented if the core does not use "NotUsedIntegrator"
431432
*/
432433
template <typename... U>
433434
StateVector derivative(const U&... input) const;
@@ -437,11 +438,18 @@ class StateVector : public StateVectorBaseType<typename Fields::type...> {
437438
state based on the supplied time delta. This is achieved by using a
438439
numerical integrator and the derivative function.
439440
*/
440-
template <typename IntegratorType = IntegratorRK4, typename... U>
441+
template <typename IntegratorType , typename... U>
441442
StateVector process_model(real_t delta, const U&... input) const {
442443
return IntegratorType::integrate(delta, *this, input...);
443444
}
444445

446+
/*
447+
Apply the direct process model (without derivative).
448+
It must be implemented if the core use "NotUsedIntegrator"
449+
*/
450+
template <typename... U>
451+
StateVector process_model(real_t delta, const U&... input) const;
452+
445453
/* Update the state vector using a delta vector. */
446454
void apply_delta(const StateVectorDelta& delta) {
447455
apply_field_deltas<Fields...>(delta);

0 commit comments

Comments
 (0)