How to get current time in a rapid accelerator mode in Simulink?

조회 수: 1 (최근 30일)
Ye Lwin
Ye Lwin 2018년 6월 15일
댓글: Walter Roberson 2025년 2월 20일
I was able to get the current real time in Simulink in normal mode using a MATLAB function block and 'clock' function as follow:
function [H,MN,S] = sysClock()
coder.extrinsic('clock');
time = clock;
H = 0;
MN = 0;
S = 0;
H = time(4);
MN = time(5);
S = time(6);
end
However, when I run in the rapid accelerator mode, I received the errors saying
  • "The extrinsic function 'clock' is not available for standalone code generation. It must be eliminated for stand-alone code to be generated. It could not be eliminated because its outputs appear to influence the calling function. Fix this error by not using 'clock' or by ensuring that its outputs are unused."
  • " Unable to build a standalone executable to simulate the model in rapid accelerator mode."
I was wondering if there is any alternative way to get the current time in rapid accelerator mode in Simulink. Thanks.
  댓글 수: 1
Thomas Duquemin
Thomas Duquemin 2020년 1월 27일
I have basically the same question, have you found an answer? I have a variety of extrinsic function calls in a simulink model that I am trying to convert to be used in accelerator mode.

댓글을 달려면 로그인하십시오.

답변 (1개)

Nivedita
Nivedita 2025년 2월 20일
To work around this limitation, you can use a workaround that involves using the Simulink.Parameter object to pass the current time from MATLAB to your Simulink model.
1. Write a MATLAB script that updates a Simulink.Parameter object with the current time. This script will be executed before running the Simulink model in rapid accelerator mode.
% Create a Simulink.Parameter object
currentTime = Simulink.Parameter;
currentTime.CoderInfo.StorageClass = 'ExportedGlobal';
% Function to update the current time
function updateTime()
timeVec = clock;
currentTime.Value = timeVec(4:6); % [Hour, Minute, Second]
end
2. Add a Constant block to your model and set its value to currentTime. This block will provide the current time to your model. And then use Gain blocks or any other blocks to extract the hour, minute, and second from the currentTime vector as needed.
3. Before running the model in rapid accelerator mode, call the updateTime() function to ensure that the currentTime parameter is updated with the latest time.
% Update current time
updateTime();
% Run the model in rapid accelerator mode
simOut = sim('your_model_name', 'SimulationMode', 'rapid');
4. Execute the MATLAB script to update the time and run your Simulink model in rapid accelerator mode. This approach ensures that the current time is passed to the model without using unsupported functions.
I hope this works for you!
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 2월 20일
I get the impression that this process would load the current time as of the time updateTIme() is called, and keep it constant for the rest of the sim() run -- as opposed to something that would provide the then-current time upon each internal call to it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by