How to avoid duplication of functions that appear in multiple plugins

asked 2016-06-10 09:20:33 -0600

spmaniato gravatar image

Let's say I'm developing a couple of base_local_planner plugins. Both of them will have a function that bounds the velocity commands such that they respect the robot's min/max velocity and acceleration bounds. How can I avoid duplicating the source code (and unit tests) of such a function in the two plugins / packages?

Continuing the example above, would it make sense to introduce an intermediate class, say MyLocalPlanner which inherits from nav_core::BaseLocalPlanner and then have the actual plugins inherit from this intermediate class? Another alternative might be multiple inheritance:

class SomeLocalPlannerPlugin : public nav_core::BaseLocalPlanner, public MyLocalPlanner

Would these play nicely with pluginlib? Would I need to use the PLUGINLIB_EXPORT_CLASS macro differently?

Other solutions to the original problem of avoiding code duplication are of course welcome.

edit retag flag offensive close merge delete