MobileRobotParticleFilterModel.cpp

00001 #include "MobileRobotParticleFilterModel.hpp"
00002 
00003 #define SYSTEM_SIZE 2
00004 #define MEAS_SIZE 1
00005 
00006 MobileRobotParticleFilterModel::MobileRobotParticleFilterModel(
00007     const double vel, const double ang) :
00008     w(SYSTEM_SIZE), v(MEAS_SIZE), vel(vel), ang(ang) {
00009   aux::vector mu(SYSTEM_SIZE);
00010   aux::symmetric_matrix sigma(SYSTEM_SIZE);
00011     
00012   /* system noise */
00013   mu.clear();
00014 
00015   sigma.clear();
00016   sigma(0,0) = pow(0.01,2.0);
00017   sigma(1,1) = pow(0.01,2.0);
00018 
00019   w.setExpectation(mu);
00020   w.setCovariance(sigma);
00021 
00022   /* measurement noise */
00023   mu.resize(MEAS_SIZE, false);
00024   sigma.resize(MEAS_SIZE, false);
00025 
00026   mu.clear();
00027   sigma.clear();
00028   sigma(0,0) = pow(0.05, 2.0);
00029 
00030   v.setExpectation(mu);
00031   v.setCovariance(sigma);
00032 }
00033 
00034 MobileRobotParticleFilterModel::~MobileRobotParticleFilterModel() {
00035   //
00036 }
00037 
00038 aux::GaussianPdf MobileRobotParticleFilterModel::suggestPrior() {
00039   aux::vector mu(SYSTEM_SIZE);
00040   aux::symmetric_matrix sigma(SYSTEM_SIZE);
00041 
00042   mu.clear();
00043   mu(0) = -1.0;
00044   mu(1) = 1.0;
00045 
00046   sigma.clear();
00047   sigma(0,0) = 1.0;
00048   sigma(1,1) = 1.0;
00049   
00050   aux::GaussianPdf x0(mu, sigma);
00051   
00052   return x0;
00053 }
00054 
00055 unsigned int MobileRobotParticleFilterModel::getStateSize() {
00056   return SYSTEM_SIZE;
00057 }
00058 
00059 unsigned int MobileRobotParticleFilterModel::getMeasurementSize() {
00060   return MEAS_SIZE;
00061 }
00062 
00063 aux::vector MobileRobotParticleFilterModel::transition(const aux::vector& x,
00064       const unsigned int start, const unsigned int delta) {
00065   aux::vector w(SYSTEM_SIZE);
00066   w = this->w.sample();
00067 
00068   aux::vector xtnp1(SYSTEM_SIZE);
00069   xtnp1(0) = x(0) + cos(0.8 + ang*start) * vel;
00070   xtnp1(1) = x(1) + sin(0.8 + ang*start) * vel;
00071 
00072   return (xtnp1 + this->w.sample());
00073 }
00074 
00075 double MobileRobotParticleFilterModel::weight(const aux::vector& x,
00076     const aux::vector& y) {
00077   aux::vector mu(MEAS_SIZE);
00078   mu(0) = 2.0 * x(1);
00079 
00080   return v.calculateDensity(y - mu);
00081 }
00082 
00083 aux::vector MobileRobotParticleFilterModel::measure(const aux::vector& x) {
00084   aux::vector y(MEAS_SIZE);
00085   y(0) = 2.0 * x(1);
00086 
00087   return y + v.sample();
00088 }
00089 
00090 aux::sparse_matrix MobileRobotParticleFilterModel::alpha(
00091     const aux::DiracMixturePdf& p_xtn_ytn,
00092     const aux::DiracMixturePdf& p_xtnp1_ytnp1,
00093     const unsigned int start, const unsigned int delta) {
00094   const unsigned int P1 = p_xtn_ytn.getSize();
00095   const unsigned int P2 = p_xtnp1_ytnp1.getSize();
00096   unsigned int i, j;
00097   double p;
00098   aux::sparse_matrix alpha(P2,P1);
00099   aux::vector mu(SYSTEM_SIZE);
00100 
00101   for (i = 0; i < p_xtn_ytn.getSize(); i++) {
00102     const aux::vector& x = p_xtn_ytn.get(i);
00103   
00104     /* propagate particle through transition to get mean */
00105     mu(0) = x(0) + cos(0.8 + ang*start) * vel;
00106     mu(1) = x(1) + sin(0.8 + ang*start) * vel;
00107 
00108     for (j = 0; j < P2; j++) {
00109       p = w.calculateDensity(p_xtnp1_ytnp1.get(j) - mu);
00110       if (p > 0.0) {
00111         alpha(j,i) = p;
00112       }
00113     }
00114   }
00115 
00116   return alpha;
00117 }
00118 

Generated on Wed Dec 17 15:05:50 2008 for dysii Filtering Test Suite by  doxygen 1.5.3