ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Creating Multiple Plugins from Single Package in ROS2

asked 2021-06-15 11:09:12 -0600

GusBus gravatar image

I am experimenting with the pluginlib and wondering if it is possible to create two plugin classes from a single package? Is it recommended to rather do separate packages for the different classes?

In my current workspace I have successfully compiled and run three packages:

control_framework - Contains executable and imports the plugins controller - Contains base class linear_controller - Contains two plugin classes

I can create multiple instances of the LinearController1, but as soon as I try and load LinearController2 I get the following error:

The plugin failed to load for some reason. Error: MultiLibraryClassLoader: Could not create object of class type linear_controller::LinearController2 as no factory exists for it. Make sure that the library exists and was explicitly loaded through MultiLibraryClassLoader::loadLibrary()

I know that LinearController2 exists and was exported correctly based on the console printout when I made a typo:

The plugin failed to load for some reason. Error: According to the loaded plugin descriptions the class linear_controller::LinearControlle2 with base class type control_base::Controller does not exist. Declared types are  linear_controller::LinearController1 linear_controller::LinearController2

Here is how I am importing them in the ControlFramework.cpp file

ControlFramework.cpp

#include <iostream>
#include <pluginlib/class_loader.hpp>
#include <controller/Controller.h>


int main(int argc, char** argv)
{
  pluginlib::ClassLoader<control_base::Controller> ctrl_loader("controller", "control_base::Controller");

  try
  {
    std::cout << "Create Controller 1\n";
    std::shared_ptr<control_base::Controller> ctrl1 = ctrl_loader.createSharedInstance("linear_controller::LinearController1");
    std::cout << "Init Controller 1\n";
    ctrl1->initialize(10.0, 0.0, 0.0);
    std::cout << "Controller Output 1: " << ctrl1->computeFeedback(2.0) << "\n";

    std::cout << "Create Controller 2\n";
    std::shared_ptr<control_base::Controller> ctrl2 = ctrl_loader.createSharedInstance("linear_controller::LinearController2");
    std::cout << "Init Controller 2\n";
    ctrl2->initialize(5.0, 0.0, 0.0);
    std::cout << "Controller Output 2: " << ctrl2->computeFeedback(2.0) << "\n";
  }
  catch(pluginlib::PluginlibException& ex)
  {
    std::cout << "The plugin failed to load for some reason. Error: " << ex.what() << "\n";
  }

  return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-27 04:45:10 -0600

lukicdarkoo gravatar image

It is definitely possible to have multiple plugins within a single package, see the example here:
https://github.com/cyberbotics/webots...

I don't have your CMake file, but the problem is probably hidden there.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2021-06-15 11:09:12 -0600

Seen: 522 times

Last updated: Jun 27 '21