0
$\begingroup$

Rosanswers logo

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()


Originally posted by ncr7 on ROS Answers with karma: 325 on 2012-08-06

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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::service::waitForService("gazebo/delete_model");
           ros::ServiceClient deleteModelClient = nh.serviceClient<gazebo::DeleteModel>("gazebo/delete_model");
           gazebo::DeleteModel deleteModel;
           deleteModel.request.model_name = model_name;
           deleteModelClient.call(deleteModel);
         }

in main()

remove(<model_name>);

Hope you can modify for python!


Originally posted by prasanna.kumar with karma: 1363 on 2012-08-06

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

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