Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I found a crazy solution to this problem, don't know if it works in your situation.

Create a system plugin library looking something like this:

#include <gazebo/gazebo.hh>
#include <my_plugins/MySensor.hh>

namespace gazebo
{
  class RegisterMySensorPlugin : public SystemPlugin
  {
    /////////////////////////////////////////////
    /// \brief Destructor
    public: virtual ~RegisterMySensorPlugin()
    {
    }

    /////////////////////////////////////////////
    /// \brief Called after the plugin has been constructed.
    public: void Load(int /*_argc*/, char ** /*_argv*/)
    {
        RegisterMySensor();
        printf("Loaded my sensor!\n");
    }

    /////////////////////////////////////////////
    // \brief Called once after Load
    private: void Init()
    {
    }

  };

  // Register this plugin with the simulator
  GZ_REGISTER_SYSTEM_PLUGIN(RegisterMySensorPlugin)
}

Note that you need to forward-declare void RegisterMySensor(); in my_plugins/MySensor.hh. The function is then generated by the GZ_REGISTER_STATIC_SENSOR macro in MySensor.cc.

With this example, you can then launch gazebo with gazebo -s libRegisterMySensorPlugin.so to load the sensor. After this, you can load it as any other sensor using the name that you used in the GZ_REGISTER_STATIC_SENSOR macro.