MCA Logo
MCA Online Reference Documentation
Main Index

1.3. Inherit from modules

Inheritances from modules are useful if sense or control methods can be reused but additional funcionality is needed. Another reason are initialization of hardware components within a constructor but different methods in controle or sense, or if only the already defined IOs are to be reused.

Of course, if none of the modules interfaces stay untouched, there is nothing to be considered specially. Only common rules in C++ inheritance are of relevance.

If IOs have to be changed i.e. they need to be overwritten or appended. Then the base class is not allowed to fix the module. Therefore the fixit parameter of its constructor has to be set to false.

If an IO has to be overwritten, i.e. the old definition is deleted and a new one is created, the Init.... functions are used as described in the last section. If the old IOs have only to be appended corrsponding Append... functions are available. Next example shows, how to use these:

Example 1-13. Derived modules: appending IO initialization

 mBetaJoint::mBetaJoint(tParent *parent,bool fixit)
   if (fixit) FixIt();

The controller output enums are defined as usual. The sensor output enums need an additional entry:

Example 1-14. Derived modules: appending IO definition

     Anonymous enumeration typ which contains the indices of the
    sensor outputs.
  enum {
    eSO_ADD_ON_1=mAlphaJoint::eSO_DIMENSION,  /*!< just an example how to append IOs */
    eSO_ADD_ON_2,       /*!< just an example how to append IOs */
    eSO_DIMENSION /*!< Endmarker and Dimension */

In both cases the corresponing descriptions are defined as in a normal module. The Init... and Append... functions consider the special cases.

Note that the FixIt() function must not be called before all IOs are completely defined. Therefore the parents constructor needs a false as fixit value in order to not call the FixIt function.