Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
Config.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_Config_h 00003 #define INCLUDED_Config_h 00004 00005 #include <vector> 00006 #include <string> 00007 #include "RobotInfo.h" 00008 extern "C" { 00009 #include <jpeglib.h> 00010 } 00011 00012 //!provides global access to system configuration information 00013 class Config { 00014 public: 00015 //!constructor 00016 Config() 00017 : wireless(), vision(), main(), behaviors(), controller(), motion(this), 00018 sound(this), fsRoot() 00019 {setFileSystemRoot("");} 00020 //!constructor 00021 Config(const std::string& filename) 00022 : wireless(), vision(), main(), behaviors(), controller(), motion(this), 00023 sound(this), fsRoot() 00024 { setFileSystemRoot(""); readConfig(filename); } 00025 //!destructor 00026 ~Config() {} 00027 00028 void setFileSystemRoot(const std::string& fsr); //!< sets #fsRoot 00029 const std::string& getFileSystemRoot() const { return fsRoot; } //!< returns #fsRoot 00030 std::string portPath(const std::string& path) const; //!< returns a portable version of @a path which should be usable on either the simulator or the robot 00031 00032 //!section IDs 00033 enum section_t { 00034 sec_wireless=0, //!< denotes wireless section of config file 00035 sec_vision, //!< denotes vision section of config file 00036 sec_main, //!< denotes main section of config file, for misc. settings 00037 sec_behaviors, //!< denotes behaviors section of config file 00038 sec_controller, //!< denotes controller section of config file 00039 sec_motion, //!< denotes motion section of config file 00040 sec_sound, //!< denotes sound section of config file 00041 sec_invalid //!< denotes an invalid section of config file 00042 }; 00043 00044 //!wirless information 00045 struct wireless_config { 00046 int id; //!< id number (in case you have more than one AIBO) 00047 00048 wireless_config () : id(1) {} //!< constructor 00049 } wireless; 00050 00051 //!vision information 00052 struct vision_config { 00053 int white_balance; //!< white balance 00054 int gain; //!< gain 00055 int shutter_speed; //!< shutter speed 00056 int resolution; //!< resolution 00057 std::vector<std::string> thresh; //!< thresholds 00058 char colors[50]; //!< colors 00059 int rawcam_port; //!< port to send raw frames on 00060 int rawcam_transport; //!< transport protocol: 0 for udp, 1 for tcp 00061 unsigned int rawcam_interval; //!< interval between images: 0 for fast-as-possible, 100 for 10 FPS, 200 for 5 FPS, etc. 00062 int rle_port; //!< port to send RLE frames on 00063 int rle_transport; //!< transport protocol: 0 for udp, 1 for tcp 00064 unsigned int rle_interval; //!< interval between images: 0 for fast-as-possible, 100 for 10 FPS, 200 for 5 FPS, etc. 00065 int region_port; //!< port to send Region information on 00066 int region_transport; //!< transport protocol: 0 for udp, 1 for tcp 00067 int obj_port; //!< port to send object info on 00068 bool restore_image; //!< if true, replaces pixels holding image info with actual image pixels (as much as possible anyway) 00069 J_DCT_METHOD jpeg_dct_method; //!< pick between dct methods for jpeg compression 00070 float aspectRatio; //!< ratio of width to height (x_res/y_res); this is *not* read from configuration file, but set from most recent camera image (or RobotInfo namespace values if no camera image has been received) 00071 float x_range; //!< range of values for the x axis when using generalized coordinates; this is *not* read from configuration file, but set from most recent camera image (or RobotInfo namespace values if no camera image has been received) 00072 float y_range; //!< range of values for the x axis when using generalized coordinates; this is *not* read from configuration file, but set from most recent camera image (or RobotInfo namespace values if no camera image has been received) 00073 00074 //! type of information to send, stored in Config::vision_config::rawcam_encoding 00075 enum encoding_t { 00076 ENCODE_COLOR, //!< send Y, U, and V channels 00077 ENCODE_SINGLE_CHANNEL, //!< send only a single channel (which channel to send is stored in Config::vision_config::rawcam_channel) This is also used for all seg cam images 00078 }; 00079 encoding_t rawcam_encoding; //!< holds whether to send color or single channel 00080 int rawcam_channel; //!< RawCameraGenerator::channel_id_t, if raw_encoding is single channel, this holds the channel to send (computed from rawcam_encoding, not set directly) 00081 00082 //! compression format to use, stored in Config::vision_config::rawcam_compression 00083 enum compression_t { 00084 COMPRESS_NONE, //!< no compression (other than subsampling) 00085 COMPRESS_JPEG, //!< JPEG compression 00086 COMPRESS_RLE //!< RLE compression 00087 }; 00088 compression_t rawcam_compression;//!< holds whether to send jpeg compression 00089 00090 int rawcam_compress_quality;//!< 0-100, compression quality (currently only used by jpeg) 00091 int rawcam_y_skip; //!< resolution level to transmit y channel at 00092 int rawcam_uv_skip; //!< resolution level to transmit uv channel at 00093 int rlecam_skip; //!< resolution level to transmit segmented images at 00094 int rlecam_channel; //!< channel of RLEGenerator to send 00095 compression_t rlecam_compression; //!< what compression to use on the segmented image 00096 int regioncam_skip; //!< resolution level to transmit segmented images at 00097 00098 //!These values represent a "Plumb Bob" model introduced by Brown in 1966 00099 /*!Lens Distortion for Close-Range Photogrammetry - D.C. Brown, Photometric Engineering, pages 855-866, Vol. 37, No. 8, 1971. 00100 * 00101 * Can be computated by 'Camera Calibration Toolbox for Matlab', by Jean-Yves Bouguet: 00102 * http://www.vision.caltech.edu/bouguetj/calib_doc/ */ 00103 //!@name Intrinsic Parameters 00104 float focal_len_x; //!< focal length of camera, in pixels, K11 00105 float focal_len_y; //!< focal length of camera, in pixels, K22 00106 float principle_point_x; //!< center of optical projection, K13 00107 float principle_point_y; //!< center of optical projection, K23 00108 float skew; //!< CCD skew, K12 = skew*focal_len_x 00109 float kc1_r2; //!< r-squared radial distortion 00110 float kc2_r4; //!< r to the 4 radial distortion 00111 float kc5_r6; //!< r to the 6 radial distortion 00112 float kc3_tan1; //!< first tangential correction term 00113 float kc4_tan2; //!< second tangential correctiont term 00114 unsigned int calibration_res_x; // x resolution of images used during calibration 00115 unsigned int calibration_res_y; // y resolution of images used during calibration 00116 00117 //!provides a ray from camera through pixel in image; where possible, use computePixel for better accuracy (i.e. try to always move from world to camera instead of the other way around) 00118 /*! We can't undo some terms of the distortion model -- this is an estimate. 00119 * @param[in] x x position in range [-1,1] 00120 * @param[in] y y position in range [-1,1] 00121 * @param[out] r_x x value of the ray 00122 * @param[out] r_y y value of the ray 00123 * @param[out] r_z z value of the ray (always 1) */ 00124 void computeRay(float x, float y, float& r_x, float& r_y, float& r_z) { 00125 x=(x+1)*calibration_res_x/2; 00126 y=(y+1)*calibration_res_y/2; 00127 float yd=(y-principle_point_y)/focal_len_y; 00128 float xd=(x-principle_point_x)/focal_len_x-skew*yd; 00129 float r2=xd*xd+yd*yd; //estimate of original 00130 float radial=(1 + kc1_r2*r2 + kc2_r4*r2*r2 + kc5_r6*r2*r2*r2); 00131 r_x=(xd - 2*kc3_tan1*x*y - kc4_tan2*(r2+2*x*x))/radial; //estimating tangential component 00132 r_y=(yd - kc3_tan1*(r2+2*y*y) - 2*kc4_tan2*x*y)/radial; //estimating tangential component 00133 r_z=1; 00134 } 00135 00136 //!provides a pixel hit in image by a ray going through the camera frame 00137 /*! Hopefully we'll eventually upgrade this to account for lens distortion 00138 * @param[in] r_x x value of the ray 00139 * @param[in] r_y y value of the ray 00140 * @param[in] r_z z value of the ray 00141 * @param[out] x x position in range [-1,1] 00142 * @param[out] y y position in range [-1,1] */ 00143 void computePixel(float r_x, float r_y, float r_z, float& x, float& y) { 00144 if(r_z==0) { 00145 x=y=0; 00146 return; 00147 } 00148 r_x/=r_z; 00149 r_y/=r_z; 00150 float r2 = r_x*r_x + r_y*r_y; //'r2' for 'radius squared', not 'ray number 2' 00151 float radial=(1 + kc1_r2*r2 + kc2_r4*r2*r2 + kc5_r6*r2*r2*r2); 00152 float xd = radial*r_x + 2*kc3_tan1*r_x*r_y + kc4_tan2*(r2+2*r_x*r_x); 00153 float yd = radial*r_y + kc3_tan1*(r2+2*r_y*r_y) + 2*kc4_tan2*r_x*r_y; 00154 x=focal_len_x*(xd+skew*yd)+principle_point_x; 00155 y=focal_len_y*yd+principle_point_y; 00156 x=2*x/calibration_res_x-1; 00157 y=2*y/calibration_res_y-1; 00158 } 00159 //@} 00160 00161 //!constructor 00162 vision_config() 00163 : white_balance(3), gain(2), shutter_speed(2), resolution(2), 00164 thresh(), colors(), rawcam_port(10011), rawcam_transport(0), rawcam_interval(0), 00165 rle_port(10012), rle_transport(0), rle_interval(0), region_port(0), region_transport(0), obj_port(0), restore_image(true), 00166 jpeg_dct_method(JDCT_IFAST), aspectRatio(CameraResolutionX/(float)CameraResolutionY), 00167 x_range(aspectRatio>1?1:aspectRatio), y_range(aspectRatio>1?1/aspectRatio:1), 00168 rawcam_encoding(ENCODE_COLOR), rawcam_channel(0), 00169 rawcam_compression(COMPRESS_NONE), rawcam_compress_quality(75), rawcam_y_skip(0), 00170 rawcam_uv_skip(0), rlecam_skip(1), rlecam_channel(0), rlecam_compression(COMPRESS_RLE), regioncam_skip(1), 00171 focal_len_x(CameraResolutionX),focal_len_y(CameraResolutionX),principle_point_x(CameraResolutionX/2), 00172 principle_point_y(CameraResolutionY/2),skew(0),kc1_r2(0),kc2_r4(0),kc5_r6(0),kc3_tan1(0),kc4_tan2(0), 00173 calibration_res_x(CameraResolutionX), calibration_res_y(CameraResolutionY) 00174 {} 00175 } vision; 00176 00177 //!core functionality information 00178 struct main_config { 00179 bool seed_rng; //!< if true, will call srand with timestamp data, mangled by current sensor data 00180 int console_port; //!< port to send/receive "console" information on (separate from system console) 00181 int stderr_port; //!< port to send error information to 00182 int error_level; //!< controls amount of info to error port 00183 int debug_level; //!< controls amount of debug info 00184 int verbose_level; //!< controls verbosity of info 00185 int wsjoints_port; //!< port to send joint positions on 00186 int wspids_port; //!< port to send pid info on 00187 int headControl_port; //!< port for receiving head commands 00188 int walkControl_port; //!< port for receiving walk commands 00189 int estopControl_port; //!< port for receiving walk commands 00190 int stewart_port; //!< port for running a stewart platform style of control 00191 int aibo3d_port; //!< port for send/receive of joint positions from Aibo 3D GUI 00192 int wmmonitor_port; //!< port for monitoring Watchable Memory 00193 bool use_VT100; //!< if true, enables VT100 console codes (currently only in Controller menus - 1.3) 00194 unsigned int worldState_interval; //!< time (in milliseconds) to wait between sending WorldState updates over wireless 00195 //!constructor 00196 main_config() 00197 : seed_rng(true), console_port(10001), stderr_port(10002), error_level(0), debug_level(0), 00198 verbose_level(0),wsjoints_port(10031),wspids_port(10032),headControl_port(10052), 00199 walkControl_port(10050),estopControl_port(10053),stewart_port(10055),aibo3d_port(10051), 00200 wmmonitor_port(10061), use_VT100(true), worldState_interval(0) 00201 { } 00202 } main; 00203 00204 //!placeholder 00205 struct behaviors_config { 00206 unsigned int flash_bytes; //!< how many bytes of the IP to flash 00207 bool flash_on_start; //!< whether or not to trigger flashing when initially started 00208 behaviors_config() : flash_bytes(4), flash_on_start(true) {} //!< constructor 00209 } behaviors; 00210 00211 //!controller information 00212 struct controller_config { 00213 int gui_port; //!< port to listen for the GUI to connect to aibo on 00214 char select_snd[50]; //!< sound file to use for "select" action 00215 char next_snd[50]; //!< sound file to use for "next" action 00216 char prev_snd[50]; //!< sound file to use for "prev" action 00217 char read_snd[50]; //!< sound file to use for "read from std-in" action 00218 char cancel_snd[50]; //!< sound file to use for "cancel" action 00219 char error_snd[50]; //!< sound file to use to signal errors 00220 00221 //!constructor 00222 controller_config() : gui_port(10020) { 00223 select_snd[0]=next_snd[0]=prev_snd[0]=read_snd[0]=cancel_snd[0]=error_snd[0]='\0'; 00224 } 00225 } controller; 00226 00227 //!motion information 00228 struct motion_config { 00229 Config* thisconfig; //!<pointer back to the containing config object 00230 std::string root; //!< path on memory stick to "motion" files - for instance, position (.pos) and motion sequence (.mot) 00231 std::string walk; //!< the walk parameter file to load by default for new WalkMC's 00232 std::string kinematics; //!< the kinematics description file to load 00233 std::vector<std::string> kinematic_chains; //!< list of chains to load from #kinematics 00234 float calibration[NumPIDJoints]; //!< multiplier from desired to command for PID joints 00235 char estop_on_snd[50]; //!< sound file to use when e-stop turned on 00236 char estop_off_snd[50]; //!< sound file to use when e-stop turned off 00237 float max_head_tilt_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s 00238 float max_head_pan_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s 00239 float max_head_roll_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s 00240 bool inf_walk_accel; //!< if true, walks should attempt to switch directions immediately; otherwise they should do some kind of software acceleration to more smoothly switch direction 00241 int console_port; //!< port to send/receive "console" information on (separate from system console) 00242 int stderr_port; //!< port to send error information to 00243 00244 //!returns an absolute path if @a is relative (to root), otherwise just @a name 00245 std::string makePath(const std::string& name) { 00246 if(name[0]=='/') 00247 return thisconfig->portPath(name); 00248 if(root[root.size()-1]=='/') 00249 return thisconfig->portPath(root+name); 00250 else 00251 return thisconfig->portPath(root+"/"+name); 00252 } 00253 00254 //!constructor 00255 motion_config(Config* c) 00256 : thisconfig(c), root(), walk(), kinematics(), kinematic_chains(), max_head_tilt_speed(0), 00257 max_head_pan_speed(0), max_head_roll_speed(0), inf_walk_accel(false), console_port(10003), stderr_port(10004) 00258 { 00259 estop_on_snd[0]=estop_off_snd[0]='\0'; 00260 for(unsigned int i=0; i<NumPIDJoints; i++) 00261 calibration[i]=1; 00262 } 00263 private: 00264 motion_config(const motion_config&); //!< don't call 00265 motion_config& operator=(const motion_config&); //!< don't call 00266 } motion; 00267 00268 //!sound information 00269 struct sound_config { 00270 Config* thisconfig; //!<pointer back to the containing config object 00271 std::string root; //!< path to sound clips 00272 unsigned int volume; //!< volume in decibels - the value is interpreted as a signed short, where 0 is full volume, 0x8000 is mute 00273 unsigned int sample_rate; //!< sample rate to send to system, currently only 8000 or 16000 supported 00274 unsigned int sample_bits; //!< sample bit depth, either 8 or 16 00275 std::vector<std::string> preload; //!< list of sounds to preload at boot 00276 00277 //!returns an absolute path if @a is relative (to root), otherwise just @a name 00278 std::string makePath(const std::string& name) { 00279 if(name[0]=='/') 00280 return thisconfig->portPath(name); 00281 if(root[root.size()-1]=='/') 00282 return thisconfig->portPath(root+name); 00283 else 00284 return thisconfig->portPath(root+"/"+name); 00285 } 00286 00287 //! audio streaming configuration 00288 struct streaming_config { 00289 unsigned int mic_port; //!< port for streaming microphone samples 00290 unsigned int mic_sample_rate; //!< sample rate from the microphone 00291 unsigned int mic_sample_bits; //!< sample bit depth from the microphone (either 8 or 16) 00292 bool mic_stereo; //!< whether to stream stereo or mono from the microphone 00293 00294 unsigned int speaker_port; //!< port for streaming speaker samples 00295 unsigned int speaker_frame_length; //!< length of frame sent to the speaker (ms) 00296 unsigned int speaker_max_delay; //!< maximum delay (ms) during playback 00297 00298 //! constructor 00299 streaming_config() : mic_port(10070), mic_sample_rate(16000), 00300 mic_sample_bits(16), mic_stereo(true), 00301 speaker_port(10071), speaker_frame_length(64), 00302 speaker_max_delay(1000) {} 00303 } streaming; 00304 00305 //!constructor 00306 sound_config(Config* c) : thisconfig(c), root(), volume(0xF600), sample_rate(0), sample_bits(0), preload(), streaming() {} 00307 private: 00308 sound_config(const sound_config&); //!< don't call 00309 sound_config& operator=(const sound_config&); //!< don't call 00310 } sound; 00311 00312 //! call this function when it's time to read the configuration file 00313 void readConfig(const std::string& filename); 00314 //! returns the section structure corresponding to the section name given 00315 section_t parseSection(const char* key); 00316 //! pass the section, item name string, item value string - sets the value and returns pointer to the item changed 00317 void* setValue(section_t section, const char *key, const char *value, bool updated=false); 00318 00319 00320 protected: 00321 //! returns true if pattern matches model - pattern may have up to 1 '*', case insensitive 00322 bool matchNoCase(const std::string& model, const std::string& pattern); 00323 00324 //! returns bool value corresponding to a @a value of "t", "f", "true", "false", "y", "n", "yes", "no", or zero/nonzero number 00325 static bool extractBool(const char* value); 00326 00327 //! a prefix representing the file system root, usually indicating the robot's storage root. 00328 /*! When running in the simulator, this is used to pretend that a subdirectory in the project folder (e.g. 'ms') is the root file system */ 00329 std::string fsRoot; 00330 }; 00331 00332 //!allows global access to current settings 00333 extern Config* config; 00334 00335 /*! @file 00336 * @brief Describes Config, which provides global access to system configuration information 00337 * @author alokl (Creator) 00338 * 00339 * $Author: ejt $ 00340 * $Name: tekkotsu-2_4_1 $ 00341 * $Revision: 1.49 $ 00342 * $State: Exp $ 00343 * $Date: 2005/08/07 04:11:03 $ 00344 */ 00345 00346 #endif |
Tekkotsu v2.4.1 |
Generated Tue Aug 16 16:32:46 2005 by Doxygen 1.4.4 |