0
$\begingroup$

Rosanswers logo

Dear All. While read the following documentation, I can not know how to use it to create c++ program to add or delete object in ros gazebo automatically by program. http://www.ros.org/wiki/simulator_gazebo/Tutorials/SpawningObjectInSimulation


Originally posted by zhenli on ROS Answers with karma: 287 on 2012-02-26

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

This shows which services to call and how and this shows how to call a service in C++.


Originally posted by Lorenz with karma: 22731 on 2012-02-26

This answer was ACCEPTED on the original site

Post score: 5

$\endgroup$
0
$\begingroup$

Rosanswers logo

You can use either the /gazebo/spawn_urdf_model service (for .urdf files) or the /gazebo/spawn_gazebo_model service (for gazebo .xml files). In your code you need a service client for the service, e.g., for urdf models:

ros::ServiceClient gazebo_spawn_clt_ = node_handle_.serviceClient< gazebo_msgs::SpawnModel> ("/gazebo/spawn_urdf_model");

Then you need to read the contents of the urdf file into the model_xml field of a gazebo_msgs::SpawnModel service. The generated service then can be used to call your client:

gazebo_spawn_clt_.call(spawn_model_srv);


Originally posted by Robert Krug with karma: 225 on 2012-02-27

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by zhenli on 2012-02-27:
Can you give me a detail example for URDF file.

Comment by Robert Krug on 2012-02-27:
I added a very simple example of a node spawning a urdf model on pastebin

Comment by [email protected] on 2017-04-21:
But I use .xacro file rather than .urdf file. How to use it for the model_xml field in c++ code? Thanks.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.