Spacecraft Control Framework 1.0
Spacecraft Control Library
sc_ukf.h
Go to the documentation of this file.
1/*
2 * sc_ukf.h
3 *
4 * Copyright 2007, Princeton Satellite Systems. All rights reserved.
5 *
6 * Unscented Kalman Filter object.
7 *
8 * Based on UKF.m and UKFP.m in Toolboxes/Aerospace/Estimation.
9 *
10 */
11
17#ifdef AS_OS_WINDOWS
18#include "matrixlib.h"
19#else
20#include <MatrixLib/MatrixLib.h>
21#endif
22
23/*
24 Note: I'm not crazy about the way parameter mode operates; it currently mimics the
25 Matlab version in the toolbox. But the way that there are several versions
26 of the parameters, and how these need to be carefully maintained across
27 calls to the RHS function, is an area of concern; it's not nearly as clean
28 as I'd like it.
29 */
30
31#ifndef __SC_UKF__
32#define __SC_UKF__
33
35typedef ml_matrix (*state_func) (ml_matrix x, double t,void *context);
37typedef ml_matrix (*integ_func) (state_func state_fun, ml_matrix &x, double h, double t,void *context);
39typedef ml_matrix (*meas_func) (const ml_matrix &state,void *context);
40
42typedef enum {
43 UKF_mode_unset = -1,
44 UKF_mode_state,
45 UKF_mode_parameter
46} UKF_mode;
47
73class UKF {
74public:
76 UKF();
78 ~UKF();
79
81 void set_filter_mode (UKF_mode mode);
83 void set_filter_parameters (const double alpha, const double kappa, const double beta);
85 void set_integrator_time_info (double t, double dt);
87 void set_initial_values (const ml_matrix &state0, const ml_matrix &covariance0, const ml_matrix &parameter0 = ml_matrix());
89 void set_noise_covariances (const ml_matrix &Rp, const ml_matrix &Rm);
91 void set_state_function (state_func state_fun);
93 void set_integrator (integ_func integ_fun);
95 void set_measurement_function (meas_func meas_fun);
97 void set_context(void *context);
99 void set_state( const ml_matrix &state0 );
101 ml_matrix current_state (void) const { return *state; }
103 ml_matrix current_residual (void) const { return *residual; }
105 ml_matrix current_parameter (void) const { return *parameter; }
107 ml_matrix current_covariance (void) const { return *covariance; }
109 ml_matrix current_residual_covariance (void) const {return * residual_covariance; }
111 ml_matrix current_rhs_params (void) const { return rhs_params; }
113 void update_estimate (const ml_matrix &measurement);
114
115private:
117 UKF (const UKF &u);
119 UKF & operator= (const UKF &u);
120
122 ml_matrix calculate_sigma_points (const ml_matrix &x, const ml_matrix &P);
123
125 void update_estimate_state (const ml_matrix &measurement);
126
128 void update_estimate_parameter (const ml_matrix &measurement);
129
131 UKF_mode mode;
132
134 unsigned int n;
136 ml_matrix *state;
138 ml_matrix *parameter;
140 ml_matrix *covariance;
141
143 ml_matrix *process_noise_cov;
145 ml_matrix *meas_noise_cov;
146
148 state_func state_fp;
150 integ_func integ_fp;
152 meas_func meas_fp;
154 void *ctx;
155
157 ml_matrix rhs_params;
158
160 double alpha;
162 double kappa;
164 double beta;
166 double t;
168 double dt;
169
170 // internal
171
173 double lambda;
175 ml_matrix *Wm;
177 ml_matrix *Wc;
179 ml_matrix *residual;
181 ml_matrix *residual_covariance;
182};
183
184#endif
Unscented Kalman Filter class.
Definition: sc_ukf.h:73
ml_matrix current_rhs_params(void) const
Returns the current RHS parameters (only used in parameter mode).
Definition: sc_ukf.h:111
void update_estimate(const ml_matrix &measurement)
Updates the current estimate.
Definition: sc_ukf.cc:210
void set_filter_mode(UKF_mode mode)
Sets the filter mode.
Definition: sc_ukf.cc:72
void set_filter_parameters(const double alpha, const double kappa, const double beta)
Sets the filter parameters.
Definition: sc_ukf.cc:83
void set_state(const ml_matrix &state0)
Sets the current state.
Definition: sc_ukf.cc:105
void set_state_function(state_func state_fun)
Sets the state function.
Definition: sc_ukf.cc:172
ml_matrix current_covariance(void) const
Returns the current estimated covariance.
Definition: sc_ukf.h:107
ml_matrix current_state(void) const
Returns the current estimated state.
Definition: sc_ukf.h:101
void set_context(void *context)
Sets the context pointer for data needed by the state or measurement functions.
Definition: sc_ukf.cc:199
void set_integrator_time_info(double t, double dt)
Sets the integrator time and time step.
Definition: sc_ukf.cc:95
UKF()
Constructor.
Definition: sc_ukf.cc:38
ml_matrix current_parameter(void) const
Returns the current estimated parameter.
Definition: sc_ukf.h:105
ml_matrix current_residual_covariance(void) const
Returns the current residual covariance.
Definition: sc_ukf.h:109
void set_integrator(integ_func integ_fun)
Sets the integrator function.
Definition: sc_ukf.cc:181
void set_noise_covariances(const ml_matrix &Rp, const ml_matrix &Rm)
Sets the noise covariance matrices.
Definition: sc_ukf.cc:151
void set_initial_values(const ml_matrix &state0, const ml_matrix &covariance0, const ml_matrix &parameter0=ml_matrix())
Sets the initial state and covariance.
Definition: sc_ukf.cc:117
void set_measurement_function(meas_func meas_fun)
Sets the measurement function.
Definition: sc_ukf.cc:190
ml_matrix current_residual(void) const
Returns the current residual.
Definition: sc_ukf.h:103
~UKF()
Destructor.
Definition: sc_ukf.cc:51
ml_matrix(* meas_func)(const ml_matrix &state, void *context)
A function used to provide the measurement vector.
Definition: sc_ukf.h:39
ml_matrix(* state_func)(ml_matrix x, double t, void *context)
A function used to propagate the state vector.
Definition: sc_ukf.h:35
ml_matrix(* integ_func)(state_func state_fun, ml_matrix &x, double h, double t, void *context)
A function used to integrate the state vector.
Definition: sc_ukf.h:37
UKF_mode
Determines in which state the filter operates.
Definition: sc_ukf.h:42