Homepage
Demos
Overview
Downloads
Tutorials
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 #include <jpeglib.h>
00009 
00010 //!provides global access to system configuration information
00011 class Config {
00012  public:
00013   //!constructor
00014   Config(const char* filename)
00015     : wireless(), vision(), main(), behaviors(), controller(), motion(),
00016     sound()
00017     { readConfig(filename); }
00018   //!destructor
00019   ~Config() {}
00020 
00021   //!section IDs
00022   enum section_t {
00023     sec_wireless=0,  //!< denotes wireless section of config file
00024     sec_vision,      //!< denotes vision section of config file
00025     sec_main,        //!< denotes main section of config file, for misc. settings
00026     sec_behaviors,   //!< denotes behaviors section of config file
00027     sec_controller,  //!< denotes controller section of config file
00028     sec_motion,      //!< denotes motion section of config file
00029     sec_sound,       //!< denotes sound section of config file
00030     sec_invalid      //!< denotes an invalid section of config file
00031   };
00032 
00033   //!wirless information
00034   struct wireless_config {
00035     int id; //!< id number (in case you have more than one AIBO)
00036       
00037     wireless_config () : id(1) {} //!< constructor
00038   } wireless;
00039 
00040   //!vision information
00041   struct vision_config {
00042     int white_balance;    //!< white balance
00043     int gain;             //!< gain
00044     int shutter_speed;    //!< shutter speed
00045     int resolution;       //!< resolution
00046     float horizFOV;       //!< horizontal field of view of camera, in radians
00047     float vertFOV;        //!< vertical field of view of camera, in radians
00048     float focal_length;   //!< focal length of the camera (mm)
00049     std::vector<std::string> thresh;      //!< thresholds
00050     char colors[50];      //!< colors
00051     int rawcam_port;      //!< port to send raw frames on
00052     int rawcam_transport; //!< transport protocol: 0 for udp, 1 for tcp
00053     int rle_port;         //!< port to send RLE frames on
00054     int rle_transport;    //!< transport protocol: 0 for udp, 1 for tcp
00055     int obj_port;         //!< port to send object info on
00056     bool restore_image;   //!< if true, replaces pixels holding image info with actual image pixels (as much as possible anyway)
00057     J_DCT_METHOD jpeg_dct_method;  //!< pick between dct methods for jpeg compression
00058 
00059     //! type of information to send, stored in Config::vision_config::rawcam_encoding
00060     enum encoding_t {
00061       ENCODE_COLOR, //!< send Y, U, and V channels
00062       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
00063     };
00064     encoding_t rawcam_encoding; //!< holds whether to send color or single channel
00065     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)
00066     
00067     //! compression format to use, stored in Config::vision_config::rawcam_compression
00068     enum compression_t {
00069       COMPRESS_NONE, //!< no compression (other than subsampling)
00070       COMPRESS_JPEG, //!< JPEG compression
00071       COMPRESS_RLE   //!< RLE compression
00072     };
00073     compression_t rawcam_compression;//!< holds whether to send jpeg compression
00074 
00075     int rawcam_compress_quality;//!< 0-100, compression quality (currently only used by jpeg)
00076     int rawcam_y_skip;     //!< resolution level to transmit y channel at
00077     int rawcam_uv_skip;    //!< resolution level to transmit uv channel at (ignored for jpeg compression)
00078     int rlecam_skip;       //!< resolution level to transmit segmented images at
00079     int rlecam_channel;    //!< channel of RLEGenerator to send
00080     compression_t rlecam_compression; //!< what compression to use on the segmented image
00081 
00082     //!provides a ray from camera through pixel in image
00083     /*! Hopefully we'll eventually upgrade this to account for lens distortion
00084      *  @param[in] x x position in range [-1,1]
00085      *  @param[in] y y position in range [-1,1]
00086      *  @param[out] r_x x value of the ray
00087      *  @param[out] r_y y value of the ray
00088      *  @param[out] r_z z value of the ray (always 1) */
00089     void computeRay(float x, float y, float& r_x, float& r_y, float& r_z) {
00090       r_x=x*tan(horizFOV/2);
00091       r_y=y*tan(vertFOV/2);
00092       r_z=1;
00093     }
00094       
00095     //!provides a pixel hit in image by a ray going through the camera frame
00096     /*! Hopefully we'll eventually upgrade this to account for lens distortion
00097      *  @param[in] r_x x value of the ray
00098      *  @param[in] r_y y value of the ray
00099      *  @param[in] r_z z value of the ray
00100      *  @param[out] x x position in range [-1,1]
00101      *  @param[out] y y position in range [-1,1] */
00102     void computePixel(float r_x, float r_y, float r_z, float& x, float& y) {
00103       x=r_x/(r_z*tan(horizFOV/2));
00104       y=r_y/(r_z*tan(vertFOV/2));
00105     }
00106       
00107     //!constructor
00108     vision_config() : white_balance(3), gain(2), shutter_speed(2), resolution(2), horizFOV(0), vertFOV(0), focal_length(0), thresh(), colors(), rawcam_port(0), rawcam_transport(0), rle_port(0), rle_transport(0), obj_port(0), restore_image(true), jpeg_dct_method(JDCT_IFAST), rawcam_encoding(ENCODE_COLOR), rawcam_channel(0), rawcam_compression(COMPRESS_NONE), rawcam_compress_quality(75), rawcam_y_skip(0), rawcam_uv_skip(0), rlecam_skip(1), rlecam_channel(0), rlecam_compression(COMPRESS_RLE) {}
00109   } vision;
00110   
00111   //!core functionality information
00112   struct main_config {
00113     int console_port;  //!< port to send/receive "console" information on (separate from system console)
00114     int stderr_port;   //!< port to send error information to
00115     int error_level;   //!< controls amount of info to error port
00116     int debug_level;   //!< controls amount of debug info
00117     int verbose_level; //!< controls verbosity of info
00118     int wsjoints_port; //!< port to send joint positions on
00119     int wspids_port;   //!< port to send pid info on
00120     int headControl_port;    //!< port for receiving head commands
00121     int walkControl_port;    //!< port for receiving walk commands
00122     int estopControl_port;     //!< port for receiving walk commands
00123     int aibo3d_port;   //!< port for send/receive of joint positions from Aibo 3D GUI
00124     int wmmonitor_port; //!< port for monitoring Watchable Memory
00125     bool use_VT100;    //!< if true, enables VT100 console codes (currently only in Controller menus - 1.3)
00126 
00127     //!constructor
00128     main_config()
00129       : console_port(0), stderr_port(0), error_level(0), debug_level(0),
00130         verbose_level(0),wsjoints_port(0),wspids_port(0),headControl_port(0),
00131         walkControl_port(0),estopControl_port(0),aibo3d_port(0),
00132         wmmonitor_port(0), use_VT100(true)
00133     { }
00134   } main;
00135 
00136   //!placeholder
00137   struct behaviors_config {
00138     unsigned int flash_bytes; //!< how many bytes of the IP to flash
00139     bool flash_on_start;      //!< whether or not to trigger flashing when initially started
00140     behaviors_config() : flash_bytes(4), flash_on_start(true) {} //!< constructor
00141   } behaviors;
00142     
00143   //!controller information
00144   struct controller_config {
00145     int gui_port;        //!< port to listen for the GUI to connect to aibo on
00146     char select_snd[50]; //!< sound file to use for "select" action
00147     char next_snd[50];   //!< sound file to use for "next" action
00148     char prev_snd[50];   //!< sound file to use for "prev" action
00149     char read_snd[50];   //!< sound file to use for "read from std-in" action
00150     char cancel_snd[50]; //!< sound file to use for "cancel" action
00151     char error_snd[50]; //!< sound file to use to signal errors
00152 
00153     //!constructor
00154     controller_config() : gui_port(0) {
00155       select_snd[0]=next_snd[0]=prev_snd[0]=read_snd[0]=cancel_snd[0]=error_snd[0]='\0';
00156     }
00157   } controller;
00158     
00159   //!motion information
00160   struct motion_config {
00161     std::string root;       //!< path on memory stick to "motion" files - for instance, position (.pos) and motion sequence (.mot)
00162     std::string walk;       //!< the walk parameter file to load by default for new WalkMC's
00163     std::string kinematics;  //!< the kinematics description file to load
00164     std::vector<std::string> kinematic_chains; //!< list of chains to load from #kinematics
00165     float calibration[NumPIDJoints]; //!< multiplier from desired to command for PID joints
00166     char estop_on_snd[50];  //!< sound file to use when e-stop turned on
00167     char estop_off_snd[50]; //!< sound file to use when e-stop turned off
00168     float max_head_tilt_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s
00169     float max_head_pan_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s
00170     float max_head_roll_speed; //!< max speed for the head joints, used by HeadPointerMC; rad/s
00171     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
00172     int console_port;  //!< port to send/receive "console" information on (separate from system console)
00173     int stderr_port;   //!< port to send error information to
00174 
00175     //!returns an absolute path if @a is relative (to root), otherwise just @a name
00176     std::string makePath(const std::string& name) { 
00177       if(name[0]=='/')
00178         return name;
00179       if(root[root.size()-1]=='/')
00180         return root+name;
00181       else
00182         return root+"/"+name;
00183     }
00184 
00185     //!constructor
00186     motion_config()
00187       : root(), walk(), kinematics(), kinematic_chains(), max_head_tilt_speed(0),
00188         max_head_pan_speed(0), max_head_roll_speed(0), inf_walk_accel(false), console_port(0), stderr_port(0)
00189     {
00190       estop_on_snd[0]=estop_off_snd[0]='\0';
00191       for(unsigned int i=0; i<NumPIDJoints; i++)
00192         calibration[i]=1;
00193     }
00194   } motion;
00195 
00196   //!sound information
00197   struct sound_config {
00198     std::string root;         //!< path to sound clips
00199     unsigned int volume;      //!< volume in decibels - the value is interpreted as a signed short, where 0 is full volume, 0x8000 is mute
00200     unsigned int sample_rate; //!< sample rate to send to system, currently only 8000 or 16000 supported
00201     unsigned int sample_bits; //!< sample bit depth, either 8 or 16
00202     std::vector<std::string> preload; //!< list of sounds to preload at boot
00203       
00204     //!returns an absolute path if @a is relative (to root), otherwise just @a name
00205     std::string makePath(const std::string& name) { 
00206       if(name[0]=='/')
00207         return name;
00208       if(root[root.size()-1]=='/')
00209         return root+name;
00210       else
00211         return root+"/"+name;
00212     }
00213     
00214     //! audio streaming configuration
00215     struct streaming_config {
00216       unsigned int mic_port;        //!< port for streaming microphone samples
00217       unsigned int mic_sample_rate; //!< sample rate from the microphone
00218       unsigned int mic_sample_bits; //!< sample bit depth from the microphone (either 8 or 16)
00219       bool mic_stereo; //!< whether to stream stereo or mono from the microphone
00220       
00221       unsigned int speaker_port;    //!< port for streaming speaker samples
00222       unsigned int speaker_frame_length; //!< length of frame sent to the speaker (ms)
00223       unsigned int speaker_max_delay; //!< maximum delay (ms) during playback
00224 
00225       //! constructor
00226       streaming_config() : mic_port(0), mic_sample_rate(16000),
00227       mic_sample_bits(16), mic_stereo(true),
00228       speaker_port(0), speaker_frame_length(64),
00229       speaker_max_delay(1000) {}
00230     } streaming;
00231 
00232     //!constructor
00233     sound_config() : root(), volume(0xF600), sample_rate(0), sample_bits(0), preload(), streaming() {}
00234   } sound;
00235 
00236   //! call this function when it's time to read the configuration file
00237   void readConfig(const char* filename);
00238   //! returns the section structure corresponding to the section name given
00239   section_t parseSection(const char* key);
00240   //! pass the section, item name string, item value string - sets the value and returns pointer to the item changed
00241   void* setValue(section_t section, const char *key, const char *value, bool updated=false);
00242 
00243 
00244 protected:
00245   //! returns true if pattern matches model - pattern may have up to 1 '*', case insensitive
00246   bool matchNoCase(const std::string& model, const std::string& pattern);
00247 
00248   //! returns bool value corresponding to a @a value of "t", "f", "true", "false", "y", "n", "yes", "no", or zero/nonzero number
00249   static bool extractBool(const char* value);
00250 };
00251 
00252 //!allows global access to current settings
00253 extern Config* config;
00254 
00255 /*! @file
00256  * @brief Describes Config, which provides global access to system configuration information
00257  * @author alokl (Creator)
00258  *
00259  * $Author: ejt $
00260  * $Name: tekkotsu-2_3 $
00261  * $Revision: 1.41 $
00262  * $State: Exp $
00263  * $Date: 2005/01/20 23:18:43 $
00264  */
00265 
00266 #endif

Tekkotsu v2.3
Generated Sat Jan 29 02:25:21 2005 by Doxygen 1.4.0