-
Notifications
You must be signed in to change notification settings - Fork 24
Parameters
Parameters in Ikaros can be numbers, strings, boolean, matrices or rate. They are declared both in the class file (ikc) and in the C++ implementation in the class declaration and accessed through the Bind-function in the Init-function of the module.
A number parameter defines a numerical value to be used in a module. Numbers are stored internally as double. A number parameter is defined in the following way in a class file:
<parameter name="param" type="number" default="3.14" description="a parameter named param that holds a numerical value" />The parameter is set in the module element in a group file:
<module name="mymodule" param="123.45 />To access the parameter in code first define a paramater in the module class then bind it to the value in the group file in the Init function:
parameter p; // In the class declaration
Bind(p, "param"); // In the Init-function
std::cout << p << std::endl; // In the Tick-function; would print the value 123.45A rate parameter is similar to a number parameter except that it scales with tick duration in the kernel. The rate is based on a tick duration of 1 second. If the kernel runs 10 ticks per second, the rate parameter will be divided by 10 when accessed. If the parameter is set to 20, the value that is obtained will be 2.
<parameter name="myrate" type="rate" default="20" />parameter my_rate;In tick:
std::cout << my_rate << std::endl; // Will print 2A rate parameter can be set and then be read back scaled by the dick duration:
my_rate = 55;
std::cout << my_rate << std::endl; // Will print 5.5 if the tick duration is 0.1 (100 ms)A string parameter holds a string value. It is also used in places for lists of comma separated string values.
<parameter name="mystring" type="string" default="abc" />In the code:
parameter my_string; // In class declaration
Bind(my_string, "mystring"); // In Init-function
std::cout << my_string << std::endl; // Will print "abc"Bool parameters are declared in the class file in eth same way as other parameters:
<parameter name="mybool" type="bool" default="false" />Permissible true string values for bools are:
- true
- True
- TRUE
- on
- On
- ON
- yes
- YEs
- YES
All other values are considered false.
Matrix parameters differs from other parameters in that they are bound to a matrix rather than a parameter. They are declared in the same way as other parameters:
<parameter name="mymatrix" type="matrix" default="1, 2, 3; 4, 5, 6" />In the code:
matrix my_matrix; // In class declaration
Bind(my_matrix, "mymatrix"); // In Init-function
std::cout << my_matrix << std::endl; // Will print {{1, 2, 3},{4, 5, 6}}By setting the options attribute for a parameter, the allowed values are limited to those listed in the attributes. How this works depends on the type of the parameter. This is how options are set for a number parameter:
<parameter name="x" type="number" options="A,B,C" />The value of options is a comma separated list of possible values. For a number parameter this is translated to an integer for each possible value. For the options list "A,B,C" the number parameter is set to 0, 1, or 3.
For a string parameters, the string value will be set to either of "A", "B", or "C".
When assigning a value to a parameter with options set, the value will be mapped to one of the allowed values.
It is possible to select which type of control should be used in the Web-interface by specifying the control attribute in a parameter. For example, the following specification will use a checkbox for tor the boolean value (which is the default):
<parameter name="mybool" type="bool" default="false" control="checkbox" />Possible control types are
- textedit
- checkbox
- slider
- menu
For a menu, it is also necessary to specify the possible choices in an options attribute.
Parameters are generally converted to the appropriate type when used in code where allowed by C++.
For example, numbers can be assigned string and bool that are automatically converted to numbers:
parameter b; // A boolean parameter
b = true; // All these lines set the parameter to true
b = 1;
b = "true";More information can be found at the project web site: ikaros-project.