Examples of registering a custom sensor (not plugin)
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] [SensorManager.cc:276] 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.
Asked by dhood on 2016-07-21 12:45:05 UTC
Answers
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.
Asked by Nils on 2017-10-30 10:53:14 UTC
Comments
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
Asked by dhood on 2018-02-28 14:22:29 UTC
@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?
Asked by maikelo on 2018-11-04 23:27:23 UTC
@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!
Asked by maikelo on 2018-11-05 14:07:32 UTC
Comments
@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.
Asked by Javi V on 2016-12-01 05:55:54 UTC
@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: https://bitbucket.org/osrf/ariac/src/6e6eebc181bed1eef147581b1604bbec3374f45d/osrf_gear/models/proximity_sensor/model.sdf?at=master&fileviewer=file-view-default#model.sdf-37 )
Asked by dhood on 2016-12-01 11:29:03 UTC