0
$\begingroup$

Rosanswers logo

Dears, I have a vector containing double type numbers representing the ros time that I recorded from a previous simulation. I need to publish data of a node at this given time. I try to explain better: I have the x,y,z coordinates of a point and the respective time at which this point were recorded. I need to publish these x,y,z coordinates at the exact time that I recorded to use it in other subscribers nodes. What can I use? I'm able to visualize a marker in rviz using these 3 coordinates at the time using the marker.header.timestamp but I'm not able to publish at the exact time the msg.position.x y and z, also because I normally use the sleep with ros::Rate. I don't understand if I can use a ros::Timer, or ros::Time, or using a node that publish in the /clock topic.

Thank you for yours answers.


Originally posted by nikkk on ROS Answers with karma: 13 on 2017-01-26

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Original comments

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.