ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

trying to publish an array of words in rospy using numpy

asked 2014-06-01 16:12:07 -0500

uzair gravatar image

I am trying to create a subscriber which accepts a word (meaning a string of characters) and then collects those words into an array and then publish the array of these words.

I am trying to use numpy for this. The length of my array always has to be 3 with the latest word at the end. This way I wil have two previous words with the latest word at the end of the array.

This is the code :

#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from rospy.numpy_msg import numpy_msg
import numpy

def callback(data):
    global c
    pub = rospy.Publisher('tag_history',numpy_msg(String))

    if len(c)>3:
    print c

 def listener():

     rospy.init_node('tag_history', anonymous=True)

     rospy.Subscriber("DA_tags", String, callback)

if __name__ == '__main__':

     global c

When I run this code, this is the error i get :

[ERROR] [WallTime: 1401656539.688481] bad callback: <function callback at 0x2456758>
Traceback (most recent call last):
File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/", line 682, in _invoke_callback
File "./", line 17, in callback
File "/opt/ros/hydro/lib/python2.7/dist-packages/rospy/", line 802, in publish
raise ROSSerializationException(str(e))
ROSSerializationException: field data must be of type str

What does this error "field data must be of type str" mean? How do I remove it?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-06-01 23:35:04 -0500

uzair gravatar image

I fixed my problem by creating a custom message which is an array or strings. However whn I use it, I get a warning. I posted a new question here

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-06-01 16:12:07 -0500

Seen: 1,761 times

Last updated: Jun 01 '14