Robotics StackExchange | Archived questions

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!

Asked by XB32Z on 2016-03-29 10:06:20 UTC

Comments

Hi, I'm facing the same problem.. Did you solve it?

Thanks!

Asked by fqez on 2017-07-05 05:48:54 UTC

Hi, same problem here. Except, that I'm developing a ModelPlugin instead of a WorldPlugin.

Did anyone figured out how to solve this problem?

Asked by Codierknecht on 2019-12-17 08:04:19 UTC

Answers