Gazebo | Ignition | Community
Ask Your Question

Examples of registering a custom sensor (not plugin)

asked 2016-07-21 12:45:05 -0500

dhood gravatar image

I'm trying to make a custom sensor (that inherits from RaySensor) but am having trouble getting it registered properly if it's not built within the gazebo source code.

I call:

GZ_REGISTER_STATIC_SENSOR("parallel_ray", ParallelRaySensor)

but when I try to add a model with that sensor, I end up with:

[Err] [] Unable to create sensor of type[parallel_ray]

because sensors::SensorFactory::GetSensorTypes() doesn't list parallel_ray as a type.

Can anyone share a link to some code where a custom sensor, from outside of the gazebo source code, has been registered with gazebo's SensorManager/SensorFactory? I suspect that I need to specify the path to the sensor's .so somehow.

edit retag flag offensive close merge delete


@dhood did you find the solution to this problem? I am having exactly the same problem. Basically I want to add a new sensor without having the recompile Gazebo.

Javi V gravatar imageJavi V ( 2016-12-01 04:55:54 -0500 )edit

@javi-v I didn't, no. I made use of an existing sensor instead. (In this case, to get a parallel ray sensor I used a RaySensor with an origin "behind" the origin of the link, so that the rays are approximately parallel in the region "in front" of the link: )

dhood gravatar imagedhood ( 2016-12-01 10:29:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-10-30 11:10:52 -0500

Nils gravatar image

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*/)
        printf("Loaded my sensor!\n");

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


  // Register this plugin with the simulator

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

With this example, you can then launch gazebo with gazebo -s 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.

edit flag offensive delete link more


thanks for replying! I ended up using a different approach to avoid needing to register a sensor but hopefully this is useful to someone else

dhood gravatar imagedhood ( 2018-02-28 13:22:29 -0500 )edit

@Nils I'm following your approach, but it is not working for me. Once I load the system plugin and register my new sensor, then I call SensorFactory::NewSensor("my_type") and I get a NULL pointer, so my new sensor is not being loaded. Do you have any example were I can see how you load your new sensor? Other question: Is your new sensor defined your RegisteringPlugin library or in a different one?

maikelo gravatar imagemaikelo ( 2018-11-04 22:27:23 -0500 )edit

@Nils I found my own error. I named my register plugin with the same name as the register sensor function used by the sensor factory.. my bad. After fixed that, everything works!! Your solution wasn't crazy at all, it the best I can think of. Thank you!

maikelo gravatar imagemaikelo ( 2018-11-05 13:07:32 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2016-07-21 12:45:05 -0500

Seen: 1,115 times

Last updated: Oct 30 '17