Exporting a plugin with multiple parents implementing same base
Hi there,
I'm trying to attach a controllable gimbal to a drone and simulate the outcome in Gazebo. After a lot of struggle on writing my own gazebo_ros_control::RobotHWSim derivation that can command both the drone and gimbal, I have decided to combine existing such instances in my own. In order to do that, I apply multiple inheritance as follows:
class MyDroneHardwareSim : public gazebo_ros_control::DefaultRobotHWSim, public hector_quadrotor_controller_gazebo::QuadrotorHardwareSim
Both of those classes are also derived from gazebo_ros_control::RobotHWSim. At the end I add
PLUGINLIB_EXPORT_CLASS(dji_m100_controller_gazebo::DJIM100HardwareSim, gazebo_ros_control::RobotHWSim)
as tutorial suggests. However, due to multiple inheritance pluginlib fails to discover which base to use from the inherited plugins and throws ‘gazebo_ros_control::RobotHWSim’ is an ambiguous base of ‘my_drone_controller_gazebo::MyDroneHardwareSim
error.
This is more of a C++ problem, and there are ways to resolve this disambiguity. However, I doubt that pluginlib has such flexibility in its class exporting macro. Does anyone know a workaround on that? I really don't want to copy paste all the code from all hardware sim classes.
Not an answer, but: isn't this what combined_robot_hw was created for? I don't know whether it is supported by the Gazebo plugin, but if you're after being able to control all joints from a single controller, then perhaps you could take a look at
combined_robot_hw
.As you said, it is a facility to easily combine several existing controllers; but it lacks any Gazebo support. That is, one needs to implement a custom RobotHWSim class, which registers the combined robot hw interface with all Gazebo-related primitives from scratch. Indeed I have started with
combined_robot_hw
, nonetheless consequently the bottleneck revealed out as the gazebo_ros_control side.Since my use-case demands only two such
Sim
classes, I've inherited from the one with most line of code and copy-pasted the other. I'm planning to add a 3DOF manipulator and if such a partial robot has another custom sim class, I'll copy-paste it too. Luckily,DefaultRobotHwSim
covers all joint-specific controllers.