# [WARN] [topic_statistics]: 在主题 '/scan' 上收到序列号 123 的消息，期望 124

- **ID:** `ros2/ros2-topic-statistics-mismatch`
- **领域:** ros2
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

主题统计监控检测到消息序列号有间隔，表示消息丢失或乱序传递，通常由于网络拥塞、CPU 负载高或 QoS 不兼容导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| ros2:humble | active | — | — |
| ros2:iron | active | — | — |
| ros2:rolling | active | — | — |
| rclcpp:18.0.0 | active | — | — |

## 解决方案

1. ```
   检查网络带宽和 CPU 使用率。如果过高，降低发布速率或使用更高效的序列化。示例：
ros2 topic hz /scan  # 检查当前速率
ros2 topic bw /scan   # 检查带宽

如果带宽高，调整发布器使用较低速率或减小消息大小。
   ```
2. ```
   如果使用不可靠的 QoS（例如 BEST_EFFORT），切换到 RELIABLE QoS 以减少丢失。在发布器代码中：
from rclpy.qos import QoSProfile, ReliabilityPolicy

qos = QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE)
self.publisher = self.create_publisher(LaserScan, '/scan', qos)
   ```

## 无效尝试

- **Disabling topic statistics without investigating the root cause** — This hides the symptom but does not address the underlying message loss, which may affect application behavior. (60% 失败率)
- **Increasing the publisher's publishing rate to compensate** — Higher rate increases network and CPU load, potentially worsening the problem. (80% 失败率)
