Soft Real Time Block for Pacing Simulink Simulations

版本 1.1.0.0 (487.3 KB) 作者: Marc Compere
This block causes Simulink to advance simulated time at the same average rate as wall-clock time
719.0 次下载
更新时间 2018/5/29

查看许可证

This is the readme file for Soft Real Time Simulink Block for Pacing Simulink Simulations
and associated c-mex S-functions:
(1) sfun_getSystemClockTimeval.c
(2) sfun_sleep.c
(3) sfun_output_to_console.c
The goal of this Simulink model is to cause the Simulink simulation to advance simulated
time forward at the same average rate as real wall-clock time. Soft real time
is achieved by adding a delay to cause a match between the total elapsed simulation time and
total elapsed wall-clock time. Because of this there is very little or no drift over many
seconds. There will always be some jitter when attempting soft-real-time on a non-real-time
operating system like Windows, standard linux or MacOS. Useful clock resolution is around
10ms on Windows machines and better in Linux or MacOS. This limits Sleep() or usleep()'s
ability to pause reliably at much less.
The C-MEX S-function sfun_sleep.c has a user-specified sample time default of 0.01(s).
This is different from the base simulation sample time of h_fixed=0.001(s).

To run, double click the light blue box in upper left to initialize h_fixed=0.001(s).

This block is similar to the Pace block provided in both the Aerospace Blockset and in the
base Simulink library as of Matlab R2018a. However, it provides two additional
features that the Pace blocks and other user-contributed Soft Real Time blocks do not provide:

(1) Full source is provided and soft-real-time is achieved through a combination of C-mex
s-functions and Similink code.

(2) There is no software limit on how many instances can run at a time on a single computer
or within a single or multiple instances of Matlab open on a single computer.

This code was developed on R2016b and is tested on Windows 10 using the MinGW 64-bit Compiler.

---------------------------------------------------------------------------
To install and get running:
- unzip .zip file into an empty folder
- open Matlab and compile the three C-mex s-functions with:
mex sfun_getSystemClockTimeval.c
mex sfun_sleep.c
mex sfun_sim_time_to_console.c
- open the Simulink model and press play: soft_real_time_block.slx

**-> double click the light blue box in upper left to
initialize h_fixed=0.001(s).
---------------------------------------------------------------------------

Marc Compere
comperem@gmail.com
created : 28 May 2018
modified: 29 May 2018

引用格式

Marc Compere (2024). Soft Real Time Block for Pacing Simulink Simulations (https://www.mathworks.com/matlabcentral/fileexchange/67520-soft-real-time-block-for-pacing-simulink-simulations), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2016b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Block and Blockset Authoring 的更多信息

Community Treasure Hunt

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

Start Hunting!

soft_real_time_block/

版本 已发布 发行说明
1.1.0.0

- minor update to 00_Reaadme.txt
- minor documentation improvements

1.0.0.0