How to add/delete a object mutliple times from a single model file using a plug-in
Hi
I like to add multiple cylinders with an id and i like also to remove them after a ceartain time using a plug-in. I worked through the model factory example. http://gazebosim.org/wiki/Tutorials/1.9/plugins/factory I am able to add, let's say ten cylinders but all cylinders a named the same. So my first question is how to I add a model, from file with a different name? How to I remove a added model by name using a plug-in?
Thanks
Asked by Markus Bader on 2014-01-10 08:56:11 UTC
Answers
I've been doing this by keeping track of whether a model type exists within the world, and using the clone_model_name field of the factory message to spawn sequential models. With this method, each new model takes the previous with "_clone" appended to its name. Unfortunately, the functions within physics::World needed modify the model name before spawning are private, so I don't think there's a better way right now.
Asked by dkotfis on 2014-01-14 00:00:38 UTC
Comments
You can delete models using the "entity_delete" field on the "~/request" topic. Just fill in the model name.
Asked by dkotfis on 2014-01-14 00:03:04 UTC
Comments
Assuming you're using a WorldPlugin, you can use the World::InsertModelSDF or World::InsertModelString API's (see example code from updated tutorial). You can specify the model name as an attribute in the passed SDF object or SDF string. I'm updating the example to show how to do this (pull request #957).
I don't think it's currently possible to specify a custom model name when spawning via a filename with a factory message, though it can be done when passing custom sdf strings (see numerous spawning functions in the ServerFixture class).
Asked by scpeters on 2014-02-10 04:05:32 UTC
Comments
Thanks for the update, spawning works now
Asked by Markus Bader on 2014-04-10 04:42:47 UTC
Comments
If you add them as in the tutorial, you could usa a variable for the model name in order to use different values. And you should be able to remove them with http://gazebosim.org/api/dev/classgazebo_1_1physics_1_1Model.html#ae8f752eae4b0a138fae49065e24e202c
Asked by AndreiHaidu on 2014-01-10 10:58:09 UTC