In Python script, how determine what topics a node is publishing?
I'm using the packages rosnode
and rospy
in my Python script. Given a node's name, how do I get the topics that node is publishing?
I'm able to get lots of information that is close.
I'm able to get a list of all topics being published using
rospy.get_published_topics
I'm able to get a list of all active nodes using
rosnode.rosnode_ping_all
I'm able to get the info about a node using
rosnode.get_node_info_description(node_name)
, but this returns one gigantic string. The name of the topics is in the string, but it isn't easy to pull the topic names out (like it would be if the topic names were in a list).
I had the idea to use get_node_info from the NodeInfo
class (see below code).
import rospy, rosnode
from rqt_top.node_info import NodeInfo
rospy.init_node('example_node')
node_class = NodeInfo()
node_info = node_class.get_node_info('/rosout')
print(node_info)
However, the node info it returns and prints (see below) doesn't seem to list the node's topics (as I thought it would).
psutil.Process(pid=6866, name='rosout', started='12:14:15')
I can't seem to find a tool, which I can place in my Python script, that links a node to the specific topics that node publishes.