00001 /** 00002 \file Robots/LoBot/config/LoConfigHelpers.H 00003 \brief Helper/convenience functions for accessing the lobot 00004 configuration database. 00005 00006 This file defines several functions that can be used to ease the 00007 interface to lobot's configuration database. Thus, clients may, for 00008 instance, simply use the get_conf() function and not have to worry 00009 about invoking Configuration::get(); so on and so forth. 00010 00011 Basically, this file provides a bunch of helpers that result less 00012 typing and less ceremony in client code for using the configuration 00013 database. 00014 */ 00015 00016 // //////////////////////////////////////////////////////////////////// // 00017 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00018 // by the University of Southern California (USC) and the iLab at USC. // 00019 // See http://iLab.usc.edu for information about this project. // 00020 // //////////////////////////////////////////////////////////////////// // 00021 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00022 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00023 // in Visual Environments, and Applications'' by Christof Koch and // 00024 // Laurent Itti, California Institute of Technology, 2001 (patent // 00025 // pending; application number 09/912,225 filed July 23, 2001; see // 00026 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00027 // //////////////////////////////////////////////////////////////////// // 00028 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00029 // // 00030 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00031 // redistribute it and/or modify it under the terms of the GNU General // 00032 // Public License as published by the Free Software Foundation; either // 00033 // version 2 of the License, or (at your option) any later version. // 00034 // // 00035 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00036 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00037 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00038 // PURPOSE. See the GNU General Public License for more details. // 00039 // // 00040 // You should have received a copy of the GNU General Public License // 00041 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00042 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00043 // Boston, MA 02111-1307 USA. // 00044 // //////////////////////////////////////////////////////////////////// // 00045 // 00046 // Primary maintainer for this file: mviswana usc edu 00047 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/config/LoConfigHelpers.H $ 00048 // $Id: LoConfigHelpers.H 13445 2010-05-21 06:12:57Z mviswana $ 00049 // 00050 00051 #ifndef LOBOT_CONFIG_HELPERS_DOT_H 00052 #define LOBOT_CONFIG_HELPERS_DOT_H 00053 00054 //------------------------------ HEADERS -------------------------------- 00055 00056 // lobot headers 00057 #include "Robots/LoBot/config/LoConfig.H" 00058 #include "Robots/LoBot/config/LoDefaults.H" 00059 00060 #include "Robots/LoBot/misc/LoTypes.H" 00061 #include "Robots/LoBot/util/LoString.H" 00062 #include "Robots/LoBot/util/triple.hh" 00063 #include "Robots/LoBot/util/range.hh" 00064 00065 // Standard C++ headers 00066 #include <string> 00067 #include <utility> 00068 00069 //----------------------------- NAMESPACE ------------------------------- 00070 00071 namespace lobot { 00072 00073 //---------------------- GENERAL CONFIG HELPERS ------------------------- 00074 00075 /// A convenience routine to allow clients to not have to type the whole 00076 /// Configuration::get call... 00077 template<typename T> 00078 inline T get_conf(const std::string& section, const std::string& key, 00079 const T& default_value = T()) 00080 { 00081 return Configuration::get(section, key, default_value) ; 00082 } 00083 00084 /// A convenience routine to return an RGB color from the specified 00085 /// section of the config file. 00086 template<> 00087 PixelType get_conf(const std::string& section, const std::string& key, 00088 const PixelType& defval) 00089 { 00090 int color[3] ; 00091 const int default_color[] = {defval.red(), defval.green(), defval.blue()} ; 00092 Configuration::get(section, key, color, default_color, 3) ; 00093 return PixelType(color[0], color[1], color[2]) ; 00094 } 00095 00096 /// Convenience routine to return a pair from the specified section of 00097 /// the config file. 00098 template<typename T> 00099 std::pair<T, T> 00100 get_conf(const std::string& section, const std::string& key, 00101 const std::pair<T, T>& defval = std::pair<T, T>(T(), T())) 00102 { 00103 T pair[2] ; 00104 const T defaults[] = {defval.first, defval.second} ; 00105 Configuration::get<T>(section, key, pair, defaults, 2) ; 00106 return std::pair<T, T>(pair[0], pair[1]) ; 00107 } 00108 00109 /// Convenience routine to return a triple from the specified section of 00110 /// the config file. 00111 template<typename T> 00112 triple<T, T, T> 00113 get_conf(const std::string& section, const std::string& key, 00114 const triple<T, T, T>& defval = make_triple(T(), T(), T())) 00115 { 00116 T triple[3] ; 00117 const T defaults[] = {defval.first, defval.second, defval.third} ; 00118 Configuration::get<T>(section, key, triple, defaults, 3) ; 00119 return make_triple(triple[0], triple[1], triple[2]) ; 00120 } 00121 00122 /// Convenience routine to return a range<T> from the specified section 00123 /// of the config file. 00124 template<typename T> 00125 range<T> get_conf(const std::string& section, const std::string& key, 00126 const range<T>& defval = range<T>(T(), T())) 00127 { 00128 std::pair<T, T> r = 00129 get_conf<T>(section, key, std::make_pair(defval.min(), defval.max())) ; 00130 return make_range(r.first, r.second) ; 00131 } 00132 00133 /// Retrieve settings from the global section of the config file 00134 template<typename T> 00135 inline T global_conf(const std::string& key, const T& default_value = T()) 00136 { 00137 return Configuration::get_global<T>(key, default_value) ; 00138 } 00139 00140 /// Retrieve settings from the secret internal section of the 00141 /// configuration database. 00142 template<typename T> 00143 inline T internal_conf(const std::string& key, const T& default_value = T()) 00144 { 00145 return get_conf<T>(LOCD_INTERNAL, key, default_value) ; 00146 } 00147 00148 //---------------------- ROBOT PLATFORM HELPERS ------------------------- 00149 00150 /// Retrieve settings from the motor section of the config file 00151 template<typename T> 00152 inline T robot_conf(const std::string& key, const T& default_value = T()) 00153 { 00154 return get_conf<T>("robot", key, default_value) ; 00155 } 00156 00157 /// Does the user want to enable the physical robot? 00158 inline bool robot_enabled() 00159 { 00160 return robot_conf("use_robot", true) ; 00161 } 00162 00163 /// Which robot platform will Robolocust be running on? 00164 inline std::string robot_platform() 00165 { 00166 return downstring(robot_conf<std::string>("platform", "roomba_cm")) ; 00167 } 00168 00169 /// Is the lobot controller running on an iRobot Create/Roomba? 00170 bool robot_platform_is_roomba() ; 00171 00172 //---------------------------- I/O HELPERS ------------------------------ 00173 00174 /// Check what input source to use for the locust LGMD spikes 00175 inline std::string locust_input() 00176 { 00177 return downstring(global_conf<std::string>("locust_input", "laser")) ; 00178 } 00179 00180 /// Check if cameras are being used to generate LGMD spikes 00181 inline bool video_input() 00182 { 00183 return locust_input() == "video" ; 00184 } 00185 00186 /// Check if the laser range finder is being used to generate LGMD spikes 00187 inline bool laser_input() 00188 { 00189 return locust_input() == "laser" ; 00190 } 00191 00192 /// Retrieve settings from the laser section of the config file 00193 template<typename T> 00194 inline T laser_conf(const std::string& key, const T& default_value = T()) 00195 { 00196 return get_conf<T>("laser", key, default_value) ; 00197 } 00198 00199 /// Check which LGMD model is being used 00200 inline std::string locust_model() 00201 { 00202 return downstring(global_conf<std::string>("locust_model", 00203 LOBOT_DEFAULT_LOCUST_MODEL)) ; 00204 } 00205 00206 //---------------------------- UI HELPERS ------------------------------- 00207 00208 /// Retrieve settings from the ui section of the config file 00209 template<typename T> 00210 inline T ui_conf(const std::string& key, const T& default_value = T()) 00211 { 00212 return get_conf<T>("ui", key, default_value) ; 00213 } 00214 00215 /// Check if a drawable (such as a behaviour, an arbiter, LRF visualizer, 00216 /// etc.) is configured to be visualized or not. By default, 00217 /// visualizations are all turned off; the user must explicitly turn them 00218 /// on. 00219 inline bool visualize(const std::string& section) 00220 { 00221 return get_conf(section, "visualization", false) ; 00222 } 00223 00224 //----------------------- VIDEO RELATED HELPERS ------------------------- 00225 00226 /// Retrieve settings from the video section of the config file 00227 template<typename T> 00228 inline T video_conf(const std::string& key, const T& default_value = T()) 00229 { 00230 return get_conf<T>("video", key, default_value) ; 00231 } 00232 00233 /// Retrieve settings from the optical flow section of the config file 00234 template<typename T> 00235 inline T optical_flow_conf(const std::string& key, const T& default_value) 00236 { 00237 return get_conf<T>("optical_flow", key, default_value) ; 00238 } 00239 00240 //----------------------------------------------------------------------- 00241 00242 } // end of namespace encapsulating this file's definitions 00243 00244 #endif 00245 00246 /* So things look consistent in everyone's emacs... */ 00247 /* Local Variables: */ 00248 /* indent-tabs-mode: nil */ 00249 /* End: */