There are two methods in general:
- You could use a ROS service call as @iche033 has said. But you need to install gazebo_ros package first.
- You could use Gazebo's built-in functions. There are a couple of functions which can insert or delete a model in
gazebo::physics::World
Class (link). For example, RemoveModel (const std::string &_name)
to remove a model or InsertModelFile (const std::string &_sdfFilename)
to insert a model.
Originally posted by winston with karma: 449 on 2017-04-21
This answer was ACCEPTED on the original site
Post score: 0
Original comments
Comment by [email protected] on 2017-04-21:
Thanks for your answer.
Comment by [email protected] on 2017-04-21:
Hi, sorry for asking another issue. I use a .xacro file for descripting the robot instead of the .urdf format. In terms of gazebo_msgs/SpawnModel message type, for the field of model_xml, can I still use .xacro file? Or I need to convert .xacro into .urdf then assign it to the model_xml field? Because I do not know how to convert .xacro to .urdf in c++ file.
Comment by winston on 2017-04-23:
I am not sure but I think .xacro should be OK. Why not have a try? BTW, if you have fond the satisfied answer to your question, please tick it as the best answer so that other people who may have the same problem could find out the answer as fast as possible.
Comment by winston on 2017-04-23:
I am not sure but I think .xacro should be OK. Why not have a try? BTW, if you have found the satisfied answer to your question, please tick it as the best answer so that other people who may have the same problem could find out the answer as fast as possible.