34 #include <StateEstimator/IteratedExtendedKalman.hh>
35 #include <Base/Math/Random.hh>
57 prediction[0] = state[0] + control[0]*state[1];
59 prediction[1] = state[1];
69 transJacobian[0][0] = 1;
70 transJacobian[0][1] = control[0];
71 transJacobian[1][0] = 0;
72 transJacobian[1][1] = 1;
76 transErrorJacobian[0][0] = 1;
77 transErrorJacobian[0][1] = 0;
78 transErrorJacobian[1][0] = 0;
79 transErrorJacobian[1][1] = 1;
85 const unsigned int index=1)
90 measurePred[0] = state[0]*state[0]*state[0];
94 measurePred[0] = state[1]*state[1]*state[1]+10*state[1];
97 BIASERR(
"Unknown measurement called!");
106 const unsigned int index=1)
111 measJacobian[0][0] = 3*state[0];
112 measJacobian[0][1] = 0;
114 measErrorJacobian[0][0] = 1;
118 measJacobian[0][0] = 0;
119 measJacobian[0][1] = 3*state[1]+10;
121 measErrorJacobian[0][0] = 1;
124 BIASERR(
"Unknown measurement called!");
131 int main(
int argc,
char *argv[]) {
134 cout <<
"Usage: " << argv[0]
135 <<
" stateHistFile truePosFile measure1File measure2File!" << endl;
140 unsigned int simLength = 500;
141 unsigned int rSeed = 0;
148 vector< BIAS::Vector<double> > measTrue1(simLength);
150 vector< BIAS::Vector<double> > measTrue2(simLength);
152 vector< BIAS::Vector<double> > measNoise1(simLength);
154 vector< BIAS::Vector<double> > measNoise2(simLength);
156 vector< BIAS::Vector<double> > stateHist(simLength);
158 vector< BIAS::Matrix<double> > covHist(simLength);
161 double sigmaM1 = 0.1;
163 double sigmaM2 = 0.01;
167 Q[0][0] = 0.001; Q[0][1] = 0.0; Q[1][0] = 0.0; Q[1][1] = 1e-5;
170 PI[0][0] = 0.001; PI[0][1] = 0.0; PI[1][0] = 0.0; PI[1][1] = 1;
180 for (
unsigned int i=0; i<simLength; i++) {
182 posTrue[i] = sin(10*M_PI*
double(i)/
double(simLength));
183 posTrue[i] = 0.25*posTrue[i]*posTrue[i]+1.0;
185 velTrue[i] = 5.0*M_PI/double(simLength)
186 *sin(10*M_PI*
double(i)/
double(simLength))
187 *cos(10*M_PI*
double(i)/
double(simLength));
189 measTrue1[i].newsize(1);
190 measTrue1[i][0] = posTrue[i]*posTrue[i]*posTrue[i];
192 measTrue2[i].newsize(1);
193 measTrue2[i][0] = velTrue[i]*velTrue[i]*velTrue[i]+10*velTrue[i];
196 stateHist[i].newsize(2);
201 for (
unsigned int i=0; i<simLength; i++) {
203 measNoise1[i][0] = measTrue1[i][0] +
204 rand.GetNormalDistributed (0.0, sigmaM1);
205 measNoise2[i].newsize(1);
206 measNoise2[i][0] = measTrue2[i][0] +
207 rand.GetNormalDistributed (0.0, sigmaM2);
216 initial[0] = posTrue[0]; initial[1] = 0.0;
217 estimator.Init(initial, PI, Q);
220 for (
unsigned int i=0; i<simLength; i++) {
222 estimator.Update(measNoise1[i], R_1, 1);
224 estimator.Update(measNoise2[i], R_2, 2);
226 estimator.GetPosterioriState(stateHist[i]);
227 estimator.GetPosterioriCovariance(covHist[i]);
229 estimator.Predict(control);
233 ofstream estFile(argv[1]);
234 ofstream gtFile(argv[2]);
235 ofstream meas1File(argv[3]);
236 ofstream meas2File(argv[4]);
237 for (
unsigned int i=0; i < simLength; i++) {
238 estFile << stateHist[i][0] <<
" " << stateHist[i][1] <<
" "
239 << sqrt(covHist[i][0][0]) << sqrt(covHist[i][1][1]) << endl;
240 gtFile << posTrue[i] <<
" " << velTrue[i] << endl;
241 meas1File << measNoise1[i][0] << endl;
242 meas2File << measNoise2[i][0] << endl;
Iterated Extended Kalman-filter (IEKF).
Matrix< T > & newsize(Subscript M, Subscript N)
class for producing random numbers from different distributions