Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Facilities for Configuration and Message Display


Detailed Description

RHexLib provides utility functions for maintaining system-wide access to a common configuration database. The module manager maintains a central database for named configuration symbols. The function MMReadConfigFile can be used to read configuration files into this database. Modules can then access this database using the functions MMGetFloatSymbol, MMGetArraySymbol, MMGetStringSymbol and MMGetStrArraySymbol. Finally, the function MMGetCurrentConfig can be used to get a handle to the configuration symbol database for explicit access.

RHexLib also provides a number of functions for dispatching prioritized messages to the user. These messages are either displayed on the console, or transferred over the network to a message logging client for remote display. Modules can use the functions MMMessage, MMWarning and MMFatalError to dispatch messages.

RC file construction and use

RC files are basic input files to the rhexLib program. The tokenizer accepts a number of basic types as shown in the example below.

float dgain  = 0.67; 
string angleunit = "degrees"; 
int directions    = 1   1   -1  1   -1;  
bool stopflags   = 0   0   1   0   1;

In the above example you can define floats, strings, ints and boolean types. The type name must accompany the variable name and if you list more than one value of that type as in the ``directions'' variable an array of that type will be created.

You can also define a structArray type as follows:

structArray  p_one =
    {
        float smooth  = 0.05;
        float p_gain  = 24.0;
        float d_gain  = 0.67;
        string angle_unit = "degrees";
    }
    {
        float times       = 0.0 0.5 1.0 1.5 2.0;
        float angles      = 0.0 50  180 50  40;
        int directions    = 1   1   -1  1   -1;
        bool stop_flags   = 0   0   1   0   1;
    };

In this example the types defined are combined into a struct called p_one.

Note: Proper naming of variables is essential to avoid name-space pollution.

All RC file variables are potentially included in a single program and are global to the entire program. Therefore, one should take care to follow a strict naming convention that prepends the name of the controller or module most likely to use the rc file variable. For example if you write a controller to fly rhex and need a P gain, prepending ``fly'' to ``kp '' would be an appropriate naming etc.

How to Include and Then Access Variables

In order to gain access to your variables you will need to tell your program about the rc file you have created. The module manager allows this via the MMReadConfigFile() function. This function will first look in the current directory then the directory specified in the environment variable ROBOT_DIR and finally CONFIG_DIR for the file you want to include. CONFIG_DIR and ROBOT_DIR are both environment variables defined from the shell. If the same file is in more than one of those directories the first copy that is located is used.

After the config files are included in your program you can access the variables in your code through the Module Manager function calls detailed above.

Using list.rc

In order to reduce the number of calls to MMReadConfigFile(), the configuration file parser allows the inclusion directives. The recommended practice is to create a single file ``list.rc'' which resides in the directory CONFIG_DIR and includes all the rc files necessary to run the main program. An example is shown below:

%include module_manager.rc
%include comm_manager.rc
%include sitstand.rc
%include rhexwalker.rc
%include rhexlogger.rc

This approach should be taken to minimize explicit calls to MMReadConfigFile() when a program needs to include many files. It eliminates the need for recompilation when the set of files that need to be included has to be changed.

Using robotlist.rc

It also turns out that the values for some configuration variables are platform dependent. So, the user may want to define the same set of variables for different platforms, but with different values. In such cases, the recommended practice is to create a file called "robotlist.rc", which is then placed in the directory ROBOT_DIR. The programmer then needs to call MMReadConfigFile("robotlist.rc" ) which will include the proper file based on the environment variable definition. This provides a convenient way of choosing a particular platform by simply redefining an environment variable.


Functions

void MMMessage (char *msg, unsigned int prio=200)
void MMWarning (char *fn, char *msg)
void MMFatalError (char *fn, char *msg)
void MMPrintModules (void)
void MMReadConfigFile (const char *fn)
utils::ConfigFile * MMGetCurrentConfig (void)
void MMPrintSymbols (void)
float MMGetFloatSymbol (const char *n, const float def)
Floats MMGetArraySymbol (const char *n)
void MMGetStringSymbol (const char *n, char *str, const char *def)
Strings MMGetStrArraySymbol (const char *n)


Function Documentation

void MMFatalError char *  fn,
char *  msg
[inline]
 

This function is used to issue a fatal error message and terminate program execution. The message is either displayed on the console or on a network client if registered. This function never returns.

Floats MMGetArraySymbol const char *  n  )  [inline]
 

This function queries the configuration database for an entry with the given name and floating point array type. If undefined, an empty array is returned.

utils::ConfigFile* MMGetCurrentConfig void   )  [inline]
 

This function returns a handle to the system-wide configuration database for explicit access.

float MMGetFloatSymbol const char *  n,
const float  def
[inline]
 

This function queries the configuration database for an entry with the given name and floating point type. If undefined, the specified default value is returned.

Strings MMGetStrArraySymbol const char *  n  )  [inline]
 

This function queries the configuration database for an entry with the given name and string array type. If undefined, an empty array is returned.

void MMGetStringSymbol const char *  n,
char *  str,
const char *  def
[inline]
 

This function queries the configuration database for an entry with the given name and string type. If undefined, the specified default value is returned.

void MMMessage char *  msg,
unsigned int  prio = 200
[inline]
 

This function is used to issue an informational message at the specified priority. The message is either displayed on the console or on a network client if registered. The priority value can be used by remote message clients to filter incoming messages.

void MMPrintModules void   )  [inline]
 

This function prints out on the console, a list of modules currently in the module manager's database. Note that console output has significant computational cost, so this function should not be called from within module execution.

void MMPrintSymbols void   )  [inline]
 

This function prints out the current contents of the configuration database.

void MMReadConfigFile const char *  fn  )  [inline]
 

This function reads the specified file and updates the system-wide configuration database with the symbols defined in the file.

void MMWarning char *  fn,
char *  msg
[inline]
 

This function is used to issue a warning message from a recoverable error. The message is either displayed on the console or on a network client if registered. The priority value can be used by remote message clients to filter incoming messages.


RHexLib Reference Documentation