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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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
00051 #include <math.h>
00052
00053
00054
00055 namespace lobot {
00056
00057
00058
00059 namespace {
00060
00061
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
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
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
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
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
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 }
00108
00109
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
00151
00152
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
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 }
00208
00209
00210
00211
00212