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

Header and timestamp for Float32MultiArray in ROS2 [closed]

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

NiranjanRavi gravatar image

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

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()

data_to_send.data = my_array

sample_publisher_.publish(data_to_send)

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()

data_to_send.data = 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
0

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

abhishek47 gravatar image

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

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()
data_to_send.array.data = my_array
edit flag offensive delete link more

Comments

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 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 1,982 times

Last updated: Sep 04 '21