ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Problem with Deleting Models

asked 2012-08-06 10:00:02 -0500

ncr7 gravatar image

I would like to spawn models and then delete them while running my python algorithm... but as I do I am only able to spawn the models, and delete the handles of these models the actual model stays in the gazebo world.

I'm using the following code to spawn the model,

os.system("rosrun gazebo spawn_model -file /opt/ros/electric/stacks/simulator_gazebo/gazebo_worlds/objects/small_sphere_1.urdf -gazebo -model p%s -x %s -y %s -z %s" %(index, particles[index,0], particles[index,1], particles[index,2]))

and using this code to delete the model,

os.system("rosservice call gazebo/delete_model '{model_name: p%s}'" %(index))

Is there anyway to clear the gazebo world of these objects using another command? These commands work the way I expect when I directly type them into the terminal but not when I use os.system()

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-08-06 11:24:31 -0500

prasanna.kumar gravatar image

Using system() might not help you most of the times. Do not go for system() unless desperate. I used the following code (snippet) in c++.

 #include "gazebo/DeleteModel.h"
    remove(std::string model_name)
           ros::NodeHandle nh("");
           ros::ServiceClient deleteModelClient = nh.serviceClient<gazebo::DeleteModel>("gazebo/delete_model");
           gazebo::DeleteModel deleteModel;
           deleteModel.request.model_name = model_name;

in main()


Hope you can modify for python!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-08-06 10:00:02 -0500

Seen: 1,536 times

Last updated: Aug 06 '12