ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Where does the output come from? In the code you post, there is not this specific output.

One thing I noticed is the following.

  object_pose obj;
  subsriber = n.subscribe("/gazebo/model_states", 1, &object_pose::callback, &obj);

You shouldn't do this, as you instantiate a new object obj and bind the subscriber to the callback function of this object. However, obj goes out of scope and is destroyed as soon as you leave the connectServiceAndPublisher function. Thus, the address of the object obj is invalid and whatever the bound callback is pointing to is not existing anymore.

It should be:

  subsriber = n.subscribe("/gazebo/model_states", 1, &object_pose::callback, this);

This way, you bind to the callback function of the class instance.

See the roscpp_tutorial and especially the last sentence of the Subscriptions section