nonlinearanalyticconditionalgaussianodo.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2008 Wim Meeussen <meeussen at willowgarage com>
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU Lesser General Public License as published by
00005 // the Free Software Foundation; either version 2.1 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 //
00017 
00018 #include <iri_robot_pose_ekf/nonlinearanalyticconditionalgaussianodo.h>
00019 #include <wrappers/rng/rng.h> // Wrapper around several rng
00020                               // libraries
00021 #define NUMCONDARGUMENTS_MOBILE 2
00022 
00023 namespace BFL
00024 {
00025   using namespace MatrixWrapper;
00026 
00027 
00028   NonLinearAnalyticConditionalGaussianOdo::NonLinearAnalyticConditionalGaussianOdo(const Gaussian& additiveNoise)
00029     : AnalyticConditionalGaussianAdditiveNoise(additiveNoise,NUMCONDARGUMENTS_MOBILE),
00030       df(6,6)
00031   {
00032     // initialize df matrix
00033     for (unsigned int i=1; i<=6; i++){
00034       for (unsigned int j=1; j<=6; j++){
00035         if (i==j) df(i,j) = 1;
00036         else df(i,j) = 0;
00037       }
00038     }
00039   }
00040 
00041 
00042   NonLinearAnalyticConditionalGaussianOdo::~NonLinearAnalyticConditionalGaussianOdo(){}
00043 
00044   ColumnVector NonLinearAnalyticConditionalGaussianOdo::ExpectedValueGet() const
00045   {
00046     ColumnVector state = ConditionalArgumentGet(0);
00047     ColumnVector vel  = ConditionalArgumentGet(1);
00048 
00049     // state = 1:x, 2:y, 3:z, 4:roll, 5:pitch, 6:yaw
00050     // vel = 1:v-x, 2:v-roll, 3:v-pitch, 4:v-yaw
00051 
00052     state(1) += cos(state(6)) * cos(state(5)) * vel(1); // state 1 = x
00053     state(2) += sin(state(6)) * cos(state(4)) * vel(1); // state 2 = y
00054     state(3) += sin(state(5)) * sin(state(4)) * vel(1); // state 3 = z
00055     state(4) += vel(2);                                 // state 4 = roll = phi
00056     state(5) += vel(3);                                 // state 5 = pitch = psi
00057     state(6) += vel(4);                                 // state 6 = yaw = theta
00058     return state + AdditiveNoiseMuGet();
00059   }
00060 
00061   Matrix NonLinearAnalyticConditionalGaussianOdo::dfGet(unsigned int i) const
00062   {
00063     if (i==0)//derivative to the first conditional argument (x)
00064     {
00065       double v = ConditionalArgumentGet(1)(1);
00066       double r = ConditionalArgumentGet(0)(4); // state 4 roll
00067       double p = ConditionalArgumentGet(0)(5); // state 5 pitch
00068       double y = ConditionalArgumentGet(0)(6); // state 6 yaw
00069 
00070       df(1,5)= -v * cos(y) * sin (p); // state 1 = x derived by state 5 pitch
00071       df(1,6)= -v * sin(y) * cos (p); //                              6 yaw
00072       df(2,4)= -v * sin(y) * sin (r); // state 2 = y derived by state 4 roll
00073       df(2,6)=  v * cos(y) * cos (r); //                              6 yaw
00074       df(3,4)=  v * sin(p) * cos (r); // state 3 = z derived by state 4 roll
00075       df(3,5)=  v * cos(p) * sin (r); //                              5 pitch
00076 
00077       return df;
00078     }
00079     else
00080     {
00081       if (i >= NumConditionalArgumentsGet())
00082       {
00083         cerr << "This pdf Only has " << NumConditionalArgumentsGet() << " conditional arguments\n";
00084         exit(-BFL_ERRMISUSE);
00085       }
00086       else{
00087         cerr << "The df is not implemented for the" <<i << "th conditional argument\n";
00088         exit(-BFL_ERRMISUSE);
00089       }
00090     }
00091   }
00092 
00093 }//namespace BFL
00094 


iri_robot_pose_ekf
Author(s): Wim Meeussen
autogenerated on Fri Dec 6 2013 23:49:07