Ros Publishing Array From Python Node
Solution 1:
The *MultiArray
messages are a bit overkill in your case. I think it is much simpler if you create your own simple message type IntList
for this (see this tutorial on how to create custom messages). The IntList.msg
-file looks just like follows:
int32[] data
To publish a list with this message use the following snippet:
a=IntList()a.data= [3250,2682,6832,2296,8865,7796,6955,8236]
pub.publish(a)
Note that you cannot directly publish the list but have to instantiate an IntList
object and fill the data
member of this object (this holds for all message types, even if you just want to publish a single integer!).
Solution 2:
You can use the following methods for python:
pub = rospy.Publisher('chatter2', Float64MultiArray, queue_size=10)
data_to_send = Float64MultiArray() # the data to be sent, initialise the array
data_to_send.data = array # assign the array with the value you want to send
pub.publish(data_to_send)
Solution 3:
If you do want to use MultiArray
, try:
array = []
my_array_for_publishing = Int32MultiArray(data=array)
Post a Comment for "Ros Publishing Array From Python Node"