0
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

The problem was caused by how I was creating and assigning value to the message.

The right way in ROS2 is:

my_msg = MyMessage()

...

my_msg.data = my_value

that did the trick and solved my problem

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.