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
00033 using namespace mrpt;
00034 using namespace mrpt::slam;
00035 using namespace mrpt::opengl;
00036 using namespace mrpt::math;
00037 using namespace mrpt::system;
00038 using namespace mrpt::utils;
00039 using namespace std;
00040
00041 PFLocalizationCore::~PFLocalizationCore()
00042 {
00043 }
00044
00045 PFLocalizationCore::PFLocalizationCore()
00046 : state_(NA)
00047 {
00048 }
00049
00050 void PFLocalizationCore::init() {
00051 mrpt::math::CMatrixDouble33 cov;
00052 cov(0,0) = 1, cov(1,1) = 1, cov(2,2) = 2*M_PI;
00053 initialPose_ = mrpt::utils::CPosePDFGaussian(mrpt::poses::CPose2D(0,0,0), cov);
00054 initialParticleCount_ = 1000;
00055 motion_model_default_options_.modelSelection = CActionRobotMovement2D::mmGaussian;
00056 motion_model_default_options_.gausianModel.minStdXY = 0.10;
00057 motion_model_default_options_.gausianModel.minStdPHI = 2.0;
00058 }
00059
00060
00061 void PFLocalizationCore::initializeFilter() {
00062 mrpt::math::CMatrixDouble33 cov;
00063 mrpt::poses::CPose2D mean_point;
00064 log_info("InitializeFilter: %4.3fm, %4.3fm, %4.3frad ", mean_point.x(), mean_point.y(), mean_point.phi());
00065 initialPose_.getCovarianceAndMean(cov, mean_point);
00066 float min_x = mean_point.x()-cov(0,0);
00067 float max_x = mean_point.x()+cov(0,0);
00068 float min_y = mean_point.y()-cov(1,1);
00069 float max_y = mean_point.y()+cov(1,1);
00070 float min_phi = mean_point.phi()-cov(2,2);
00071 float max_phi = mean_point.phi()+cov(2,2);
00072 pdf_.resetUniformFreeSpace( metric_map_.m_gridMaps[0].pointer(), 0.7f,
00073 initialParticleCount_ , min_x,max_x, min_y, max_y, min_phi, max_phi);
00074 state_ = RUN;
00075 }
00076
00077 void PFLocalizationCore::updateFilter(CActionCollectionPtr _action, CSensoryFramePtr _sf) {
00078 if(state_ == INIT) initializeFilter();
00079 tictac_.Tic();
00080 pf_.executeOn( pdf_, _action.pointer(), _sf.pointer(), &pf_stats_ );
00081 timeLastUpdate_ = _sf->getObservationByIndex(0)->timestamp;
00082 update_counter_++;
00083 }
00084
00085 void PFLocalizationCore::observation(mrpt::slam::CSensoryFramePtr _sf, mrpt::slam::CObservationOdometryPtr _odometry) {
00086
00087 mrpt::slam::CActionCollectionPtr action = mrpt::slam::CActionCollection::Create();
00088 mrpt::slam::CActionRobotMovement2D odom_move;
00089 odom_move.timestamp = _sf->getObservationByIndex(0)->timestamp;
00090 if(_odometry) {
00091 if(odomLastObservation_.empty()) {
00092 odomLastObservation_ = _odometry->odometry;
00093 }
00094 mrpt::poses::CPose2D incOdoPose = _odometry->odometry - odomLastObservation_;
00095 odomLastObservation_ = _odometry->odometry;
00096 odom_move.computeFromOdometry(incOdoPose, motion_model_options_);
00097 action->insert(odom_move);
00098 updateFilter(action, _sf);
00099 } else {
00100 if(use_motion_model_default_options_){
00101 log_info("No odometry at update %4i -> using dummy", update_counter_);
00102 odom_move.computeFromOdometry(CPose2D(0,0,0), motion_model_default_options_);
00103 action->insert(odom_move);
00104 updateFilter(action, _sf);
00105 } else {
00106 log_info("No odometry at update %4i -> skipping observation", update_counter_);
00107 }
00108 }
00109 }