
I'm working on such a plugin at the moment, and hopefully I'll release it in the next days, gazebo_video_monitor_plugins. Perhaps, it can fit your use case.
But, more specifically on your question...
As a side note, you don't need a new link. It should be enough to just specify a pose inside the camera description, and attach the camera to an existing link. Although, I'm not entirely sure that this is working properly with the camera sensor. But, that's the idea anyway.
The way to create a sensor is by triggering the createSensor event, where you provide the sensor description, the name of the world is which to create the sensor, and the name and id of the link to which to attach the sensor.
#include <gazebo/common/Events.hh> #include <gazebo/sensors/SensorFactory.hh> event::Events::createSensor(sdf->GetElement("sensor"), world->Name(), link->GetScopedName(), link->GetId());
This will be picked up by the sensor manager, which it will take care of the rest.
Originally posted by nlamprian with karma: 833 on 2020-04-16
This answer was ACCEPTED on the original site
Post score: 2
Original comments
Comment by kumpakri on 2020-04-17:
How do you get this camera sensor description? The first parameter must be of type sdf::ElementPtr. I haven't found how to create this element with a text description (such as "...").
Comment by nlamprian on 2020-04-17:
I define the camera in the plugin configuration. If you really want to have it defined inside the plugin, you can use sdf::initString.
Comment by kumpakri on 2020-04-22:
@nlamprian Thank you! May I ask you how long it took to create this gazebo video package? I'm just curious. This looks like a lot of work.
Comment by nlamprian on 2020-04-22:
I worked on it sporadically for several weeks. It was quite painful, because of all the different ways that gazebo crashes and misbehaves for no obvious reason, while trying to figure out how everything works. It still doesn't do everything I wanted to implement, but at least it records videos successfully.