MCA2 Puma Tutorial Chapter 4

From Mca2
Revision as of 09:26, 14 August 2009 by Karaman (talk | contribs)
Jump to navigationJump to search

GO BACK HOME

Using Parameters

A part is the interface to the external environment for modules and groups. This also includes command line parameter input. There are many standard parameters in order to configure the program behaviour, but the programmer is also able to define application specific parameters. The standard command line parameters are explained in section 3.3 of the programmers guide .

In this chapter we learn how to use command line parameters inside a part (section 4.1 and 4.2). These parameters are then forwarded to the module which is executed inside our part (section 4.3). In section 4.4 it is explained what the default method parameters of the module constructor mean.

Note that it is important to distinguish between the different types of parameters: First of all we have the method parameters as usually used in C++. Additionally MCA provides internal part parameters and internal module parameters which can be used to adjust the behaviour to a specific configuration. 4.1. Define program parameters

Program parameters can be easily defined using the tPartParameter struct. We also recommend to use enumerations as for all array definitions in MCA. The following example defines parameters for setting name, min and max angle values and angular velocity for our example program pJointSimulation.C. Add the following lines just before void initPartDescription() in the file pJointSimulation.C:

> enum {
>   eOPT_NAME,
>   eOPT_MIN_ANGLE,
>   eOPT_MAX_ANGLE,
>   eOPT_ANGULAR_VELOCITY,
>   eOPT_DIMENSION
> };
>
> tPartParameter parameter[eOPT_DIMENSION+1]={
>   {"name:", "set the module name"},
>   {"min:","set the minimum joint angle"},
>   {"max:","set the maximum joint angle"},
>   {"v:","set the angular velocity"},
>   {0,0}
> };

Our part uses these parameter definitions if we add an additional entry into the function initPartDescription():

> void initPartDescription()
> {
>   SetProgramDescription("\n This Program simulates a single joint.\n");
>   SetProgramParameter(parameter);
> }

Save the changed pJointSimulation.C as pJointSimulation2.C, copy and change the entry in SConscript and compile everything:

> # this is a -*- python -*- file
> # -----------------------------
> Import('*')
>
>
> # ------------------
> # joint_simulation
> # simulate one joint
> # ------------------
> jointsimulation = MCAProgram('joint_simulation')
> jointsimulation.addSourceFiles("""
> pJointSimulation.C
> mJointSimulation.C
> """)
>
> jointsimulation.addLibs('mca2_kernel')
> jointsimulation.BuildIt()
> 
> # ------------------
> # joint_simulation with parameters
> # simulate one joint
> # ------------------
> jointsimulation2 = MCAProgram('joint_simulation2',jointsimulation.BuildEnv())
> jointsimulation2.AddSourceFiles("""
> pJointSimulation2.cpp
> mJointSimulation2.cpp
> """)
>
> jointsimulation2.Build()