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

Revision history [back]

If I understood you well, you want your callback to process some data and then deliver some result that will be used by other functions. What I do in that case is that instead of return y I publish y to a topic making it accessible to other functions: callback_pub.publish(y) where callback_pub is declared as

callback_pub = rospy.Publisher("callback_y",std_msgs/int32)

As a concrete example you can imagine an image_callback detecting faces and publishing faces positions.

Another easy way to do that is to just set y as a global variable and make the callback function change its value whenever it is called. I don't know how python internally works but you should maybe consider using mutex to avoid Write/Read on y on the same time.

Finally and as al-dev suggested, using a class but you should bind it as a callback using boost. I don't know if there is some tutorial for that in python.