Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are two problems in your code for vel_filter.

The first is that the publisher is always going to publish twists with all values at zero. There is no connection between the msg variable in your while loop and the msg variable that the subscriber callback receives. If you want to publish the filtered velocities, you should pass the publisher to the subscriber callback as an argument and do the publishing in the callback.

The second is that you go into a while loop that will never end until the node shuts down, but you do not provide any time for the ROS infrastructure inside that loop. ros::spin() will only be called when the loop exits, at which point the node is shutting down and it will return instantly. In order to use a while loop with a timed sleep like you are doing here, you need to call ros::spinOnce() after your sleep. This will provide the ROS infrastructure with one cycle of processing its buffers, subscriptions, etc., and allow the filterVelocityCallback() to be called.