You have two main options; use rosbag, or generate the messages manually. Either way, if you want to treat that data as if the experiment was being run (as in, you wanted it treated as if you were back in time running the live), then you can set the "use_sim_time" parameter to true, which will make RVIZ (and anything else that uses ros::Time, which is just about everything except tf) act like the experiment was running live.
Option 1: rosbag. With rosbag, you can record data from a topic into a file, and then replay it, and ROS will worry about all the timing issues. There is plenty of information about rosbag, so I'll leave this here.
Option 2: Manually. Assuming you have recorded the data from an external source (outside of ROS), or the experiment is unrepeatable for whatever reason, you could use a node to both generate clock messages and publish your data. Jumping ahead, I am assuming you already have your data imported into a node of some sort (in a vector or something). Your best bet would be to set up a publisher for the /clock message (you can manually create a time message and just send your recorded time as this), then set up a publisher for your data and have it populate the fields as usual (you can use ros::Time::now() as usual for this, or set the stamp header manually, it shouldn't matter if your /clock messages are sent correctly). From here, you would just want to use ros::Time::sleep(dt), where dt is the difference in time between your recorded timestamps.
Originally posted by pryre with karma: 16 on 2017-01-26
This answer was ACCEPTED on the original site
Post score: 0
Comment by nikkk on 2017-01-26:
Thank you for your complete answer. I try to publish in the clock topic but my problem is that it doesn't publish in the correct time. And then I can't use a dt because there's a differenza delta time between each successive recorded timestamps.
Comment by pryre on 2017-01-27:
You should be able to do something along the lines of this: https://gist.github.com/pryre/323fde0dd4573fd74f8fa0b1010ceadf
I can't compile it right now, don't have access to a stable machine. It should be transferable to your application though.