How to get current time in a rapid accelerator mode in Simulink?
4 次查看(过去 30 天)
显示 更早的评论
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
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
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!