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

rostopic piping

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

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

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
2

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

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
0

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

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

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:

http://notsourgent.com/ros/turtle_stdin.txt
edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-08-03 15:26:09 -0600

Seen: 1,166 times

Last updated: Aug 07 '12