How to measure Round Trip Time in Simulink using S-Functions and Time Stamps?

9 ビュー (過去 30 日間)
Fritz
Fritz 2021 年 2 月 11 日
回答済み: Mark McBroom 2021 年 2 月 15 日
Dear Community,
I have a setup where I want to evaluate the latency when sending data from one Simulink model to another, where the second model can either run in a different instance on the same computer or a remote machine. What I want to achieve is evaluating the Round Trip Time (RTT), i.e. the time it takes between generating the data, encoding and sending it to the second simulation and receiving and decoding the data coming back (see the attached image for the general idea). The commuication can e.g. be based on TCP socket communication, but the measurement of RTT should be independent of the underlying principle. It is important, though, to be able to measure the time it takes for every "data packet" to go around, so that information about packet jitter / RTT standard deviation can be gathered.
My general idea was to generate time stamps with a C++ MEX S-Function using the following two methods:
  • the "chrono" library and the "high_resolution_clock::now()" to create a time stamp
  • the "fstream" library to ofstream the timestamp to a text file, e.g. csv or txt
When placing two of such MEX S-Functions blocks in the model (one before sending and one after receving data) the RTT could be evaluated by taking the difference of the logged time stamps.
My questions are:
  1. Does this approach seem valid / is there a better way to get a (most accurate) time measurement?
  2. The data should be sent at different sample rates. What is the best way to "trigger" the time stamp functions accordingly, i.e. everytime a new data package is sent / received?
  3. The data can vary in size, e.g. vectors or matrices with up to several hundred elements. Is there an efficient way to achieve the time stamping as proposed using MEX S-Functions without having to pass all the data through the block? I could imagine this to be computationally inefficient. The pseudo code in this case would basically be: timestamp = high_resolution_clock::now(); ofstream timestamp; y=u;
Any help / input would be appreciated!

回答 (1 件)

Mark McBroom
Mark McBroom 2021 年 2 月 15 日
Trhee suggestions
  1. Don't bother writing time to file in s-function. Use simulink logging capabilities to log the outputs from the s-function. You can also Simulink blocks to compute the delta time
  2. Change your S-function so that it only outputs a time. You can feed this into your data generator when creating your packet of data to send.
  3. On the receive side simply put your s-function inside the receive/decode subsystem so that it is executed when new data arrives.

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by