0

Rosanswers logo

I want to publish 3 ints as a message but i'm getting this vague error that I'm not sure how to solve this.

This is the relevant bit of my code:

self.publisher = self.create_publisher(
    Int32,
    'wheel_settings',
    10)
#test publishing wheel settings
self.publisher.publish([1, 1, 1])

Error: "raise TypeError()"

How do I fix this? P


Originally posted by rydb on ROS Answers with karma: 125 on 2021-04-30

Post score: 0

1 Answers1

0

Rosanswers logo

alas, Int32 =/= Int32[]

You'll need to define your publisher to publish arrays (in your case, you can use Int32MultiArray.msg).

In python, (without knowing the contents of self.create_publisher()) that could look something like:

from std_msgs.msg import Int32MultiArray

...

self.publisher = self.create_publisher( Int32MultiArray, 'wheel_settings', 10) ...

msg = Int32MultiArray() msg.data = [1, 1, 1] pub.publish(msg)


Originally posted by shonigmann with karma: 1567 on 2021-05-03

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by rydb on 2021-05-04:
Yep, this fixes it. I wish error handling for this was more specific like "error: expected type x, got type y" or something though.

shonigmann
  • 771
  • 1
  • 2
  • 7