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

Header and timestamp for Float32MultiArray in ROS2 [closed]

asked 2021-09-03 13:44:50 -0600

NiranjanRavi gravatar image

updated 2021-09-03 13:45:54 -0600

Hi, I am working with ROS 2 foxy distribution. I have a publisher which sends an array (for every second) to the ROS queue. I am able to successfully subscribe it and save it. I want to add a timestamp every time the array is getting sent over ROS queue. I tried the following code.
Without timeStamp: // Working

data_to_send = Float32MultiArray() = my_array


With added timestamp code: // Not Working

pp = PublishingNode() // creating an instance of the class

data_to_send = std_msgs.msg.Header()

data_to_send.stamp = pp.get_clock().now().to_msg() = my_array

AttributeError: 'Header' object has no attribute 'data'

The aim is send an array along with the timestamp every second using python in ROS2.

Any guidance would be helpful?

Regards Niranjan

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by NiranjanRavi
close date 2021-09-20 16:59:08.645557

1 Answer

Sort by ยป oldest newest most voted

answered 2021-09-04 05:48:05 -0600

abhishek47 gravatar image

updated 2021-09-04 05:50:55 -0600

If you examine std_msgs/msg/Header, the only two attributes are stamp and frame_id.

For your purpose, you could create your own custom message StampedArray.msg:

builtin_interfaces/Time stamp
std_msgs/Float32MultiArray array

Then you should be able to do something like:

data_to_send = StampedArray()
data_to_send.stamp = pp.get_clock().now().to_msg() = my_array
edit flag offensive delete link more


Hi, Yes it worked perfectly. I ended up creating my own custom messages and was able to publish and receive the values.

NiranjanRavi gravatar image NiranjanRavi  ( 2021-09-20 16:58:52 -0600 )edit

Question Tools

1 follower


Asked: 2021-09-03 13:44:50 -0600

Seen: 1,612 times

Last updated: Sep 04 '21