Config.hGo to the documentation of this file.00001
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
00013 class Config {
00014 public:
00015
00016 Config()
00017 : wireless(), vision(), main(), behaviors(), controller(), motion(this),
00018 sound(this), fsRoot()
00019 {setFileSystemRoot("");}
00020
00021 Config(const std::string& filename)
00022 : wireless(), vision(), main(), behaviors(), controller(), motion(this),
00023 sound(this), fsRoot()
00024 { setFileSystemRoot(""); readConfig(filename); }
00025
00026 ~Config() {}
00027
00028 void setFileSystemRoot(const std::string& fsr);
00029 const std::string& getFileSystemRoot() const { return fsRoot; }
00030 std::string portPath(const std::string& path) const;
00031
00032
00033 enum section_t {
00034 sec_wireless=0,
00035 sec_vision,
00036 sec_main,
00037 sec_behaviors,
00038 sec_controller,
00039 sec_motion,
00040 sec_sound,
00041 sec_invalid
00042 };
00043
00044
00045 struct wireless_config {
00046 int id;
00047
00048 wireless_config () : id(1) {}
00049 } wireless;
00050
00051
00052 struct vision_config {
00053 int white_balance;
00054 int gain;
00055 int shutter_speed;
00056 int resolution;
00057 std::vector<std::string> thresh;
00058 char colors[50];
00059 int rawcam_port;
00060 int rawcam_transport;
00061 unsigned int rawcam_interval;
00062 int rle_port;
00063 int rle_transport;
00064 unsigned int rle_interval;
00065 int region_port;
00066 int region_transport;
00067 int obj_port;
00068 bool restore_image;
00069 J_DCT_METHOD jpeg_dct_method;
00070 float aspectRatio;
00071 float x_range;
00072 float y_range;
00073
00074
00075 enum encoding_t {
00076 ENCODE_COLOR,
00077 ENCODE_SINGLE_CHANNEL,
00078 };
00079 encoding_t rawcam_encoding;
00080 int rawcam_channel;
00081
00082
00083 enum compression_t {
00084 COMPRESS_NONE,
00085 COMPRESS_JPEG,
00086 COMPRESS_RLE
00087 };
00088 compression_t rawcam_compression;
00089
00090 int rawcam_compress_quality;
00091 int rawcam_y_skip;
00092 int rawcam_uv_skip;
00093 int rlecam_skip;
00094 int rlecam_channel;
00095 compression_t rlecam_compression;
00096 int regioncam_skip;
00097
00098
00099
00100
00101
00102
00103
00104 float focal_len_x;
00105 float focal_len_y;
00106 float principle_point_x;
00107 float principle_point_y;
00108 float skew;
00109 float kc1_r2;
00110 float kc2_r4;
00111 float kc5_r6;
00112 float kc3_tan1;
00113 float kc4_tan2;
00114 unsigned int calibration_res_x;
00115 unsigned int calibration_res_y;
00116
00117
00118
00119
00120
00121
00122
00123
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;
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;
00132 r_y=(yd - kc3_tan1*(r2+2*y*y) - 2*kc4_tan2*x*y)/radial;
00133 r_z=1;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
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;
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
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
00178 struct main_config {
00179 bool seed_rng;
00180 int console_port;
00181 int stderr_port;
00182 int error_level;
00183 int debug_level;
00184 int verbose_level;
00185 int wsjoints_port;
00186 int wspids_port;
00187 int headControl_port;
00188 int walkControl_port;
00189 int estopControl_port;
00190 int stewart_port;
00191 int aibo3d_port;
00192 int wmmonitor_port;
00193 bool use_VT100;
00194 unsigned int worldState_interval;
00195
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
00205 struct behaviors_config {
00206 unsigned int flash_bytes;
00207 bool flash_on_start;
00208 behaviors_config() : flash_bytes(4), flash_on_start(true) {}
00209 } behaviors;
00210
00211
00212 struct controller_config {
00213 int gui_port;
00214 char select_snd[50];
00215 char next_snd[50];
00216 char prev_snd[50];
00217 char read_snd[50];
00218 char cancel_snd[50];
00219 char error_snd[50];
00220
00221
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
00228 struct motion_config {
00229 Config* thisconfig;
00230 std::string root;
00231 std::string walk;
00232 std::string kinematics;
00233 std::vector<std::string> kinematic_chains;
00234 float calibration[NumPIDJoints];
00235 char estop_on_snd[50];
00236 char estop_off_snd[50];
00237 float max_head_tilt_speed;
00238 float max_head_pan_speed;
00239 float max_head_roll_speed;
00240 bool inf_walk_accel;
00241 int console_port;
00242 int stderr_port;
00243
00244
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
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&);
00265 motion_config& operator=(const motion_config&);
00266 } motion;
00267
00268
00269 struct sound_config {
00270 Config* thisconfig;
00271 std::string root;
00272 unsigned int volume;
00273 unsigned int sample_rate;
00274 unsigned int sample_bits;
00275 std::vector<std::string> preload;
00276
00277
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
00288 struct streaming_config {
00289 unsigned int mic_port;
00290 unsigned int mic_sample_rate;
00291 unsigned int mic_sample_bits;
00292 bool mic_stereo;
00293
00294 unsigned int speaker_port;
00295 unsigned int speaker_frame_length;
00296 unsigned int speaker_max_delay;
00297
00298
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
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&);
00309 sound_config& operator=(const sound_config&);
00310 } sound;
00311
00312
00313 void readConfig(const std::string& filename);
00314
00315 section_t parseSection(const char* key);
00316
00317 void* setValue(section_t section, const char *key, const char *value, bool updated=false);
00318
00319
00320 protected:
00321
00322 bool matchNoCase(const std::string& model, const std::string& pattern);
00323
00324
00325 static bool extractBool(const char* value);
00326
00327
00328
00329 std::string fsRoot;
00330 };
00331
00332
00333 extern Config* config;
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 #endif
|