Spacecraft Control Framework 1.0
Spacecraft Control Library
sc_ukf_2.h
1//
2// sc_ukf_2.h
3// SCControl
4//
5// Created by Eric Ham on 6/12/16.
6//
7// Implements an Unscented Kalman Filter using separate predict and update functions
8// Uses the Unscented Transformation to simplify the code.
9// The sigma points are computed using a Cholesky transform.
10//
11//
12
13#ifndef __SCControl__sc_ukf_2__
14#define __SCControl__sc_ukf_2__
15
16#include <stdio.h>
17#ifdef AS_OS_WINDOWS
18#include "matrixlib.h"
19#else
20#include <MatrixLib/MatrixLib.h>
21#endif
22
24typedef ml_matrix (*state_func) (ml_matrix x, double t,void *context);
26typedef ml_matrix (*integ_func) (state_func state_fun, ml_matrix &x, double h, double t,void *context);
28typedef ml_matrix (*propagate_func) (const ml_matrix &state, void *context);
30typedef ml_matrix (*meas_2_func) (const ml_matrix &state,void *context);
31
32
33class UKF2 {
34
35 //instance variables
36 private:
37 ml_matrix r;
38 ml_matrix v;
39 ml_matrix m;
40 ml_matrix p;
41 ml_matrix q;
42 ml_matrix w;
43 ml_matrix wM;
44 ml_matrix y;
45 double alpha;
46 double kappa;
47 double beta;
48 double nL;
49 double c;
50 double dT;
51 void weight_matrix(void);
52 bool has_propagate_function = false;
53
54 // methods
55 public:
57 UKF2(void);
59 ~UKF2();
61 void initialize(void);
63 void predict(void);
65 void update(void);
67 void set_state_covariance(const ml_matrix & q) { this->q = q; }
69 void set_measurement_covariance(const ml_matrix & r) { this->r = r; }
71 void set_mean(const ml_matrix & m) { this->m = m; }
73 void set_measurement(const ml_matrix & y) { this->y = y; }
75 void set_covariance(const ml_matrix & p){ this->p = p;}
77 void set_filter_parameters(double alpha, double kappa, double beta){ this->alpha = alpha; this->kappa = kappa; this->beta = beta;}
79 void set_integrator_time_step(double dT){this->dT = dT;};
81 void set_state_function (state_func state_fun){state_fp = state_fun; has_propagate_function = false;};
83 void set_integrator (integ_func integ_fun){integ_fp = integ_fun; has_propagate_function = false;};
85 void set_measurement_function (meas_2_func meas_fun){meas_fp = meas_fun;};
87 void set_propagate_function (propagate_func propagate_fun){propagate_fp = propagate_fun; has_propagate_function = true;};
89 void set_context_rhs(void *context){ctx_rhs = context;};
91 void set_context_meas(void *context){ctx_meas = context;};
93 ml_matrix get_mean(void) { return m;}
95 ml_matrix get_covariance(void) { return p;}
97 ml_matrix get_residual(void) { return v;}
103 meas_2_func meas_fp;
105 propagate_func propagate_fp;
107 void *ctx_rhs;
109 void *ctx_meas;
110
111};
112
113
114#endif /* defined(__SCControl__sc_ukf_2__) */
Definition: sc_ukf_2.h:33
ml_matrix get_mean(void)
Get the mean value.
Definition: sc_ukf_2.h:93
ml_matrix get_residual(void)
Get the measurement residual.
Definition: sc_ukf_2.h:97
void set_integrator_time_step(double dT)
Set the integrator time step.
Definition: sc_ukf_2.h:79
void update(void)
Perform a measurement update.
Definition: sc_ukf_2.cc:73
void set_integrator(integ_func integ_fun)
Set the integrator function.
Definition: sc_ukf_2.h:83
void predict(void)
Perform a prediction.
Definition: sc_ukf_2.cc:28
void * ctx_rhs
The context pointer provided to the propagate and right hand side functions.
Definition: sc_ukf_2.h:107
void set_state_covariance(const ml_matrix &q)
Set the state covariance.
Definition: sc_ukf_2.h:67
void set_filter_parameters(double alpha, double kappa, double beta)
Set the UKF parameters.
Definition: sc_ukf_2.h:77
void set_mean(const ml_matrix &m)
Set the mean value.
Definition: sc_ukf_2.h:71
void set_measurement_covariance(const ml_matrix &r)
Set the measurement covariance.
Definition: sc_ukf_2.h:69
void set_measurement_function(meas_2_func meas_fun)
Set the measurement function.
Definition: sc_ukf_2.h:85
UKF2(void)
Constructor.
Definition: sc_ukf_2.cc:12
void initialize(void)
Initialize the filter.
Definition: sc_ukf_2.cc:23
void * ctx_meas
The context pointer provided to the measurement functions.
Definition: sc_ukf_2.h:109
void set_context_rhs(void *context)
Set the context pointer for data needed by the state functions.
Definition: sc_ukf_2.h:89
integ_func integ_fp
The integrator used to propagate the state.
Definition: sc_ukf_2.h:101
void set_measurement(const ml_matrix &y)
Set the measurement.
Definition: sc_ukf_2.h:73
meas_2_func meas_fp
The measurement function.
Definition: sc_ukf_2.h:103
void set_propagate_function(propagate_func propagate_fun)
Set the measurement function.
Definition: sc_ukf_2.h:87
~UKF2()
Destructor.
Definition: sc_ukf_2.cc:18
ml_matrix get_covariance(void)
Get the covariance.
Definition: sc_ukf_2.h:95
void set_state_function(state_func state_fun)
Set the state function.
Definition: sc_ukf_2.h:81
propagate_func propagate_fp
The propagate function.
Definition: sc_ukf_2.h:105
void set_covariance(const ml_matrix &p)
Set the covariance.
Definition: sc_ukf_2.h:75
state_func state_fp
The state propagation right hand side.
Definition: sc_ukf_2.h:99
void set_context_meas(void *context)
Set the context pointer for data needed by the measurement functions.
Definition: sc_ukf_2.h:91
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