Implement a new plugin for mc_rtc

In mc_rtc, every interface uses the mc_control::MCGlobalController class to initialize and run the controllers in the framework. In particular, they will run the mc_control::MCGlobalController::run() function on every iteration.

The plugin system allows one to write a component that will run at the start and/or end of this run function.

These plugins can be used for a variety of purpose:

  • Publish data using a 3rd-party middleware (for example, the ROS plugin)
  • Provide sensor data that is obtained with a different interface than the one where mc_rtc is running
  • Provide high-level functionalities that are above a single controller scope

Writing your own plugin

To write a plugin you should write a class that derives from the mc_control::GlobalPlugin class. Then you must implement the following functions:

mc_rtc will not call the reset method when the first controller is started — only the init method is called in that case. If needed, you can call the reset method from the init method.

Finally, your class must be exported in a shared library that can be loaded by mc_rtc. The simplest way to achieve this is to use the EXPORT_MC_RTC_PLUGIN macro in mc_rtc, similar to its counterpart for controllers, states and robot modules.

Customize what runs and when

Optionally, you can override the mc_cotrol::GlobalPlugin::configuration() method. This lets you inform mc_rtc that your plugin does not to run before or after the run loop or whether your plugin should run when the controller is not running.

By default, a plugin's before and after method is always called.

It is even possible to load a plugin that does not run at all. This can be useful to register methods in the datastore or tasks and constraints in the meta task and constraint loaders.

Autoload

The CMake macro add_plugin automatically creates a CMake option named AUTOLOAD_${PLUGIN}_PLUGIN. When this option is ON, a special file will be installed in ${MC_RTC_INSTALL_PREFIX}/lib/mc_plugins/autoload. When this file is present, the plugin will be automatically loaded regardless of the Plugins configuration entry.

Get started

Use the mc-rtc/new-plugin template project to get started quickly. This template provides the barebone structure for a C++ GlobalPlugin