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" 00018 *AND * 00019 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 ** 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 00022 * DISCLAIMED. IN NO EVENT SHALL Markus Bader BE LIABLE FOR ANY * 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 ** 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * 00027 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 ** 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ** * 00032 ***********************************************************************************/ 00033 00034 #ifndef MRPT_LOCALIZATION_CORE_H 00035 #define MRPT_LOCALIZATION_CORE_H 00036 00037 #include <iostream> 00038 #include <stdint.h> 00039 00040 #include <mrpt/bayes/CParticleFilter.h> 00041 #include <mrpt/poses/CPose2D.h> 00042 #include <mrpt/poses/CPosePDFGaussian.h> 00043 #include <mrpt/utils/CTicTac.h> 00044 #include <mrpt/slam/CMonteCarloLocalization2D.h> 00045 #include <mrpt_bridge/mrpt_log_macros.h> 00046 00047 #include <mrpt/version.h> 00048 #include <mrpt/obs/CActionRobotMovement2D.h> 00049 #include <mrpt/obs/CActionCollection.h> 00050 #include <mrpt/obs/CObservationOdometry.h> 00051 #include <mrpt/obs/CSensoryFrame.h> 00052 #include <mrpt/maps/CMultiMetricMap.h> 00053 using namespace mrpt::maps; 00054 using namespace mrpt::obs; 00055 00056 class PFLocalizationCore 00057 { 00058 MRPT_VIRTUAL_LOG_MACROS 00059 00060 public: 00061 enum PFStates 00062 { 00063 NA, 00064 INIT, 00065 RUN, 00066 IDLE 00067 }; 00068 00069 PFLocalizationCore(); 00070 ~PFLocalizationCore(); 00071 00076 void init(); 00085 void observation( 00086 CSensoryFrame::Ptr _sf, CObservationOdometry::Ptr _odometry); 00087 00088 protected: 00089 bool use_motion_model_default_options_; 00090 CActionRobotMovement2D::TMotionModelOptions 00091 motion_model_default_options_; 00092 CActionRobotMovement2D::TMotionModelOptions 00093 motion_model_options_; 00094 CMultiMetricMap metric_map_; 00095 mrpt::bayes::CParticleFilter 00096 pf_; 00097 mrpt::bayes::CParticleFilter::TParticleFilterStats 00098 pf_stats_; 00099 mrpt::slam::CMonteCarloLocalization2D pdf_; 00100 mrpt::poses::CPosePDFGaussian 00101 initial_pose_; 00102 int initial_particle_count_; 00103 mrpt::system::TTimeStamp time_last_update_; 00104 mrpt::utils::CTicTac tictac_; 00105 size_t update_counter_; 00106 00107 PFStates state_; 00108 00109 mrpt::poses::CPose2D 00110 odom_last_observation_; 00111 bool init_PDF_mode; 00112 00113 float init_PDF_min_x; 00114 float init_PDF_max_x; 00115 float init_PDF_min_y; 00116 float init_PDF_max_y; 00117 00118 private: 00125 void initializeFilter(); 00126 00127 void updateFilter(CActionCollection::Ptr _action, CSensoryFrame::Ptr _sf); 00128 }; 00129 00130 #endif // MRPT_LOCALIZATION_CORE_H