00001 /** 00002 \file Robots/LoBot/slam/LoSlamParams.C 00003 \brief This file defines the non-inline member functions of the 00004 lobot::SlamParams class. 00005 */ 00006 00007 // //////////////////////////////////////////////////////////////////// // 00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00009 // by the University of Southern California (USC) and the iLab at USC. // 00010 // See http://iLab.usc.edu for information about this project. // 00011 // //////////////////////////////////////////////////////////////////// // 00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00014 // in Visual Environments, and Applications'' by Christof Koch and // 00015 // Laurent Itti, California Institute of Technology, 2001 (patent // 00016 // pending; application number 09/912,225 filed July 23, 2001; see // 00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00018 // //////////////////////////////////////////////////////////////////// // 00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00022 // redistribute it and/or modify it under the terms of the GNU General // 00023 // Public License as published by the Free Software Foundation; either // 00024 // version 2 of the License, or (at your option) any later version. // 00025 // // 00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00029 // PURPOSE. See the GNU General Public License for more details. // 00030 // // 00031 // You should have received a copy of the GNU General Public License // 00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00034 // Boston, MA 02111-1307 USA. // 00035 // //////////////////////////////////////////////////////////////////// // 00036 // 00037 // Primary maintainer for this file: mviswana usc edu 00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/slam/LoSlamParams.C $ 00039 // $Id: LoSlamParams.C 13575 2010-06-17 01:42:18Z mviswana $ 00040 // 00041 00042 //------------------------------ HEADERS -------------------------------- 00043 00044 // lobot headers 00045 #include "Robots/LoBot/slam/LoSlamParams.H" 00046 #include "Robots/LoBot/config/LoConfigHelpers.H" 00047 #include "Robots/LoBot/misc/LoRegistry.H" 00048 #include "Robots/LoBot/util/LoMath.H" 00049 00050 // Standard C headers 00051 #include <math.h> 00052 00053 //----------------------------- NAMESPACE ------------------------------- 00054 00055 namespace lobot { 00056 00057 //-------------------------- KNOB TWIDDLING ----------------------------- 00058 00059 namespace { 00060 00061 // Quick helper to return settings from "map" section of config file 00062 template<typename T> 00063 inline T map_conf(const std::string& key, T default_value) 00064 { 00065 return get_conf<T>("map", key, default_value) ; 00066 } 00067 00068 // Overload for returning config settings via an array 00069 template<typename T> 00070 inline void 00071 map_conf(const std::string& key, T* array, const T* defaults, unsigned int n) 00072 { 00073 Configuration::get<T>("map", key, array, defaults, n) ; 00074 } 00075 00076 // Quick helper to return settings from "slam" section of config file 00077 template<typename T> 00078 inline T slam_conf(const std::string& key, T default_value) 00079 { 00080 return get_conf<T>("slam", key, default_value) ; 00081 } 00082 00083 // Overload for retrieving pairs 00084 template<typename T> 00085 inline std::pair<T, T> 00086 slam_conf(const std::string& key, const std::pair<T, T>& default_value) 00087 { 00088 return get_conf<T>("slam", key, default_value) ; 00089 } 00090 00091 // Overload for retrieving triples 00092 template<typename T> 00093 inline triple<T, T, T> 00094 slam_conf(const std::string& key, const triple<T, T, T>& default_value) 00095 { 00096 return get_conf<T>("slam", key, default_value) ; 00097 } 00098 00099 // Overload for retrieving ranges 00100 template<typename T> 00101 inline range<T> 00102 slam_conf(const std::string& key, const range<T>& default_value) 00103 { 00104 return get_conf<T>("slam", key, default_value) ; 00105 } 00106 00107 } // end of anonymous local namespace encapsulating above helpers 00108 00109 // Parameter initialization 00110 SlamParams::SlamParams() 00111 : m_cell_size(clamp(map_conf("cell_size", 10.0f), 1.0f, 1000.0f)), 00112 m_initial_pose(slam_conf("initial_pose", make_triple(0.0f, 0.0f, 0.0f))), 00113 m_errors(slam_conf("errors", make_triple(5.0f, 5.0f, 0.5f))), 00114 m_num_particles(clamp(slam_conf("num_particles", 100), 1, 50000)), 00115 m_ess_threshold(clamp(slam_conf("ess_threshold", m_num_particles/2), 00116 0, m_num_particles + 1)), 00117 m_alpha(slam_conf("alpha", std::make_pair(0.85f, 0.05f))), 00118 m_beam_specs(slam_conf("beam_specs", make_triple(-90, 90, 15))), 00119 m_beam_model_sigma(clamp(slam_conf("beam_model_sigma", 75.0f), 00120 1.0f, 1000.0f)), 00121 m_beam_model_fudge(clamp(slam_conf("beam_prob_fudge_factor", 2500.0f), 00122 1.0f, 1e+12f)), 00123 m_beam_range(clamp(slam_conf("beam_range", make_range(60.0f, 5600.0f)), 00124 make_range(30.0f, 30000.0f))), 00125 m_prob_rnd(1/(m_beam_range.size() + 1)), 00126 m_occ_range_error(clamp(slam_conf("occupancy_range_error", 50.0f), 00127 5.0f, 500.0f)), 00128 m_occ_threshold(prob_to_log_odds( 00129 clamp(map_conf("occupancy_threshold", 0.75f), 0.05f, 0.95f))), 00130 m_update_weight(clamp(map_conf("update_weight", 0.75f), 0.5f, 0.95f)), 00131 m_match_scans(slam_conf("scan_matching", false)), 00132 m_map_file(get_conf<std::string>(LOBE_SURVEY, "map_file", "")), 00133 m_geometry(map_conf<std::string>("geometry", "0 0 390 390")) 00134 { 00135 float default_extents[4] = {0, 5000, -2500, 2500} ; 00136 map_conf("extents", m_extents, default_extents, 4) ; 00137 m_extents[1] = std::max(m_extents[1], m_extents[0] + m_cell_size) ; 00138 m_extents[3] = std::max(m_extents[3], m_extents[2] + m_cell_size) ; 00139 00140 const float L = m_extents[0] ; 00141 const float R = m_extents[1] ; 00142 const float B = m_extents[2] ; 00143 const float T = m_extents[3] ; 00144 const float S = m_cell_size ; 00145 00146 m_width = static_cast<int>(ceilf((R - L)/S)) ; 00147 m_height = static_cast<int>(ceilf((T - B)/S)) ; 00148 m_max_distance = sqrtf(sqr(R - L) + sqr(T - B)) ; 00149 00150 // See comment preceding Coords::to_grid() for explanation of why 00151 // these scale factors are computed in this manner and how they are 00152 // used. 00153 m_scale.first = 1/S - 1/(R - L) ; 00154 m_scale.second = 1/S - 1/(T - B) ; 00155 00156 m_initial_pose.first = clamp(m_initial_pose.first, L, R) ; 00157 m_initial_pose.second = clamp(m_initial_pose.second, B, T) ; 00158 m_initial_pose.third = clamp_angle(m_initial_pose.third) ; 00159 00160 m_errors.first = clamp(m_errors.first, 0.0f, 500.0f) ; 00161 m_errors.second = clamp(m_errors.second, 0.0f, 500.0f) ; 00162 m_errors.third = clamp(m_errors.third, 0.0f, 90.0f) ; 00163 00164 m_alpha.first = clamp(m_alpha.first, 0.50f, 0.99f) ; 00165 m_alpha.second = clamp(m_alpha.second, 0.01f, 0.25f) ; 00166 00167 float p = clamp(slam_conf("kmeans_percentage", 10.0f), 0.0f, 50.0f) ; 00168 m_k = clamp(round(p * m_num_particles/100.0f), 1, 100) ; 00169 00170 m_beam_specs.first = clamp(m_beam_specs.first, -180, 180) ; 00171 m_beam_specs.second = 00172 clamp(m_beam_specs.second, 00173 m_beam_specs.first + 1, 00174 static_cast<int>(clamp_angle(m_beam_specs.first + 359))) ; 00175 m_beam_specs.third = clamp(m_beam_specs.third, 1, 00176 m_beam_specs.second - m_beam_specs.first + 1) ; 00177 } 00178 00179 //---------------------------- MAP EXTENTS ------------------------------ 00180 00181 void SlamParams::map_extents(float* L, float* R, float* B, float* T) 00182 { 00183 const float* ext = instance().m_extents ; 00184 if (L) 00185 *L = ext[0] ; 00186 if (R) 00187 *R = ext[1] ; 00188 if (B) 00189 *B = ext[2] ; 00190 if (T) 00191 *T = ext[3] ; 00192 } 00193 00194 void SlamParams::map_extents(float x[4]) 00195 { 00196 if (x) { 00197 const float* ext = instance().m_extents ; 00198 x[0] = ext[0] ; 00199 x[1] = ext[1] ; 00200 x[2] = ext[2] ; 00201 x[3] = ext[3] ; 00202 } 00203 } 00204 00205 //----------------------------------------------------------------------- 00206 00207 } // end of namespace encapsulating this file's definitions 00208 00209 /* So things look consistent in everyone's emacs... */ 00210 /* Local Variables: */ 00211 /* indent-tabs-mode: nil */ 00212 /* End: */