!REDIRECT “https://docs.px4.io/master/zh/middleware/micrortps_throughput_test.html

Micro RTPS 吞吐量测试

这是一个测量 PX4-FastRTPS Bridge 吞吐量的简单测试。 最大速率下,同时收发 256 字节的报文,并且输出结果。

Tip 该示例需要你 手动生成客户端和代理代码

使用 uORB 报文

First create a new uORB message for this test in the folder /PX4-Autopilot/msg/. 可以命名为 throughput_256.msg 并包含如下内容:

  1. uint8[256] data

可以使用如下命令:

  1. cd /path/to/PX4/PX4-Autopilot/msg
  2. echo uint8[256] data > throughput_256.msg

Register the new message adding it to the list of messages in the file: /PX4-Autopilot/msg/CMakeLists.txt:

  1. ...
  2. wind_estimate.msg
  3. throughput_256.msg
  4. )
  5. ...

Give the message a topic id by adding a line in the /PX4-Autopilot/Tools/message_id.py script:

  1. ...
  2. 'wind_estimate': 94,
  3. 'throughput_256': 95,
  4. }
  5. ...

禁用自动桥接代码生成

找到对应的目标平台(cmake/configs/),通过设置 .cmake 文件中的变量 GENERATE_RTPS_BRIDGE 来禁用自动桥接代码生成(作为 PX4 构建进程的一部分):

  1. set(GENERATE_RTPS_BRIDGE off)

生成桥接代码

使用 generate_microRTPS_bridge.py 手动生成桥接代码(代码会发送和接收我们刚刚加入的 throughput_256 uORB 话题报文):

  1. cd /path/to/PX4/PX4-Autopilot
  2. python Tools/generate_microRTPS_bridge.py --send msg/throughput_256.msg --receive msg/throughput_256.msg

Client 源代码生成在 src/modules/micrortps_bridge/micrortps_client/Agent 则在 src/modules/micrortps_bridge/micrortps_agent/

更改客户端代码

接下来,我们修改 Client 用来在每次循环中发送 throughput_256 报文。 这是必需的,因为 PX4 实际上并没有发布该主题,而且我们希望确保以尽可能高的速率发送该主题。

打开文件 src/modules/micrortps_bridge/micrortps_client/microRTPS_client.cpp。 更新 send() 函数中的 while 循环,使其如下所示:

  1. ...
  2. while (!_should_exit_task)
  3. {
  4. //bool updated;
  5. //orb_check(fds[0], &updated);
  6. //if (updated)
  7. {
  8. // obtained data for the file descriptor
  9. struct throughput_256_s data = {};
  10. // copy raw data into local buffer
  11. //orb_copy(ORB_ID(throughput_256), fds[0], &data);
  12. data.data[0] = loop%256;
  13. serialize_throughput_256(&data, data_buffer, &length, &microCDRWriter);
  14. if (0 < (read = transport_node->write((char)95, data_buffer, length)))
  15. {
  16. total_sent += read;
  17. ++sent;
  18. }
  19. }
  20. usleep(_options.sleep_ms*1000);
  21. ++loop;
  22. }
  23. ...

Note 你可能还记得,这是一个 bidirectional 吞吐量测试,其中还必须将消息从 Agent 发送到 Client。 你不需要修改代理代码就可以实现这一点。 由于 Agent 是 RTPS 发布者和订阅者,它将自动收到有关其发送的 RTPS 消息的通知,然后将这些消息镜像回客户端。

Compileand launchClientAgent

结果

测试是在 Pixracer 上运行的 PX4, 通过 UART 连接到运行 Ubuntu 16.04 的普通 PC。 默认配置用于两个客户/代理。

吞吐量可以在 shell 窗口中观察到的结果如下:

  1. SENT: 13255 messages in 13255 LOOPS, 3512575 bytes in 30.994 seconds - 113.33KB/s
  2. RECEIVED: 13251 messages in 10000 LOOPS, 3511515 bytes in 30.994 seconds - 113.30KB/s