ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

publish arrays to a topic on the command line

asked 2011-06-13 07:13:40 -0500

TillScout gravatar image

Hi all,

I am new to ROS and experimenting with several things. Now I have the following problem: I want to define a topic where the type contains arrays of strings and floats. So I wrote a file Arrays.msg that contains

string[] name
float32[] value

and a simple Subscriber node:

import roslib; roslib.load_manifest("playground")
import rospy
from playground.msg import Arrays

def callback(data):
        print "test"

def main():
        sub = rospy.Subscriber("array_test", Arrays, callback)

if __name__ == "__main__":

Now my question is: How do I publish a list of strings and floats on the command line? It works when I type

rostopic pub /array_test playground/Arrays -- ["Foo"] [1.1]

and it publishes the correct message on /array_test. But what if I have more strings? I tried

rostopic pub /array_test playground/Arrays -- ["Foo", "Bar"] [1.1, 2.2]

but I get the following error message:

rostopic: error: Argument error: while parsing a flow node
expected the node content, but found '<stream end>'
    in "<string>", line 1, column 6:

What would be the correct command for publishing these arrays on the command line?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-06-13 07:33:05 -0500

updated 2011-06-13 07:37:40 -0500

Try this:

rostopic pub /array_test playground/Arrays "{name:['Foo', 'Bar'], value:[1.1, 2.2]}"

EDIT - the inner quotes don't seem to be required, even with spaces in the string, so this also works:

rostopic pub /array_test playground/Arrays "{name:[Some words, More words], value:[1.1, 2.2]}"
edit flag offensive delete link more


That works, thank you!
TillScout gravatar image TillScout  ( 2011-06-13 07:45:22 -0500 )edit
Hmm, yes it works, but it is a bit clumsy. Why are the qoutes and the curly brackets necessary?
TillScout gravatar image TillScout  ( 2011-06-14 01:59:29 -0500 )edit

Question Tools



Asked: 2011-06-13 07:13:40 -0500

Seen: 19,361 times

Last updated: Jun 13 '11