0
$\begingroup$

Gazebo Answers logo

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));

Originally posted by jelavice on Gazebo Answers with karma: 5 on 2017-05-19

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

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.


Originally posted by chapulina with karma: 7504 on 2017-05-19

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by jelavice on 2017-05-20:
That solved the error, thanks.

Comment by jelavice on 2017-05-20:
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.

Comment by mstniy on 2020-08-08:
You probably need to create the node in Init, not Load

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.