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

Revision history [back]

So your program is failing when the constructor of your base class, quad_controller_base::QuadController gets called on instantiation of the derived class that you've dynamically loaded. It sounds like it's failing because this constructor is defined in the .so instead of the executable, and linking across that boundary is causing a problem.

Regardless of the above issue, I don't think this is what you want to be doing. Assuming you're trying to make it so that you can dynamically load different quadcopter controllers via pluginlib, a good pattern is to make this interface (base class) defined in a header file so that dependencies can use it. Then they dynamically load derived classes via pluginlib.

This way, someone else can implement their own controller from quad_controller_base and define it in their own plugin, and dynamically load that as well. If you defined the base class constructor in this library, then the user-defined controllers wouldn't really be "peers" with the default controllers that you provide in your package.

Consider the following scenario:

  • Someone builds a controller manager for quadcopters
    • This depends only on quad_controller_base.h
  • One person's application wants to use the controller manager with your default controllers
    • This depends on: libquad_controller_manager.so,
    • This loads libquad_controllers.so at runtime via pluginlib
  • Another person's application wants to use the controller manager with additional controllers
    • This depends on: libquad_controller_manager.so,
    • This loads libquad_controllers.so at runtime via pluginlib
    • This loads libmy_sweet_controller.so at runtime via pluginlib

This way, none of these different programs need to know anything except the interface at compile time, and then they can load whatever collection of controllers that are defined at runtime. This is compared to achieving the same behavior only with static linking, whereby the controller manager would need to be dependent on the packages that contain your default controllers AND my sweet controller. @tfoote likes to refer to it as "flipping the dependency tree."

Hope this helps.