31 #include <Base/Math/Random.hh>
32 #include <StateEstimator/Kalman.hh>
37 const double meas_noise = 2.0;
38 const double process_noise = 1.0;
46 const int dim = res.
Size();
49 for (
int i=0; i<dim; i++){
64 const int meas_dim = meas.
Size();
65 for (
int r=0; r<meas_dim; r++){
67 meas_cov[r][r] = std_dev * std_dev;
68 meas[r] = gt_meas[r] +
75 int main(
int ,
char ** )
77 const int state_dim = 2;
78 const int meas_dim = 2;
90 meas_cov(meas_dim, meas_dim),
91 update_cov(state_dim, state_dim),
92 process_covariance(state_dim, state_dim);
96 for (
int r=0; r<state_dim; r++){
98 process_covariance[r][r] = std_dev * std_dev;
103 for (
int r=0; r<state_dim; r++){
106 pred_cov[r][r] = std_dev * std_dev;
110 cout <<
"# ground truth system state: " << state
111 <<
"\n# intial system state guess: " << pred
112 <<
"\n# covariance matrix of initial system state guess: "
116 kafi.
Init(A, H, pred, pred_cov);
118 const int num_cycles=100;
119 cout <<
"# time\tstate\t\tpred\t\tpred_cov\tmeas\t\tmeas-cov\tup\t\tup-cov\n";
120 for (
int i=0; i<num_cycles; i++){
122 state = Process(A, state, process_covariance);
125 kafi.
Predict(process_covariance);
130 GenerateNoisyMeasurements(state, H, meas, meas_cov);
133 kafi.
Update(meas, meas_cov);
138 for (
int d=0; d<state_dim; d++){
139 cout <<
"\t"<<state[d] <<
"\t" << pred[d]
140 <<
"\t"<<sqrt(pred_cov[d][d])<<
"\t";
142 cout << meas[d] <<
"\t" << sqrt(meas_cov[d][d]) <<
"\t" ;
144 cout <<
"nan" <<
"\t" <<
"nan" <<
"\t";
146 cout << update[d] <<
"\t"
147 << sqrt(update_cov[d][d]);
void Init(const Matrix< double > &SystemMatrix, const Matrix< double > &MeasurementMatrix, const Vector< double > &InitialSystemState, const Matrix< double > &InitialSystemCovariance)
unsigned int Size() const
length of the vector
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
void SetZero()
Sets all values to zero.
void Update(const Vector< double > &Measurement, const Matrix< double > &MeasurementCovariance)
Calculates the update step.
void GetState(Vector< double > &state) const
Returns the system state.
void Predict(const Matrix< double > &ProcessCovariance)
Calculates the prediction using the system matrix A.
void GetCovariance(Matrix< double > &cov) const
Returns the system state covariance.
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
class for producing random numbers from different distributions