Get the timestamp a Float64MultiArray message was published
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
and
(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)?
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 useros::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 codemsg.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.Thank you!