Get the timestamp a Float64MultiArray message was published

asked 2019-04-25 10:12:02 -0600

rsh95 gravatar image

I am trying to retrieve the time a Float64MultiArray message was published.

The only attributes for a Float64MultiArray message are :

(1) MultiArrayLayout layout # specification of data layout


(2) float64[] data # array of data

There is no header that I can retrieve the timestamp from, unlike in other message types and I don't think either of these has the timestamp.

However, when I print the message, I do get something of this format: [INFO] [1556205014.502280] which I believe is a timestamp. Is there a way to get this (or the timestamp)?

edit retag flag offensive close merge delete


The timestamp you are seeing is from the ROS log output. It has nothing to do with the time the message was published.

To my knowledge, there is no direct way to get the time a message is published. Also note that actually, the header.stamp is also not the time the message is published, but rather whatever you put into it. Most often, you use ros::Time::now() to do that, but there might still be some delay between setting the header and actually publishing, as shown below in the pseudo code

msg.header.stamp = ros::Time::now(); ros::Duration(5).sleep(); pub.publish(msg)

For your use-case, you'd either have to create a new stamped message with a Float64MultiArray or use the time you receive the topic.

mgruhler gravatar image mgruhler  ( 2019-04-26 01:53:30 -0600 )edit

Thank you!

rsh95 gravatar image rsh95  ( 2019-04-26 20:00:34 -0600 )edit