How do I make a Simulink embedded function run independent of the time step of the model?
조회 수: 6 (최근 30일)
So to explain on this: Let us say I have a simulink model with multiple blocks that I have to run for 100 sec with a time step of 1 sec. The model runs real time. I have added an embedded function added to the model that should run at time = 20 sec only once. However, the embedded function has lots of computations in it, and thus at time = 20 sec, the model takes some time to run the embedded function and thus does not run real time anymore. The question is: I need the function to run at time = 20 sec, but I dont need it to run in one time step necessarily (i.e. the results of the function do not feed into any other block or anything, it is just a result that I want to look at at the end of the 100sec). Can I make the function run independently of the model, i.e. have the model run in real time, and the function take the time it needs to finish independently (as long as it doesn't change the real time performance of the model)? Hopefully, my question makes sense.
Venkatachala Sarma 2016년 1월 13일
It is currently not possible to execute a block as an independent task or a background task directly in Simulink. Simulink just does single tasking and does not support multi tasking at the moment. There are ways to start the block after a particular major step time like using a Clock block from Simulink/Sources and using simulation time feature of a block (get_param). Although you could design your code in the MATLAB function block to indirectly maintain real-time by saving the states and retrieving the states later, it is directly not possible to run a block in background.
One workaround for the case provided here is to save all the data in a '.mat' file and run the logic separately after the execution of the model.