-
Notifications
You must be signed in to change notification settings - Fork 24
Writing a Simple Module
A module in ikaros is defined in two files, a C++ file that contains the code for the module and a class file that defines the interface to ikaros.
This example describes a minimal module class that demonstrates some basic aspects of ikaros modules.
The file below describes a minimal class file the declares one input, one output and three parameters. The input and outputs are named INPUT and OUTPUT buth they can be named anything. By convention, inputs and outputs are named with capital letters. This file should be saved as "MyModule.ikc".
<class name="MyModule">
<input name="INPUT" description="The input to the module names INPUT" />
<output name="OUTPUT" size="10" description="The output from the module names OUTPUT" />
<parameter name="alpha" type="number" default="42" description="This is a numerical parameter" />
<parameter name="beta" type="string" default="abc" description="This is a string parameter" />
<parameter name="gamma" type="bool" default="false" description="This is a boolean parameter" />
</class>Below is an example of a minimal C++ file for the class file above. This file should be saved as "MyModule.cc". The code defines the class for the module and memebrs for the input, output and parameters. Every module also need an Init and a Tick function. The Init-function is called once during start-up and Tick is called repeatedly while Ikaros is running.
#include "ikaros.h"
using namespace ikaros;
class MyModule: public Module
{
parameter alpha; // Define variables for inputs, outputs and parameters
parameter beta;
parameter gamma;
matrix input;
matrix output;
void Init()
{
Bind(input, "input"); // Get the inputs and outputs and bid then to matrices
Bind(output, "output");
Bind(alpha, "alpha"); // Get parameters and bind them to member variables
Bind(beta, "beta");
Bind(gamma, "gamma");
}
void Tick()
{
// Process the input and produce the output here
}
};
INSTALL_CLASS(MyModule) // Install the class in the Ikaros kernelMore information can be found at the project web site: ikaros-project.