Ask Your Question

Revision history [back]

The problem with your subscriber is not related to the node handles, although I'll get to that later.

Your subscriber will only function while the sub object exists, since you declare it as a local variable in the turn() method as soon as that function finishes the subscriber is destroyed. This is the reason why you're not receiving any messages.

I would recommend putting everything into your class and storing the subscriber as a private member of the class.

Node handles are slightly unusual in that they always behave as the same object whenever you create them, so there is no point storing and passing a node handle object, because any code can create a new node handle and it will behave exactly the same way.

If you move all your ROS code into the class then your constructor would create a nodeHandle as usual, and use it to create the subscriber.

Hope this helps.