Skip to content

Writing a Simple Module

ikaros-project edited this page Aug 3, 2024 · 6 revisions

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.

Minimal class file

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>

Minimal C++ file

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 kernel

Clone this wiki locally