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

publish arrays to a topic on the command line

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

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():
        rospy.init_node("array_test_node")
        sub = rospy.Subscriber("array_test", Arrays, callback)
        rospy.spin()

if __name__ == "__main__":
        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:
    [Foo,
         ^

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

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
12

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

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

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

Comments

That works, thank you!
TillScout gravatar image TillScout  ( 2011-06-13 07:45:22 -0600 )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 -0600 )edit

Question Tools

3 followers

Stats

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

Seen: 20,626 times

Last updated: Jun 13 '11