Repository Summary
Checkout URI | https://github.com/ctu-vras/gazebo_custom_sensor_preloader.git |
VCS Type | git |
VCS Version | master |
Last Updated | 2023-08-29 |
Dev Status | MAINTAINED |
CI status | No Continuous Integration |
Released | RELEASED |
Tags | No category tags. |
Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Packages
Name | Version |
---|---|
gazebo_custom_sensor_preloader | 1.1.0 |
README
Implement custom Gazebo sensors at ease
The current structure of the Gazebo simulator doesn’t allow
implementation of custom <sensor>
s in the form of externally loaded
plugins. To add a new sensor implementation, you officially need
to fork Gazebo and add the sensor to its source code.
This doesn’t sound really great, does it?
This Gazebo system plugin allows you to write custom Gazebo sensors as ROS packages (so it depends on gazebo_ros, and adding them to Gazebo is then a matter of a few configuration lines in your sensor code. Theoretically, the mechanism this plugin uses could work completely without ROS, but hey, who uses Gazebo without ROS? :)
This plugin is only tested to work with Gazebo 9. If you successfully use it with a different version, please let me know in the issues.
Known custom sensors
Here’s a (noncomprehensive) list of known custom sensor implementations that work with this plugin. Feel free to open a pull request to add your own implementation here.
- gazebo_rotating_lidar: A sensor for more realistic simulation of lidars based on a rotating mirror where each laser beam has a different timestamp.
How to do it
There is an example custom sensor in this package: ExampleCustomSensor.cpp, ExampleCustomSensor.h and example_custom_sensor.xml. The most important things will be described further in this document.
⚠ In this guide, we use the names
ExampleCustomSensor
andexample_custom_sensor
, which you have to change, because a custom sensor with this class/name is already built in this package.
Create a ROS/catkin package for your sensor
E.g. by calling
catkin_create_pkg ... example_custom_sensor ...
A pretty normal Sensor
implementation …
ExampleCustomSensor.h
Here, it is important to note that your custom sensor has to reside inside the
gazebo::sensors
namespace.
#include <gazebo/sensors/Sensor.hh>
namespace gazebo
{
namespace sensors
{
class ExampleCustomSensor : public Sensor
{
// your code
}
}
}
ExampleCustomSensor.cpp
In the implementation file, you have to register your sensor via the following
block of code. The first argument is the Gazebo sensor type, which is how you
reference the custom sensor in SDF. It should also match the name
attribute
in XML plugin definition (prefixed with sensors/
).
#include <gazebo/sensors/SensorFactory.hh>
using gazebo::sensors::Sensor;
using gazebo::sensors::SensorFactory;
extern "C"
{
GZ_REGISTER_STATIC_SENSOR("example_custom_sensor", ExampleCustomSensor)
}
// your sensor implementation
… a few configuration lines …
example_custom_sensor.xml
This is a configuration file you may know if you’ve ever used ROS pluginlib, e.g. when implementing a nodelet. The library path is relative to the devel space of your sensor’s workspace, and contains the name of the shared object containing the sensor, excluding the
File truncated at 100 lines see the full file