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

can `ros2 topic list` poll periodically?

asked 2019-08-16 15:37:30 -0600

Pete B gravatar image

Maybe I imagined this - but was there once a way to run ros2 topic list and not have it exit immediately, but rather poll periodically and list all topics that it eventually sees?

I can't find any reference to this in the git history - but I also can't believe I completely imagined this feature.

I'm interested in having ros2 topic list monitor some other processes that get launched, and then check the list of all topics that were seen - even ones that appeared later, or went away at some point.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-08-21 13:18:02 -0600

DanRose gravatar image

updated 2019-08-21 13:50:53 -0600

It doesn't exist in ROS2. If you're on Linux, you should be able to use some utilities to do what you want:

watch ros2 topic list will show the current topics (by default every 2 seconds) but won't accumulate like you want.

Try this two-liner shell (bash or bash-like) script to gather all the topics into a file called topics.txt:

> topics.txt

while true; do ros2 topic list | sort -u -o topics.txt topics.txt -; sleep 1; done

edit flag offensive delete link more
1

answered 2019-08-21 12:24:11 -0600

jacobperron gravatar image

updated 2019-08-21 12:25:04 -0600

You can try using the option --spin-time, which will cause ros2 topic list to wait for the specified number of seconds before returning. Note, it will only wait if a daemon is not already running. E.g. when running ros2 topic list --spin-time 3 consecutively, only the first call will wait 3 seconds and the others will return immediately since the daemon was started by the first call.

You can force the discovery time to happen by first stopping the daemon:

ros2 daemon stop
ros2 topic list --spin-time 3

I'm not sure this is quite the feature you are looking for though. ros2 topic list does not provide a way to periodically poll for topics.

edit flag offensive delete link more

Comments

It seems I was mis-remembering how the --spinp-time option worked. When I looked at this a few months ago, I must have overlooked the part about the daemon

Pete B gravatar image Pete B  ( 2019-08-22 10:01:07 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2019-08-16 15:37:30 -0600

Seen: 419 times

Last updated: Aug 21 '19