MBot Software Library  v1.0
An API documentation to mbot_firmware repository
kalman.h
1 
67 #ifndef RC_KALMAN_H
68 #define RC_KALMAN_H
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 #include <stdint.h>
75 #include <rc/math/vector.h>
76 #include <rc/math/matrix.h>
77 
78 
79 /*
80  * @brief Struct to contain full state of kalman filter
81  */
82 typedef struct rc_kalman_t {
89 
97 
103 
107  uint64_t step;
109 } rc_kalman_t;
110 
111 #define RC_KALMAN_INITIALIZER {\
112  .F = RC_MATRIX_INITIALIZER,\
113  .G = RC_MATRIX_INITIALIZER,\
114  .H = RC_MATRIX_INITIALIZER,\
115  .Q = RC_MATRIX_INITIALIZER,\
116  .R = RC_MATRIX_INITIALIZER,\
117  .P = RC_MATRIX_INITIALIZER,\
118  .Pi = RC_MATRIX_INITIALIZER,\
119  .x_est = RC_VECTOR_INITIALIZER,\
120  .x_pre = RC_VECTOR_INITIALIZER,\
121  .initialized = 0,\
122  .step = 0}
123 
139 
154 
166 
167 
176 int rc_kalman_free(rc_kalman_t* kf);
177 
178 
189 
190 
216 
217 
245 
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif // RC_KALMAN_H
252 
int rc_kalman_reset(rc_kalman_t *kf)
reset state and dynamics of the filter to 0
Definition: kalman.c:140
rc_kalman_t rc_kalman_empty(void)
Critical function for initializing rc_kalman_t structs.
Definition: kalman.c:14
int rc_kalman_alloc_ekf(rc_kalman_t *kf, rc_matrix_t Q, rc_matrix_t R, rc_matrix_t Pi)
Allocates memory for a Kalman filter of given dimensions.
Definition: kalman.c:80
int rc_kalman_update_ekf(rc_kalman_t *kf, rc_matrix_t F, rc_matrix_t H, rc_vector_t x_pre, rc_vector_t y, rc_vector_t h)
Kalman Filter measurement update step.
Definition: kalman.c:250
int rc_kalman_free(rc_kalman_t *kf)
Frees the memory allocated by a kalman filter's matrices and vectors. Also resets all values to 0 lik...
Definition: kalman.c:115
int rc_kalman_alloc_lin(rc_kalman_t *kf, rc_matrix_t F, rc_matrix_t G, rc_matrix_t H, rc_matrix_t Q, rc_matrix_t R, rc_matrix_t Pi)
Allocates memory for a Kalman filter of given dimensions.
Definition: kalman.c:21
int rc_kalman_update_lin(rc_kalman_t *kf, rc_vector_t u, rc_vector_t y)
Kalman Filter state prediction step based on physical model.
Definition: kalman.c:159
Definition: kalman.h:82
rc_matrix_t H
observation-model
Definition: kalman.h:87
rc_vector_t x_est
Estimated state x[k|k] = x[k|k-1],y[k])
Definition: kalman.h:100
uint64_t step
counts times rc_kalman_measurement_update has been called
Definition: kalman.h:107
rc_matrix_t G
control input model
Definition: kalman.h:86
rc_matrix_t R
Measurement noise covariance set by user.
Definition: kalman.h:93
rc_matrix_t Q
Process noise covariance set by user.
Definition: kalman.h:92
int initialized
set to 1 once initialized with rc_kalman_alloc
Definition: kalman.h:106
rc_matrix_t F
undriven state-transition model
Definition: kalman.h:85
rc_vector_t x_pre
Predicted state x[k|k-1] = f(x[k-1],u[k])
Definition: kalman.h:101
rc_matrix_t Pi
Initial P matrix set by user.
Definition: kalman.h:95
rc_matrix_t P
Predicted state error covariance calculated by the update functions.
Definition: kalman.h:94
Struct containing the state of a matrix and a pointer to dynamically allocated memory to hold its con...
Definition: matrix.h:32
Struct containing the state of a vector and a pointer to dynamically allocated memory to hold its con...
Definition: vector.h:41