Gazebo | Ignition | Community
Ask Your Question

How to remove a model which has been inserted in a Ros-enabled plugin??

asked 2013-05-04 01:45:56 -0500

Zahra gravatar image


I have a difficulty to remove a model during the simulation time. I have inserted this light point using InsertModelSDF() method in a callback function that is run every time data is published to ros topic.

To be clear more , the below code is the callback function:

void ROSCallbackVel(const geometrymsgs::Twist::ConstPtr& msg)


this->simtime = common::Time(0.90);

if ( this->model2_ ->GetWorld()->GetSimTime() > this->simtime )


sdf::SDF sphereSDF;

   "<sdf version ='1.4'>\
     <light type='Point' name='bulb100'>\
       <pose>-2.0 -0.994333 0.8  0 0 0</pose>\
    <diffuse>0.8 0.8 0.8 1</diffuse>\
     <specular>.4 .4 .4 0</specular>\
        <direction>0.0 0.7 0.0</direction>\

this->model2_ ->GetWorld()->InsertModelSDF(sphereSDF); }

ROS_INFO("subscriber two velocities: [%f %f %f %f %f %f ]", msg->linear.x,msg->linear.y,msg->linear.z, msg->angular.x,msg->angular.y, msg->angular.z);

        Vlinx=msg->linear.x; Vliny=msg->linear.y; Vlinz=msg->linear.z;
        Vangx=msg->angular.x; Vangy=msg->angular.y; Vangz=msg->angular.z;
       this->model_->SetLinearVel(math::Vector3( Vlinx, Vliny, Vlinz));
       this->model_->SetAngularVel(math::Vector3(Vangx, Vangy, Vangz));


my question is:

Is there a way to remove this light point using gazebo functions or maybe other ways to do that? Any ideas and suggestions are appreciated!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-05-07 22:50:50 -0500

iche033 gravatar image

You can send a request message to delete the light

gzfactory's delete function shows how to send the message

edit flag offensive delete link more

answered 2013-05-08 12:08:10 -0500

Zahra gravatar image

Thanks for answering.

I have tried to send a msg request to delete the model as you recommended it, but it couldn't recognize the light name and it gave me this when I run it: Msg Waiting for master Msg Connected to gazebo master @ Msg Publicized address: Error: No model name specified.

I also tried this with box model but it didnt work , I know that problem goes with recognizing the model name but I dont know how to do it even thouhgh I tried to get the model name in this way to delete the light

std::string modelName= _sdf->GetElement("light")->GetValueString();

but gazebo crashed and gave this error :gazebo: /usr/include/boost/smartptr/sharedptr.hpp:418: T* boost::shared_ptr<t>::operator->() const [with T = sdf::Element]: Assertion `px != 0' failed.

The code below shows how it is done:

if ( this->model2_ ->GetWorld()->GetSimTime() > this->simtime )


// std::string modelName= _sdf->GetElement("light")->GetValueString();

if (!transport::init())


if (vm.count("bulb100"))

modelName = vm["bulb100"].as<std::string>();



std::cerr << "Error: No model name specified.\n";




transport::NodePtr node(new transport::Node());


msgs::Request *msg = msgs::CreateRequest("entity_delete", modelName);

transport::PublisherPtr pub = node->Advertise<msgs::request>("~/request");

// Model file to load



delete msg;



thanks in advance!

edit flag offensive delete link more


looks like you're passing an empty string. Is the name of the light bulb100? If so then just set modelName to "bulb100"

iche033 gravatar imageiche033 ( 2013-05-10 00:12:31 -0500 )edit

thanks it works! once I set the modelName to the name of light.

Zahra gravatar imageZahra ( 2013-05-10 01:10:21 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-05-04 01:45:56 -0500

Seen: 1,476 times

Last updated: May 08 '13