Ask Your Question
1

can `ros2 topic list` poll periodically?

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

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 12:24:11 -0500

jacobperron gravatar image

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

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 imagePete B ( 2019-08-22 10:01:07 -0500 )edit
1

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

DanRose gravatar image

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 33 times

Last updated: Aug 21