In this tutorial we show more details of how to write a YARP module using the module helper class.
Introduction
The RFModule helper class simplify writing a generic module. It provides support for:
- Perform periodic activities
- Handle signals, catch termination and perform smooth shutdown
- Parses messages from a port to monitor module activity and set/get parameters
- Use the ResourceFinder class to handle parameters
You do not need to understand the details of yarp::os::ResourceFinder to proceed with this tutorial. However it may be useful: ResourceFinder Tutorials and Specification.
Code
This is how a module will look like:
28 std::cout <<
"[" << count <<
"]" <<
" updateModule..." <<
'\n';
34 std::cout <<
"Got something, echo is on" <<
'\n';
48 if (!handlerPort.
open(
"/myModule"))
61 std::cout <<
"Interrupting your module, for port cleanup" <<
'\n';
68 std::cout <<
"Calling close function\n";
74 int main(
int argc,
char * argv[])
86 std::cout <<
"Configuring and starting module.\n";
88 if (!
module.runModule(rf)) {
89 std::cerr <<
"Error module did not start\n";
92 std::cout <<
"Main returning..." <<
'\n';
See code in: examples/rfmodule/main.cpp