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 #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 }


mrpt_localization
Author(s):
autogenerated on Tue Aug 5 2014 10:58:12