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

How to rostopic pub multiple line for std_msgs/String type topic

asked 2016-11-23 21:51:13 -0500

sonictl gravatar image

updated 2016-12-22 00:10:46 -0500

How to use rostopic pub to publish multiple line or \n or \r\r for std_msgs/String typed topic.

I tried as YAML commandLine said. but nothing works.

Thank you!!!

$ rostopic pub /send_BTSVR std_msgs/String ['test'] --- ['test2'] ---

Usage: rostopic pub /topic type [args...]

rostopic: error: no such option: ---

$ rostopic pub /send_BTSVR std_msgs/String ['test'] --- ['test2'] ---

Usage: rostopic pub /topic type [args...]

rostopic: error: no such option: ---

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-12-22 03:29:04 -0500

gvdhoorn gravatar image

Not sure about the approach the wiki describes, but at least in a Bash shell, the following works for me:

$ rostopic pub /send_BTSVR std_msgs/String "data: '\
first line

second line

third line
'"

note the \ after the '. This allows you to continue on the next line.

edit flag offensive delete link more

Comments

How is this multiple lines? There are no CR or LF in the topic that is sent. This also doesn't answer how to do \r or \n in a message

borgcons gravatar image borgcons  ( 2020-05-12 04:18:14 -0500 )edit

Testing this on my ROS Melodic/Ubuntu Bionic install I see this output:

$ rostopic echo /send_BTSVR
data: "first line\nsecond line\nthird line "
---
data: "first line\nsecond line\nthird line "
---
data: "first line\nsecond line\nthird line "

etc.

Afaict, that is a multiline string encoded in a singe std_msgs/String. A Python node subscribing to this with print(msg.data) shows me this:

$ python ./sub.py
first line
second line
third line 
---
first line
second line
third line 
---

etc.

\n==line feed==LF, which is the standard Linux newline.

\r would be something else. I've not checked how to get that in a YAML string, but I would expect it to work the same way (ie: by adding the escape sequence to the string).

Did you expect rostopic echo to also print the multi-line string?

gvdhoorn gravatar image gvdhoorn  ( 2020-05-12 07:00:02 -0500 )edit
0

answered 2016-12-22 03:03:37 -0500

rbbg gravatar image

updated 2016-12-22 03:07:17 -0500

I never got the multi-line pub to work either. The only way I figured out how to send multiline strings using rostopic pub is to make a file like this (named test.yaml):

"first line

second line

third line"

and then use rostopic pub /send_BTSVR std_msgs/String -f test.yaml

Note that there is an empty line between the lines. I am pretty sure there's an easier/better way, but I don't know it and would love to hear if anyone has an idea?

edit flag offensive delete link more

Comments

gvdhoorn's answer seems work for me. you can have a try.

sonictl gravatar image sonictl  ( 2016-12-22 20:51:36 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-11-23 21:51:13 -0500

Seen: 10,035 times

Last updated: Dec 22 '16