Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <mrpt_localization/mrpt_localization_core.h>
00031
00032 #include <mrpt/base.h>
00033 #include <mrpt/slam.h>
00034
00035 using namespace mrpt;
00036 using namespace mrpt::slam;
00037 using namespace mrpt::opengl;
00038 using namespace mrpt::math;
00039 using namespace mrpt::system;
00040 using namespace mrpt::utils;
00041 using namespace mrpt::random;
00042 using namespace std;
00043
00044 PFLocalizationCore::~PFLocalizationCore()
00045 {
00046 }
00047
00048 PFLocalizationCore::PFLocalizationCore()
00049 : state_(NA)
00050 {
00051 }
00052
00053 void PFLocalizationCore::init(){
00054 }
00055
00056
00057 void PFLocalizationCore::initializeFilter(mrpt::utils::CPosePDFGaussian &p){
00058 mrpt::math::CMatrixDouble33 cov;
00059 mrpt::math::CPose2D mean_point;
00060 log_info("InitializeFilter: %4.3fm, %4.3fm, %4.3frad ", mean_point.x(), mean_point.y(), mean_point.phi());
00061 p.getCovarianceAndMean(cov, mean_point);
00062 float min_x = mean_point.x()-cov(0,0);
00063 float max_x = mean_point.x()+cov(0,0);
00064 float min_y = mean_point.y()-cov(1,1);
00065 float max_y = mean_point.y()+cov(1,1);
00066 float min_phi = mean_point.phi()-cov(2,2);
00067 float max_phi = mean_point.phi()+cov(2,2);
00068 pdf_.resetUniformFreeSpace( metric_map_.m_gridMaps[0].pointer(), 0.7f,
00069 initialParticleCount_ , min_x,max_x, min_y, max_y, min_phi, max_phi);
00070 state_ = RUN;
00071 }
00072
00073 void PFLocalizationCore::updateFilter(CActionCollectionPtr _action, CSensoryFramePtr _sf) {
00074 if(state_ == INIT) initializeFilter(initialPose_);
00075 tictac_.Tic();
00076 pf_.executeOn( pdf_, _action.pointer(), _sf.pointer(), &pf_stats_ );
00077 timeLastUpdate_ = _sf->getObservationByIndex(0)->timestamp;
00078 update_counter_++;
00079 }
00080
00081 void PFLocalizationCore::observation(mrpt::slam::CSensoryFramePtr _sf, mrpt::slam::CObservationOdometryPtr _odometry) {
00082
00083 mrpt::slam::CActionCollectionPtr action = mrpt::slam::CActionCollection::Create();
00084 mrpt::slam::CActionRobotMovement2D odom_move;
00085 odom_move.timestamp = _sf->getObservationByIndex(0)->timestamp;
00086 if(_odometry) {
00087 if(odomLastObservation_.empty()) {
00088 odomLastObservation_ = _odometry->odometry;
00089 }
00090 mrpt::poses::CPose2D incOdoPose = _odometry->odometry - odomLastObservation_;
00091 odomLastObservation_ = _odometry->odometry;
00092 odom_move.computeFromOdometry(incOdoPose, odom_params_);
00093 action->insert(odom_move);
00094 } else {
00095 log_info("No odometry at update %4i -> using dummy", update_counter_);
00096 odom_move.computeFromOdometry(CPose2D(0,0,0), odom_params_dummy_);
00097 action->insert(odom_move);
00098 }
00099 updateFilter(action, _sf);
00100 }