Home | Tutorials | Wiki | Issues
Ask Your Question
0

ConnectDeleteEntity event doesn't work in World Plugin

asked 2017-01-31 08:43:23 -0500

Benoit gravatar image

Hello everybody,

I want to make a world plugin with events callback, everything work perfectly except the ConnectDeleteEntity event. With the following code, when we create a model, we get a "Add" message (the function "OnAddEntity" is called) but when remove a model (for example, by selecting a model and pressing the Delete Key, or with the menu), the function "OnDeleteEntity" is not called.

    namespace gazebo{
        struct PluginGazebo : public WorldPlugin {      
            //----------------------------------
            event::ConnectionPtr DeleteEntityConnection;
            event::ConnectionPtr AddEntityConnection;
            //----------------------------------
            void OnDeleteEntity(const std::string str){
                std::cerr << "Delete " << str << std::endl;
            }
            //----------------------------------
            void OnAddEntity(const std::string str){
                std::cerr << "Add " << str << std::endl;
            }
            //----------------------------------
                virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf){
                //--
                    this->DeleteEntityConnection = event::Events::ConnectDeleteEntity(boost::bind(&PluginGazebo::OnDeleteEntity, this, _1)); 
                    this->AddEntityConnection = event::Events::ConnectAddEntity(boost::bind(&PluginGazebo::OnAddEntity, this, _1)); 
                }
        };

        GZ_REGISTER_WORLD_PLUGIN(PluginGazebo)
    }

When OnDeleteEntity should be called ?

Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-01-31 10:31:11 -0500

It looks like the deleteEntity event is never being fired by Gazebo, which is a bug. I ticketed an issue here.

A workaround for now would be to subscribe to the ~/request topic and check if _msg->request() == "entity_delete", see an example here.

edit flag offensive delete link more

Comments

Your workaround works perpectly ! Thanks a lot.

Benoit gravatar imageBenoit ( 2017-02-01 04:59:15 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-01-31 08:42:19 -0500

Seen: 84 times

Last updated: Jan 31 '17