0

I have defined a custom message: uint8[] data

The custom message is imported in my Node class with no problems: from my_shared.msg import MyMessage

In the same Node, I create the publisher with: self.my_publisher = self.create_publisher(MyMessage, 'topic_in', 200)

and I publish the message with: self.my_publisher.publish(my_msg)

my_msg is built in the following way:

payload_bitstream = np.fromstring(my_data, np.uint8)
my_msg = payload_bitstream.tolist()

Sadly, I get a TypeError: File "/opt/ros/eloquent/lib/python3.6/site-packages/rclpy/publisher.py", line 68, in publish raise TypeError() TypeError

Could you help out with this if you know what I am doing wrong pls?

Thanks in advance, G.

JWCS
  • 1,120
  • 1
  • 7
  • 17
Anthares
  • 1,041
  • 1
  • 13
  • 30

1 Answers1

0

The issue is in your assignment of my_msg, which is an instance of the class MyMessage containing attributes defined in the my_shared.msg file, namely my_msg.data which has type of uint8[]. It's correct that you did payload_bitstream.tolist() to get a list of native python ints with uint8 values, but you need to assign it to the data attribute. TL;DR:

my_msg.data = payload_bitstream.tolist()
JWCS
  • 1,120
  • 1
  • 7
  • 17