Skip to content

Commit 76a106f

Browse files
committed
Enhanced ros2 topic info to display node name, node namespace,
topic type and qos profile of the publishers and subscribers. Signed-off-by: Jaison Titus <[email protected]>
1 parent 067f107 commit 76a106f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

ros2topic/ros2topic/verb/info.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,27 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from rclpy.qos import QoSDurabilityPolicy
16+
from rclpy.qos import QoSLivelinessPolicy
17+
from rclpy.qos import QoSReliabilityPolicy
18+
1519
from ros2cli.node.direct import DirectNode
1620
from ros2topic.api import TopicNameCompleter
1721
from ros2topic.verb import VerbExtension
1822

23+
def print_topic_info(info):
24+
print('\nNode Name: %s' % info['node_name'])
25+
print('Node Namespace: %s' % info['node_namespace'])
26+
print('Topic Type: %s' % info['topic_type'])
27+
print('QoS Profile:')
28+
qos_profile = info['qos_profile']
29+
print(' Reliability: %s' % QoSReliabilityPolicy(qos_profile['reliability']).name)
30+
print(' Durability: %s' % QoSDurabilityPolicy(qos_profile['durability']).name)
31+
print(' Lifespan: %d nanoseconds' % qos_profile['lifespan'].nanoseconds)
32+
print(' Deadline: %d nanoseconds' % qos_profile['deadline'].nanoseconds)
33+
print(' Liveliness: %s' % QoSLivelinessPolicy(qos_profile['liveliness']).name)
34+
print(' Liveliness Lease Duration: %d nanoseconds' %
35+
qos_profile['liveliness_lease_duration'].nanoseconds)
1936

2037
class InfoVerb(VerbExtension):
2138
"""Print information about a topic."""
@@ -30,6 +47,10 @@ def add_arguments(self, parser, cli_name):
3047
def main(self, *, args):
3148
with DirectNode(args) as node:
3249
topic_name = args.topic_name
33-
print('Topic: %s' % topic_name)
34-
print('Publisher count: %d' % node.count_publishers(topic_name))
35-
print('Subscriber count: %d' % node.count_subscribers(topic_name))
50+
print('Topic : %s' % topic_name)
51+
print('\nPublisher count : %d' % node.count_publishers(topic_name))
52+
for publisher_info in node.get_publishers_info_by_topic(topic_name):
53+
print_topic_info(publisher_info)
54+
print('\nSubscription count : %d' % node.count_subscribers(topic_name))
55+
for subscription_info in node.get_subscriptions_info_by_topic(topic_name):
56+
print_topic_info(subscription_info)

0 commit comments

Comments
 (0)