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

How do I make rostopic hz print a single line only?

asked 2018-05-16 09:15:48 -0500

thinwybk gravatar image

updated 2018-05-16 10:04:40 -0500

gvdhoorn gravatar image

Is there a way to get exactly one stdout response of rostopic hz only? (I know about watch -n1 ... but would like to avoid that.)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-16 09:25:16 -0500

gvdhoorn gravatar image

updated 2018-05-16 10:10:03 -0500

You mean print a single message? Sure:

rostopic echo -n1 <other options> /topic

This is also mentioned in the usage output of rostopic echo:

-n COUNT              number of messages to echo

Edit:

Sorry, wrong command in the question. I updated it to rostopic hz...

That is not supported.

Perhaps you can use some of the methods used by rostopic hz directly (ros/ros_comm/tools/rostopic/src/rostopic/__init__.py, lines 103 to 270).

edit flag offensive delete link more

Comments

Sorry, wrong command in the question. I updated it to rostopic hz...

thinwybk gravatar image thinwybk  ( 2018-05-16 10:00:01 -0500 )edit

Thx. I'll check it out...

thinwybk gravatar image thinwybk  ( 2018-05-16 10:14:35 -0500 )edit

... as I am running rostopic hz in a docker container with docker-py: How I can interface with (ros/ros_comm/tools/rostopic/src/rostopic/__init__.py, lines 103 to 270) with plain Ubuntu terminal (which is "exposed" via docker-py)?

thinwybk gravatar image thinwybk  ( 2018-05-16 10:20:28 -0500 )edit

You wouldn't. You probably need to write a small script that outputs what you want using the class I linked to.

Or: contribute a -n COUNT option to rostopic hz itself. That would be +100.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-16 10:23:53 -0500 )edit

I am going for "Or: contribute a -n COUNT option to rostopic hz itself." over the longer term for sure. For now I just stick to my very dirty workaround (running every subsequent command in separate containers).

thinwybk gravatar image thinwybk  ( 2018-05-16 10:30:54 -0500 )edit

I believe that the reason that hz doesn't have a COUNT right now is that it's debatable whether it would make sense: rostopic hz needs some time to properly calculate the msg rate, so simply looking at the first output may not be entirely representative.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-16 10:34:57 -0500 )edit
1

If you're doing this for some testing purpose, you might want to take a look at ipa-fmw/atf, particularly publish_rate.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-16 10:36:07 -0500 )edit

"rostopic hz needs some time to properly calculate the msg rate, so simply looking at the first output may not be entirely representative." I agree. I don't know much about the implementation of rostopic hz but using it is probably just a rough estimate anyway? A rough estimate is fine for me here.

thinwybk gravatar image thinwybk  ( 2018-05-16 10:43:59 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-16 09:15:48 -0500

Seen: 1,604 times

Last updated: May 16 '18