How to write a module

From Wiki for iCub and Friends
Jump to navigation Jump to search

Although you can contribute any working piece of software to the repository, we require that your module respects a minimum set of requirements. These are listed here:

  • Module configuration: it should be possible to change the parameters used by the module from the command line. Paths to configuration files should not be machine or configuration dependent.
  • Remotization: it should be possible to execute the module remotely, using yarprun. If the module accepts commands, there should be a yarp interface that allows to send these commands to the module (one or more yarp ports).
  • Clean shutdown: make sure there is a way to shut down the module without killing it.

The software infrastructures we provide facilitate writing modules that have these characteristics.

We provide sections in the manual and software tutorials that explain how to achieve this behavior.

Module configuration

The class ResourceFinder in YARP simplifies this task.

Remotization and clean shutdown

Modules are managed using the yarprun utility. In particular yarprun uses signals to stop or kill modules. Normal shutdown is requested by sig-term (the equivalent of hitting ctrl+c at the console). This means that your module will have to intercept and correctly handle this signal.

The helper class RFModule in YARP deals with this automatically, so you do not have to do anything special. It also supports the use of the ResourceFinder class described above.

This tutorial shows how to use the RFModule: