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

Publish at the time of a vector

asked 2017-01-26 11:51:06 -0500

nikkk gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-26 19:55:06 -0500

pryre gravatar image

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.

edit flag offensive delete link more


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.

nikkk gravatar image nikkk  ( 2017-01-26 20:56:52 -0500 )edit

You should be able to do something along the lines of this:

I can't compile it right now, don't have access to a stable machine. It should be transferable to your application though.

pryre gravatar image pryre  ( 2017-01-27 22:01:10 -0500 )edit

Question Tools



Asked: 2017-01-26 11:51:06 -0500

Seen: 705 times

Last updated: Jan 26 '17