Ask Your Question

rostopic pub does not allow carriage return or line feed in the string

asked 2019-10-18 17:03:07 -0600

borgcons gravatar image

Am am trying to send a string like


to a modem through a String topic in ROS

I am able to do it in code but I can not do it in a terminal window

rostopic pub /my_topic std_msgs/String "data: 'AT\r\n'"

Is there a way to do this?

edit retag flag offensive close merge delete


I have one terminal opened with $ rostopic echo /foo and another where I do $ rostopic pub /foo std_msgs/String 'AT\r\n'. The first one receives, as expected:

data: "AT\\r\\n"

The same output can be achieved with $ rostopic pub /banana std_msgs/String "{data: AT\r\n}" which is more similar to your syntax.

This to say I don't think your issue is clear. Is it that you don't want the double backslash? Or you want the \r and \n to be interpreted as carriage return?

aPonza gravatar image aPonza  ( 2019-10-23 11:06:07 -0600 )edit

Yes I want the \r and \n to be interpreted as CR and LF

borgcons gravatar image borgcons  ( 2020-05-12 04:26:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-18 19:08:19 -0600

updated 2019-10-18 23:36:29 -0600

s.macenski@reese:~$ echo $'\r'

s.macenski@reese:~$ echo '\r'

Does the $ fix your issue?

Edit: I think you actually want \\ out instead. But you'd have to indicate specifically what issue you're having that you're looking to solve, its not necessarily clear to me, maybe I'm misreading what you're looking for

edit flag offensive delete link more


I'm not sure how this helps me do a rostopic pub

borgcons gravatar image borgcons  ( 2019-10-18 19:27:02 -0600 )edit

because its still your shell interpreting the return. Did you try it?

stevemacenski gravatar image stevemacenski  ( 2019-10-18 19:46:45 -0600 )edit

This is what I am trying to do:

rostopic pub /my_topic std_msgs/String "data: 'AT\r\n'"

How do I use the $ for this?

I just don't get it yet

borgcons gravatar image borgcons  ( 2019-10-18 21:46:59 -0600 )edit

I'm suggesting trying 'AT$\r\n' but I'm not sure if it'll work, I was looking to you to tell me if that fixes it.

If not another option to try is double slash, ei 'AT<2 \>r<2 \>n' which should also potentially give you the viable solution

stevemacenski gravatar image stevemacenski  ( 2019-10-18 23:30:57 -0600 )edit

Neither work

borgcons gravatar image borgcons  ( 2019-10-19 17:10:44 -0600 )edit

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: 2019-10-18 17:03:07 -0600

Seen: 225 times

Last updated: Oct 18 '19