using the latest message in a service
I have looked at a bunch of tutorials and read a bunch of similar question about this but am still struggling to figure it out and I would appreciate some insight.
I am running a bunch of programs together and I would like to synchronize everything as best as I can. My application involves solving an optimization that takes about 0.5 seconds to solve and then using this data to guide finer control of the system during the 0.5 second intervals where I am waiting for the optimization to solve. I am also publishing data that informs the optimization much faster than this to a message. Just before I solve the optimization I want to grab the most recent data available, what I was thinking about doing was creating a service that basically echos the latest message that got published to my topic of interest. Are there any examples of something like this?
I also was thinking about making a subscriber node that has a callback function that is constantly updating ros parameters, but not only does this seem wasteful, it seems dangerous because I might try to use one of the parameters when they are being written to.
Why do you want to echo the latest message published in your topic of interest instead of using that topic directly?