#!/usr/bin/env python3 """统计导航链路上各级速度话题的消息数。""" import time import rclpy from geometry_msgs.msg import Twist, TwistStamped from rclpy.node import Node from rclpy.qos import QoSProfile, QoSReliabilityPolicy qos = QoSProfile(depth=10, reliability=QoSReliabilityPolicy.BEST_EFFORT) rclpy.init() node = Node('cmd_probe_all') counts = {} def make_cb(name): def cb(_msg): counts[name] = counts.get(name, 0) + 1 return cb for t in ('/cmd_vel_nav', '/cmd_vel_smoothed', '/cmd_vel', '/model/sentry/cmd_vel'): node.create_subscription(Twist, t, make_cb(t), qos) node.create_subscription(TwistStamped, '/cmd_vel_nav', make_cb('/cmd_vel_nav[stamped]'), qos) t0 = time.time() while time.time() - t0 < 10: rclpy.spin_once(node, timeout_sec=0.2) for t in ('/cmd_vel_nav', '/cmd_vel_nav[stamped]', '/cmd_vel_smoothed', '/cmd_vel', '/model/sentry/cmd_vel'): print(f' {t:26} {counts.get(t, 0)}') node.destroy_node() rclpy.shutdown()