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

This is a lot of coding to be answered in one question. Try to be more specific with your question. For how to respond to changes in a topic, see the tutorial on writing a subscriber . If you know how to do that part, all you need to do is write the callback method for the topic that you are subscribing to.

Make a global variable that is the previous joint state. In the callback method use a simple for loop to check if the velocity vector in the current Jointstate (the one that is received by the callback method) has changed from the velocity vector in the previous Jointstate. It looks like the velocity is an array of float64. In C++ this will be interpreted as a std::vector of type double. So you can just traverse both vectors and see if the components have changed to some tolerance. If it has, then traverse the positions the same way and subtract them and save that off. At the end of your callback method, be sure to save the current Jointstate off as the previous Jointstate. If you know how many times its going to happen.. just add a global count variable that counts and run the program until the count is at 100.