test_nonlinear_kalman.cpp
Go to the documentation of this file.
00001 // $Id: kalman_mobile.cpp 5925 2006-03-14 21:23:49Z tdelaet $
00002 // Copyright (C) 2006 Tinne De Laet <first dot last at mech dot kuleuven dot be>
00003 //
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published by
00006 // the Free Software Foundation; either version 2.1 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018 /* Demonstration program for the Bayesian Filtering Library.
00019    Mobile robot localization with respect to wall with different possibilities for filter
00020 */
00021 
00022 
00023 #include <filter/extendedkalmanfilter.h>
00024 
00025 #include <model/linearanalyticsystemmodel_gaussianuncertainty.h>
00026 #include <model/linearanalyticmeasurementmodel_gaussianuncertainty.h>
00027 
00028 #include <pdf/analyticconditionalgaussian.h>
00029 #include <pdf/linearanalyticconditionalgaussian.h>
00030 #include "../nonlinearanalyticconditionalgaussian3D.h"//added
00031 
00032 #include "../mobile_robot.h"
00033 
00034 #include <iostream>
00035 #include <fstream>
00036 
00037 // Include file with properties
00038 #include "../mobile_robot_wall_cts.h"
00039 
00040 using namespace MatrixWrapper;
00041 using namespace BFL;
00042 using namespace std;
00043 
00044 
00045 
00046 /* The purpose of this program is to construct a kalman filter for the problem
00047   of localisation of a mobile robot equipped with an ultrasonic sensor.
00048   In this case the orientation is known, which simplifies the model considerably:
00049   The system model will become linear.
00050   The ultrasonic measures the distance to the wall (it can be switched off:
00051   see mobile_robot_wall_cts.h)
00052 
00053   The necessary SYSTEM MODEL is:
00054 
00055   x_k      = x_{k-1} + v_{k-1} * cos(theta) * delta_t
00056   y_k      = y_{k-1} + v_{k-1} * sin(theta) * delta_t
00057 
00058   The used MEASUREMENT MODEL:
00059   measuring the (perpendicular) distance z to the wall y = ax + b
00060 
00061   set WALL_CT = 1/sqrt(pow(a,2) + 1)
00062   z = WALL_CT * a * x - WALL_CT * y + WALL_CT * b + GAUSSIAN_NOISE
00063   or Z = H * X_k + J * U_k
00064 
00065   where
00066 
00067   H = [ WALL_CT * a       - WALL_CT      0 ]
00068   and GAUSSIAN_NOISE = N((WALL_CT * b), SIGMA_MEAS_NOISE)
00069 
00070 */
00071 
00072 
00073 int main(int argc, char** argv)
00074 {
00075   cerr << "==================================================" << endl
00076        << "Test of kalman filter" << endl
00077        << "Mobile robot localisation example" << endl
00078        << "==================================================" << endl;
00079 
00080 
00081   /****************************
00082    * NonLinear system model      *
00083    ***************************/
00084 
00085   // create gaussian
00086   ColumnVector sys_noise_Mu(STATE_SIZE);
00087   sys_noise_Mu(1) = MU_SYSTEM_NOISE_X;
00088   sys_noise_Mu(2) = MU_SYSTEM_NOISE_Y;
00089   sys_noise_Mu(3) = MU_SYSTEM_NOISE_THETA;
00090 
00091   SymmetricMatrix sys_noise_Cov(STATE_SIZE);
00092   sys_noise_Cov = 0.0;
00093   sys_noise_Cov(1,1) = SIGMA_SYSTEM_NOISE_X;
00094   sys_noise_Cov(1,2) = 0.0;
00095   sys_noise_Cov(1,3) = 0.0;
00096   sys_noise_Cov(2,1) = 0.0;
00097   sys_noise_Cov(2,2) = SIGMA_SYSTEM_NOISE_Y;
00098   sys_noise_Cov(2,3) = 0.0;
00099   sys_noise_Cov(3,1) = 0.0;
00100   sys_noise_Cov(3,2) = 0.0;
00101   sys_noise_Cov(3,3) = SIGMA_SYSTEM_NOISE_THETA;
00102 
00103   Gaussian system_Uncertainty(sys_noise_Mu, sys_noise_Cov);
00104 
00105   // create the model
00106   NonLinearAnalyticConditionalGaussianMobile sys_pdf(system_Uncertainty);
00107   AnalyticSystemModelGaussianUncertainty sys_model(&sys_pdf);
00108 
00109   /*********************************
00110    * Initialise measurement model *
00111    ********************************/
00112 
00113   // create matrix H for linear measurement model
00114   double wall_ct = 2/(sqrt(pow(RICO_WALL,2.0) + 1));
00115   Matrix H(MEAS_SIZE,STATE_SIZE);
00116   H = 0.0;
00117   H(1,1) = wall_ct * RICO_WALL;
00118   H(1,2) = 0 - wall_ct;
00119   H(1,3) = 0.0;
00120   // Construct the measurement noise (a scalar in this case)
00121   ColumnVector meas_noise_Mu(MEAS_SIZE);
00122   meas_noise_Mu(1) = MU_MEAS_NOISE;
00123 
00124   SymmetricMatrix meas_noise_Cov(MEAS_SIZE);
00125   meas_noise_Cov(1,1) = SIGMA_MEAS_NOISE;
00126   Gaussian measurement_Uncertainty(meas_noise_Mu, meas_noise_Cov);
00127 
00128   // create the measurement model
00129   LinearAnalyticConditionalGaussian meas_pdf(H, measurement_Uncertainty);
00130   LinearAnalyticMeasurementModelGaussianUncertainty meas_model(&meas_pdf);
00131 
00132   /****************************
00133    * Linear prior DENSITY     *
00134    ***************************/
00135    // Continuous Gaussian prior (for Kalman filters)
00136   ColumnVector prior_Mu(STATE_SIZE);
00137   prior_Mu(1) = PRIOR_MU_X;
00138   prior_Mu(2) = PRIOR_MU_Y;
00139   prior_Mu(3) = PRIOR_MU_THETA;
00140   SymmetricMatrix prior_Cov(STATE_SIZE);
00141   prior_Cov(1,1) = PRIOR_COV_X;
00142   prior_Cov(1,2) = 0.0;
00143   prior_Cov(1,3) = 0.0;
00144   prior_Cov(2,1) = 0.0;
00145   prior_Cov(2,2) = PRIOR_COV_Y;
00146   prior_Cov(2,3) = 0.0;
00147   prior_Cov(3,1) = 0.0;
00148   prior_Cov(3,2) = 0.0;
00149   prior_Cov(3,3) = PRIOR_COV_THETA;
00150   Gaussian prior_cont(prior_Mu,prior_Cov);
00151 
00152   /******************************
00153    * Construction of the Filter *
00154    ******************************/
00155   ExtendedKalmanFilter filter(&prior_cont);
00156 
00157   /***************************
00158    * initialise MOBILE ROBOT *
00159    **************************/
00160   // Model of mobile robot in world with one wall
00161   // The model is used to simultate the distance measurements.
00162   MobileRobot mobile_robot;
00163   ColumnVector input(2);
00164   input(1) = 0.1;
00165   input(2) = 0.0;
00166 
00167 
00168 
00169 
00170   /*******************
00171    * ESTIMATION LOOP *
00172    *******************/
00173   cout << "MAIN: Starting estimation" << endl;
00174   unsigned int time_step;
00175   for (time_step = 0; time_step < NUM_TIME_STEPS-1; time_step++)
00176     {
00177       // DO ONE STEP WITH MOBILE ROBOT
00178       mobile_robot.Move(input);
00179 
00180       // DO ONE MEASUREMENT
00181       ColumnVector measurement = mobile_robot.Measure();
00182 
00183       // UPDATE FILTER
00184       filter.Update(&sys_model,input,&meas_model,measurement);
00185       //filter.Update(&sys_model,input);
00186 
00187     } // estimation loop
00188 
00189 
00190 
00191   Pdf<ColumnVector> * posterior = filter.PostGet();
00192   cout << "After " << time_step+1 << " timesteps " << endl;
00193   cout << " Posterior Mean = " << endl << posterior->ExpectedValueGet() << endl
00194        << " Covariance = " << endl << posterior->CovarianceGet() << "" << endl;
00195 
00196 
00197   cout << "======================================================" << endl
00198        << "End of the Kalman filter for mobile robot localisation" << endl
00199        << "======================================================"
00200        << endl;
00201 
00202 
00203   return 0;
00204 }


ekf_localization
Author(s):
autogenerated on Sat Jun 8 2019 20:11:55