Home | Tutorials | Wiki | Issues
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

World Plugin, callback function ConnectWorldUpdateBegin is not called

Hey!

I think everything is in the title, I made a world plugin using gazebo 7 (on Windows). I'm using the Event ConnectWorldUpdateBegin to send the poses of the links to another program I made (to control the robots in the simulation) but the callback doesn't work.

#include <sdf/sdf.hh>

#include <gazebo/transport/transport.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <gazebo/physics/physics.hh>


namespace gazebo
{
    class MyPlugin: public WorldPlugin
    {
    private:
        physics::WorldPtr world;

        event::ConnectionPtr updateConnection;
        transport::NodePtr node;

        transport::SubscriberPtr newModel;

        physics::Model_V models;    

    public: 
        MyPlugin();
        ~MyPlugin();

    public:
        void Load(physics::WorldPtr _parent, sdf::ElementPtr /*_sdf*/);

        public:
        /**
        Function called at each step. Send the poses and joint value of each joint
        */
        void Update(const common::UpdateInfo &_info);

        virtual void NewModelAdded(ConstModelPtr &_msg);

    };

}

and the .cc

void MyPlugin::Load(physics::WorldPtr _parent, sdf::ElementPtr /*_sdf*/)
{
    world = _parent;

    this->updateConnection = event::Events::ConnectWorldUpdateBegin(boost::bind(&MyPlugin::Update, this, _1));

    this->node = transport::NodePtr(new transport::Node());
    this->node->Init();

    //To add future models
    this->newModel = this->node->Subscribe("~/model/info", &MyPlugin::NewModelAdded, this);  
}

void MyPlugin::Update(const common::UpdateInfo &_info)
{       
    std::cerr << "UPDATE";
//...
}

I can't use Debug (too hard on Windows) but I'm sure the plugin is loaded as I can print stuff from Load function. But the UPDATE string never appears and the code after is not executed.

I also changed the register by its value:

/*
Here, copy of the define macro GZ_REGISTER_WORLD_PLUGIN because gazebo isn't configure to work with windows (no __declspec(dllexport)) so dlfcn couldn't find the plugin
*/
extern "C"  __declspec(dllexport) gazebo::WorldPlugin *RegisterPlugin();
gazebo::WorldPlugin *RegisterPlugin()
{
    return new MyPlugin();
}

Could it be related? The subscriber and publisher works perfectly well from a stand alone server, so it shouldn't. However I guess that the scope is somehow wrong.

Thx for your help!