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

Revision history [back]

click to hide/show revision 1
initial version

I wouldn't create the Publisher in the callback. Usually I have a class where I create the publisher in the constructor and store it in a member variable. Publishing can then be done from a callback method, that uses the publisher member to call .publish().

You could also use a global variable to store the publisher object if you do not want classes. Or you bind the publisher boost::bind to the callback.

See http://www.ros.org/wiki/roscpp/Overview/Publishers%20and%20Subscribers for more info.