Adding multiple models in gazebo using c++ api
Is it possible to add multiple objects with c++ api in gazebo? I have used methods given in this tutorial for adding models from a sdf file. But if the sdf file contains more than one model, it is only adding the first model. Can anyone please tell me if there is a way to add multiple models from the sdf file. Thank you
Asked by cadbury on 2020-06-03 23:58:22 UTC
Answers
An SDF model file may only contain one model, thus why only the first model is being loaded. You can:
- Put each model in its own SDF file and load each file separately
- Create a .world file that contains all your models
- Create a nested SDF file as seen in this tutorial: http://gazebosim.org/tutorials?tut=nested_model&cat=build_robot
Asked by zokowc on 2020-06-05 15:51:04 UTC
Comments
Thanks for your reply, but actually the entire sdf file is provided by some user and I have to insert those models at runtime. Can you suggest me how to insert multiple models at runtime?
Asked by cadbury on 2020-06-08 02:49:40 UTC
You can add models at run time using two different methods(The ones I know off):
In terminal, using(where model_0 is the name of your model):
gz model -m model_0 -f path_to_model.sdf
Through python using rosservices as outlined in this answer https://answers.gazebosim.org//question/5553/how-does-one-use-gazebospawn_sdf_model/
Method 2 can be replicated in C++
Asked by zokowc on 2020-06-08 11:59:58 UTC
Thanks I will check that
Asked by cadbury on 2020-06-09 00:35:06 UTC
Anytime! Please mark this answer correct if it works for you.
Asked by zokowc on 2020-06-15 13:05:44 UTC
Comments