.Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime

Information

Synchronizes the simulation time of the simulation process with the operating system real-time clock. Different priority levels are supported:

Note that the provided level of real-time synchronization is "soft", meaning that there are no guarantees that deadlines are met or that latencies are restricted to a predictable (low) maximum. This is often enough to satisfy requirements for interactive simulations and can be compared to the real-time experience provided by computer games. However, applications requiring "hard" real-time synchronization (e.g. HIL simulations) are not satisfied!

Using the "High Priority" and "Real-Time" priorities in Linux will usually require "root" privileges for the simulation process. Using the "Real-Time" priority in Linux with a low-latency kernel as provided by the PREEMPT_RT patch will even provide limited (however, implementation specific limitations given below still apply) "hard" real-time capabilities (see e.g., https://www.osadl.org/Realtime-Linux.projects-realtime-linux.0.html).

IMPORTANT: This real-time synchronization is a hack. Do not rely on it in any (safety) relevant application where precise timing is mandatory!

Implementation Notes

The block introduces an equation with a call to an external C-function that takes the current simulation time as an argument. Within the C-function the simulation time is compared to the operating system real-time clock and execution of the thread is halted until the simulation time equals real-time. This equation will be added to the other model equations and sorted according to the (tool dependent) sorting algorithm. Therefore, no prediction can be made when, within the simulation cycle, the real-time synchronization function is called (e.g., it might be before, or after (external) inputs are read from a device or (external) outputs are written to a device).

Final Remark

If your Modelica tool provides a better mechanism to real-time synchronization, consider to use that mechanism instead of that block. E.g., Dymola provides a "Synchronize with real-time" option within the solver settings. If that option is ticked the "SynchronizeRealtime" block is not needed! However, Dymola only supports that option for Windows (at least Dymola 2013 and below). Also, experiences of the authors indicate that compile and run-time performance seems sometimes better using the "hackish" block, than using the "official" real-time synchronization of Dymola. Please test for yourself, which option works best for you.

Contents

NameDescription
 ProcessPrioritySet process priority

Generated at 2024-11-21T19:25:40Z by OpenModelicaOpenModelica 1.24.2 using GenerateDoc.mos