Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Config.h

Go 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 segcam_port;         //!< port to send segmented color frames on
00063     int segcam_transport;    //!< transport protocol: 0 for udp, 1 for tcp
00064     unsigned int segcam_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     bool region_calc_total; //!< if true, RegionGenerator will calculate total area for each color (has to run through the region list for each color)
00070     J_DCT_METHOD jpeg_dct_method;  //!< pick between dct methods for jpeg compression
00071     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)
00072     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)
00073     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)
00074 
00075     //! type of information to send, stored in Config::vision_config::rawcam_encoding
00076     enum encoding_t {
00077       ENCODE_COLOR, //!< send Y, U, and V channels
00078       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
00079     };
00080     encoding_t rawcam_encoding; //!< holds whether to send color or single channel
00081     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)
00082     
00083     //! compression format to use, stored in Config::vision_config::rawcam_compression
00084     enum compression_t {
00085       COMPRESS_NONE, //!< no compression (other than subsampling)
00086       COMPRESS_JPEG, //!< JPEG compression
00087       COMPRESS_PNG, //!< PNG compression
00088       COMPRESS_RLE   //!< RLE compression
00089     };
00090     compression_t rawcam_compression;//!< holds whether to send jpeg compression
00091 
00092     int rawcam_compress_quality;//!< 0-100, compression quality (currently only used by jpeg)
00093     int rawcam_y_skip;     //!< resolution level to transmit y channel at
00094     int rawcam_uv_skip;    //!< resolution level to transmit uv channel at
00095     int segcam_skip;       //!< resolution level to transmit segmented images at
00096     int segcam_channel;    //!< channel to send (which color threshold map to use)
00097     compression_t segcam_compression; //!< what compression to use on the segmented image
00098     int regioncam_skip;    //!< resolution level to transmit segmented images at 
00099 
00100     //!These values represent a "Plumb Bob" model introduced by Brown in 1966
00101     /*!Lens Distortion for Close-Range Photogrammetry -  D.C. Brown, Photometric Engineering, pages 855-866, Vol. 37, No. 8, 1971.
00102      * 
00103      * Can be computated by 'Camera Calibration Toolbox for Matlab', by Jean-Yves Bouguet:
00104      * http://www.vision.caltech.edu/bouguetj/calib_doc/ */
00105     //!@name Intrinsic Parameters
00106     float focal_len_x; //!< focal length of camera, in pixels, K11
00107     float focal_len_y; //!< focal length of camera, in pixels, K22
00108     float principle_point_x; //!< center of optical projection, K13
00109     float principle_point_y; //!< center of optical projection, K23
00110     float skew; //!< CCD skew, K12 = skew*focal_len_x
00111     float kc1_r2; //!< r-squared radial distortion
00112     float kc2_r4; //!< r to the 4 radial distortion
00113     float kc5_r6; //!< r to the 6 radial distortion
00114     float kc3_tan1; //!< first tangential correction term
00115     float kc4_tan2; //!< second tangential correctiont term
00116     unsigned int calibration_res_x; // x resolution of images used during calibration
00117     unsigned int calibration_res_y; // y resolution of images used during calibration
00118 
00119     //!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)
00120     /*! We can't undo some terms of the distortion model -- this is an estimate.
00121      *  @param[in] x x position in range [-1,1]
00122      *  @param[in] y y position in range [-1,1]
00123      *  @param[out] r_x x value of the ray
00124      *  @param[out] r_y y value of the ray
00125      *  @param[out] r_z z value of the ray (always 1) */
00126     void computeRay(float x, float y, float& r_x, float& r_y, float& r_z) {
00127       x=(x+1)*calibration_res_x/2;
00128       y=(y+1)*calibration_res_y/2;
00129       float yd=(y-principle_point_y)/focal_len_y;
00130       float xd=(x-principle_point_x)/focal_len_x-skew*yd;
00131       float r2=xd*xd+yd*yd; //estimate of original
00132       float radial=(1 + kc1_r2*r2 + kc2_r4*r2*r2 + kc5_r6*r2*r2*r2);
00133       r_x=(xd - 2*kc3_tan1*xd*yd - kc4_tan2*(r2+2*xd*xd))/radial; //estimating tangential component
00134       r_y=(yd - kc3_tan1*(r2+2*yd*yd) - 2*kc4_tan2*xd*yd)/radial; //estimating tangential component
00135       r_z=1;
00136     }
00137       
00138     //!provides a pixel hit in image by a ray going through the camera frame
00139     /*! Hopefully we'll eventually upgrade this to account for lens distortion
00140      *  @param[in] r_x x value of the ray
00141      *  @param[in] r_y y value of the ray
00142      *  @param[in] r_z z value of the ray
00143      *  @param[out] x x position in range [-1,1]
00144      *  @param[out] y y position in range [-1,1] */
00145     void computePixel(float r_x, float r_y, float r_z, float& x, float& y) {
00146       if(r_z==0) {
00147         x=y=0;
00148         return;
00149       }
00150       r_x/=r_z;
00151       r_y/=r_z;
00152       float r2 = r_x*r_x + r_y*r_y; //'r2' for 'radius squared', not 'ray number 2'
00153       float radial=(1 + kc1_r2*r2 + kc2_r4*r2*r2 + kc5_r6*r2*r2*r2);
00154       float xd = radial*r_x + 2*kc3_tan1*r_x*r_y + kc4_tan2*(r2+2*r_x*r_x);
00155       float yd = radial*r_y + kc3_tan1*(r2+2*r_y*r_y) + 2*kc4_tan2*r_x*r_y;
00156       x=focal_len_x*(xd+skew*yd)+principle_point_x;
00157       y=focal_len_y*yd+principle_point_y;
00158       x=2*x/calibration_res_x-1;
00159       y=2*y/calibration_res_y-1;
00160     }
00161     //@}
00162     
00163     //!constructor
00164     vision_config()
00165       : white_balance(3), gain(2), shutter_speed(2), resolution(2),
00166         thresh(), rawcam_port(10011), rawcam_transport(0), rawcam_interval(0),
00167         segcam_port(10012), segcam_transport(0), segcam_interval(0), region_port(0), region_transport(0), obj_port(0), restore_image(true), region_calc_total(true),
00168         jpeg_dct_method(JDCT_IFAST), aspectRatio(CameraResolutionX/(float)CameraResolutionY),
00169         x_range(aspectRatio>1?1:aspectRatio), y_range(aspectRatio>1?1/aspectRatio:1), 
00170         rawcam_encoding(ENCODE_COLOR), rawcam_channel(0),
00171         rawcam_compression(COMPRESS_NONE), rawcam_compress_quality(75), rawcam_y_skip(0),
00172         rawcam_uv_skip(0), segcam_skip(1), segcam_channel(0), segcam_compression(COMPRESS_RLE), regioncam_skip(1),
00173         focal_len_x(CameraResolutionX),focal_len_y(CameraResolutionX),principle_point_x(CameraResolutionX/2),
00174         principle_point_y(CameraResolutionY/2),skew(0),kc1_r2(0),kc2_r4(0),kc5_r6(0),kc3_tan1(0),kc4_tan2(0),
00175         calibration_res_x(CameraResolutionX), calibration_res_y(CameraResolutionY)
00176     {colors[0]='\0';}
00177   } vision;
00178   
00179   //!core functionality information
00180   struct main_config {
00181     bool seed_rng;     //!< if true, will call srand with timestamp data, mangled by current sensor data
00182     int console_port;  //!< port to send/receive "console" information on (separate from system console)
00183     //! types that #consoleMode can take on
00184     enum consoleMode_t {
00185       CONTROLLER, //!< all input is interpreted as Controller commands, using same syntax as the GUI sends
00186       TEXTMSG, //!< all input is broadcast as a text message event
00187       AUTO //!< if the GUI is connected, interpret as text messages, otherwise as controller commands.  This was the historical behavior, but seems to be more confusing than helpful.
00188     };
00189     //! determines how input on #console_port is interpreted
00190     consoleMode_t consoleMode; 
00191     int stderr_port;   //!< port to send error information to
00192     int error_level;   //!< controls amount of info to error port
00193     int debug_level;   //!< controls amount of debug info
00194     int verbose_level; //!< controls verbosity of info
00195     int wsjoints_port; //!< port to send joint positions on
00196     int wspids_port;   //!< port to send pid info on
00197     int headControl_port;    //!< port for receiving head commands
00198     int walkControl_port;    //!< port for receiving walk commands
00199     int estopControl_port;     //!< port for receiving walk commands
00200     int stewart_port;  //!< port for running a stewart platform style of control
00201     int aibo3d_port;   //!< port for send/receive of joint positions from Aibo 3D GUI
00202     int wmmonitor_port; //!< port for monitoring Watchable Memory
00203     bool use_VT100;    //!< if true, enables VT100 console codes (currently only in Controller menus - 1.3)
00204     unsigned int worldState_interval; //!< time (in milliseconds) to wait between sending WorldState updates over wireless
00205     //!constructor
00206     main_config()
00207       : seed_rng(true), console_port(10001), consoleMode(CONTROLLER), stderr_port(10002), error_level(0), debug_level(0),
00208         verbose_level(0),wsjoints_port(10031),wspids_port(10032),headControl_port(10052),
00209         walkControl_port(10050),estopControl_port(10053),stewart_port(10055),aibo3d_port(10051),
00210         wmmonitor_port(10061), use_VT100(true), worldState_interval(0)
00211     { }
00212   } main;
00213 
00214   //!placeholder
00215   struct behaviors_config {
00216     unsigned int flash_bytes; //!< how many bytes of the IP to flash
00217     bool flash_on_start;      //!< whether or not to trigger flashing when initially started
00218     behaviors_config() : flash_bytes(4), flash_on_start(true) {} //!< constructor
00219   } behaviors;
00220     
00221   //!controller information
00222   struct controller_config {
00223     int gui_port;        //!< port to listen for the GUI to connect to aibo on
00224     char select_snd[50]; //!< sound file to use for "select" action
00225     char next_snd[50];   //!< sound file to use for "next" action
00226     char prev_snd[50];   //!< sound file to use for "prev" action
00227     char read_snd[50];   //!< sound file to use for "read from std-in" action
00228     char cancel_snd[50]; //!< sound file to use for "cancel" action
00229     char error_snd[50]; //!< sound file to use to signal errors
00230 
00231     //!constructor
00232     controller_config() : gui_port(10020) {
00233       select_snd[0]=next_snd[0]=prev_snd[0]=read_snd[0]=cancel_snd[0]=error_snd[0]='\0';
00234     }
00235   } controller;
00236     
00237   //!motion information
00238   struct motion_config {
00239     Config* thisconfig;  //!<pointer back to the containing config object
00240     std::string root;       //!< path on memory stick to "motion" files - for instance, position (.pos) and motion sequence (.mot)
00241     std::string walk;       //!< the walk parameter file to load by default for new WalkMC's
00242     std::string kinematics;  //!< the kinematics description file to load
00243     std::vector<std::string> kinematic_chains; //!< list of chains to load from #kinematics
00244     float calibration[NumPIDJoints]; //!< multiplier from desired to command for PID joints
00245     char estop_on_snd[50];  //!< sound file to use when e-stop turned on
00246     char estop_off_snd[50]; //!< sound file to use when e-stop turned off
00247     float max_head_tilt_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s
00248     float max_head_pan_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s
00249     float max_head_roll_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s
00250     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
00251     int console_port;  //!< port to send/receive "console" information on (separate from system console)
00252     int stderr_port;   //!< port to send error information to
00253 
00254     //!returns an absolute path if @a is relative (to root), otherwise just @a name
00255     std::string makePath(const std::string& name) { 
00256       if(name[0]=='/')
00257         return thisconfig->portPath(name);
00258       if(root[root.size()-1]=='/')
00259         return thisconfig->portPath(root+name);
00260       else
00261         return thisconfig->portPath(root+"/"+name);
00262     }
00263 
00264     //!constructor
00265     motion_config(Config* c)
00266       : thisconfig(c), root(), walk(), kinematics(), kinematic_chains(), max_head_tilt_speed(0),
00267         max_head_pan_speed(0), max_head_roll_speed(0), inf_walk_accel(false), console_port(10003), stderr_port(10004)
00268     {
00269       estop_on_snd[0]=estop_off_snd[0]='\0';
00270       for(unsigned int i=0; i<NumPIDJoints; i++)
00271         calibration[i]=1;
00272     }
00273   private:
00274     motion_config(const motion_config&); //!< don't call
00275     motion_config& operator=(const motion_config&); //!< don't call
00276   } motion;
00277 
00278   //!sound information
00279   struct sound_config {
00280     Config* thisconfig;  //!<pointer back to the containing config object
00281     std::string root;         //!< path to sound clips
00282     unsigned int volume;      //!< volume in decibels - the value is interpreted as a signed short, where 0 is full volume, 0x8000 is mute
00283     unsigned int sample_rate; //!< sample rate to send to system, currently only 8000 or 16000 supported
00284     unsigned int sample_bits; //!< sample bit depth, either 8 or 16
00285     std::vector<std::string> preload; //!< list of sounds to preload at boot
00286     float pitchConfidenceThreshold; //!< confidence threshold required to generate a pitch event [0-1]
00287       
00288     //!returns an absolute path if @a is relative (to root), otherwise just @a name
00289     std::string makePath(const std::string& name) { 
00290       if(name[0]=='/')
00291         return thisconfig->portPath(name);
00292       if(root[root.size()-1]=='/')
00293         return thisconfig->portPath(root+name);
00294       else
00295         return thisconfig->portPath(root+"/"+name);
00296     }
00297     
00298     //! audio streaming configuration
00299     struct streaming_config {
00300       unsigned int mic_port;        //!< port for streaming microphone samples
00301       unsigned int mic_sample_rate; //!< sample rate from the microphone
00302       unsigned int mic_sample_bits; //!< sample bit depth from the microphone (either 8 or 16)
00303       bool mic_stereo; //!< whether to stream stereo or mono from the microphone
00304       
00305       unsigned int speaker_port;    //!< port for streaming speaker samples
00306       unsigned int speaker_frame_length; //!< length of frame sent to the speaker (ms)
00307       unsigned int speaker_max_delay; //!< maximum delay (ms) during playback
00308 
00309       //! constructor
00310       streaming_config() : mic_port(10070), mic_sample_rate(16000),
00311       mic_sample_bits(16), mic_stereo(true),
00312       speaker_port(10071), speaker_frame_length(64),
00313       speaker_max_delay(1000) {}
00314     } streaming;
00315 
00316     //!constructor
00317     sound_config(Config* c) : thisconfig(c), root(), volume(0xF600), sample_rate(0), sample_bits(0), preload(), pitchConfidenceThreshold(.6f), streaming() {}
00318   private:
00319     sound_config(const sound_config&); //!< don't call
00320     sound_config& operator=(const sound_config&); //!< don't call
00321   } sound;
00322 
00323   //! call this function when it's time to read the configuration file
00324   void readConfig(const std::string& filename);
00325   //! returns the section structure corresponding to the section name given
00326   section_t parseSection(const char* key);
00327   //! pass the section, item name string, item value string - sets the value and returns pointer to the item changed
00328   void* setValue(section_t section, const char *key, const char *value, bool updated=false);
00329 
00330 
00331 protected:
00332   //! returns true if pattern matches model - pattern may have up to 1 '*', case insensitive
00333   bool matchNoCase(const std::string& model, const std::string& pattern);
00334 
00335   //! returns bool value corresponding to a @a value of "t", "f", "true", "false", "y", "n", "yes", "no", or zero/nonzero number
00336   static bool extractBool(const char* value);
00337   
00338   //! a prefix representing the file system root, usually indicating the robot's storage root.
00339   /*! 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 */
00340   std::string fsRoot;
00341 };
00342 
00343 //!allows global access to current settings
00344 extern Config* config;
00345 
00346 /*! @file
00347  * @brief Describes Config, which provides global access to system configuration information
00348  * @author alokl (Creator)
00349  *
00350  * $Author: ejt $
00351  * $Name: tekkotsu-3_0 $
00352  * $Revision: 1.55 $
00353  * $State: Exp $
00354  * $Date: 2006/09/21 21:26:08 $
00355  */
00356 
00357 #endif

Tekkotsu v3.0
Generated Wed Oct 4 00:03:42 2006 by Doxygen 1.4.7