Home | Tutorials | Wiki | Issues
Ask Your Question
0

Subscriber with member callback function

asked 2017-05-19 08:56:13 -0500

jelavice gravatar image

updated 2017-05-19 10:22:40 -0500

I am trying to subscribe to the model msgs in gazebo, however I cannot bind the callback function in a correct way. This is the code:

class WorldInterface : public WorldPlugin

{

public:


    void messageReceived1(const msgs::Model& _msg)
    {
        std::cout << "Got the message!" << std::endl;
        modelLoaded_ = true;
    }

    void Load(physics::WorldPtr _parent, sdf::ElementPtr _sdf)
    {

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


        transport::SubscriberPtr modelSub =
                node->Subscribe("~/model/info", std::bind(&gazebo::WorldInterface::messageReceived1, this, _1));

.....
}
};

The error I get is:

error: no matching function for call to ‘gazebo::transport::Node::Subscribe(const char [13], std::_Bind_helper<false, void (gazebo::WorldInterface::*)(const gazebo::msgs::Model&), gazebo::WorldInterface*, boost::arg<1>&>::type)’
     node->Subscribe("~/model/info", std::bind(&gazebo::WorldInterface::messageReceived1, this, _1));
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-05-19 10:28:45 -0500

Try changing your subscriber to this:

node->Subscribe("~/model/info", &WorldInterface::messageReceived1, this));

And your callback to this:

void messageReceived1(ConstModelPtr &_msg)

See an example here.

edit flag offensive delete link more

Comments

That solved the error, thanks.

jelavice gravatar imagejelavice ( 2017-05-20 08:31:10 -0500 )edit

Btw can you think of any good reason my plugin is not receiving any messages? As far as I understood, there should be a message broadcasted on "~/model/info" topic any time a model is inserted in to a simulation. I insert the model with parent->InsertModelFile() however no message is received + model count in the world stays exactly the same. I am doing this in the Load function for the world plugin.

jelavice gravatar imagejelavice ( 2017-05-20 11:01:54 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-05-19 08:56:13 -0500

Seen: 92 times

Last updated: May 19