I got stuck when I wanted to publish an array in ROS so I'll share it
At first, you can imitate how to write C ++ and do this! I mean ...
import rospy
from std_msgs.msg import Float32MultiArray
def talker():
pub = rospy.Publisher('/hoge', Float32MultiArray, queue_size=10)
array=Float32MultiArray()
array.data.resize(5)
i=0
for p in range(5):
array.data[i]=p
i+=1
pub.publish(array)
AttributeError: 'list' object has no attribute 'resize'
Was angry
The correct sentence is below
import rospy
from std_msgs.msg import Float32MultiArray
def talker():
pub = rospy.Publisher('/hoge', Float32MultiArray, queue_size=10)
array=[]
for p in range(5):
array.append(p)
array_forPublish = Float32MultiArray(data=array)
pub.publish(array_forPublish)
You can convert it to MultiArray after putting it in List type once.
Recommended Posts