How to make a loop that runs every time ros node receives a message?
Hello, I'm trying to write a node that subscribes to a topic, then, in the callback function for the subscriber, saves each message received in a global variable (one that is overwritten each time a new message is received), and that manually republishes the messages on a different topic name every time the a message is received (like a node for manually remapping a topic). I realize that this node isn't useful in itself, but it is part of a larger program and I have to get it working before I can get the larger program working.
Does anyone know how to make a loop or event or some qualifier that I can put code inside that will run every time I receive a message on a specific topic in ROS? For now I just measured the average hz of the topic I'm subscribing to, and then set the loop rate of the publishing loop equal to that average, but I would like something more exact.