Ask Your Question

rostopic piping

asked 2012-08-03 15:26:09 -0500

updated 2012-08-07 11:02:56 -0500

I'm trying to do something with rostopic that may not be possible, though the documentation suggests it is, and it's possible I've just got bad syntax or XAML usage. Using turtlesim, I'd like to initially do something simple on the command line, like:

while true; do echo '{linear: 0.0, angular: 1.0}'; sleep 1; done | rostopic pub -l turtle1/command_velocity turtlesim/Velocity

This doesn't seem to work, and I get no error messages of any sort. Am I missing something?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-08-06 08:28:34 -0500

pgrice gravatar image

If you are trying to publish an unchanging message repeatedly, use the rate parameter (-r) for rostopic on the commandline:

rostopic pub -r 10 turtle1/command_velocity turtlesim/Velocity "{'linear':0.0, 'angular':1.0}"

This should publish a turtlesim/Velocity type msg to the turtle1/command_velocity topic at 10 Hz.

edit flag offensive delete link more

answered 2012-08-07 10:58:00 -0500

updated 2012-08-07 11:22:42 -0500

Looking at the rostopic source code, it appears that even if this could work, it might not process the input as a stream, but will buffer it and issue the messages in one shot.

It seems the proper answer to this is to write a node capable of receiving STDIN. I've done this:
edit flag offensive delete link more


Using rostopic pub -r 10 ... publishes the provided message every 100ms (10 Hz) until you ctrl-c the command. (Try rostopic echo [topic] in another terminal to verify). If you want to change the values, ctrl-c, up-arrow, modify, and repeat.

pgrice gravatar image pgrice  ( 2012-08-08 06:38:55 -0500 )edit

Or, if you want a single publish for each time you hit enter, don't use -r. By default, rostopic pub publishes the message once (and then holds it latched for any new subscribers until ctrl-c'ed). This is what your node does (though your node makes it easier to enter new/different commands).

pgrice gravatar image pgrice  ( 2012-08-08 06:41:20 -0500 )edit

Thanks, but, I wish to transfer arbitrary information at arbitrary times for arbitrary reasons via stdin. Unfortunately, neither of your methods address that.

urgent gravatar image urgent  ( 2012-08-09 11:33:39 -0500 )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: 2012-08-03 15:26:09 -0500

Seen: 793 times

Last updated: Aug 07 '12