ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I suspect that the issue has to do with you resubscribing to the chatter topic everytime you iterate that loop. Put the
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
line above your while loop and try your program again.
Also, someone correct me if I'm wrong, but using spinOnce() only processes the messages that have come in since the last time you called spinOnce. If your publisher of the "chatter" topic is not publishing messages at the rate at which you are calling spinOnce, you will not get 50 messages (thus, not getting 50 printouts in your callback). You are looping so fast there that you will for sure not get 50 callbacks.
2 | No.2 Revision |
I suspect that the issue has to do with you resubscribing one of two things.
1) Resubscribing to the chatter topic everytime you iterate that loop. Put the
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
line above your while loop and try your program again.
or 2) Also, someone correct me if I'm wrong, but using spinOnce() only processes the messages that have come in since the last time you called spinOnce. If your publisher of the "chatter" topic is not publishing messages at the rate at which you are calling spinOnce, you will not get 50 messages (thus, not getting 50 printouts in your callback). You are looping so fast there that you will for sure not get 50 callbacks.