Home | Tutorials | Wiki | Issues
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

Hello,

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 ROSCallback_Vel(const geometry_msgs::Twist::ConstPtr& msg)

{

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

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

{

sdf::SDF sphereSDF;

sphereSDF.SetFromString(
   "<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>\
     <attenuation>\
            <range>2</range>\
            <linear>0.0</linear>\
            <constant>0.1</constant>\
            <quadratic>0.5</quadratic>\
      </attenuation>\
        <direction>0.0 0.7 0.0</direction>\
        <cast_shadows>false</cast_shadows>\
       </light>\
    </sdf>");

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!