mrpt_localization_core.cpp
Go to the documentation of this file.
00001 /***********************************************************************************
00002  * Revised BSD License                                                             *
00003  * Copyright (c) 2014, Markus Bader <markus.bader@tuwien.ac.at>                    *
00004  * All rights reserved.                                                            *
00005  *                                                                                 *
00006  * Redistribution and use in source and binary forms, with or without              *
00007  * modification, are permitted provided that the following conditions are met:     *
00008  *     * Redistributions of source code must retain the above copyright            *
00009  *       notice, this list of conditions and the following disclaimer.             *
00010  *     * Redistributions in binary form must reproduce the above copyright         *
00011  *       notice, this list of conditions and the following disclaimer in the       *
00012  *       documentation and/or other materials provided with the distribution.      *
00013  *     * Neither the name of the Vienna University of Technology nor the           *
00014  *       names of its contributors may be used to endorse or promote products      *
00015  *       derived from this software without specific prior written permission.     *
00016  *                                                                                 *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED   *
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE          *
00020  * DISCLAIMED. IN NO EVENT SHALL Markus Bader BE LIABLE FOR ANY                    *
00021  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES      *
00022  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    *
00023  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND     *
00024  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT      *
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS   *
00026  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                    *                       *
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 }


mrpt_localization
Author(s): Markus Bader
autogenerated on Mon Aug 11 2014 11:23:29