How do I make a Simulink embedded function run independent of the time step of the model?
조회 수: 5 (최근 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.
댓글 수: 0
답변 (1개)
Venkatachala Sarma
2016년 1월 13일
Hi,
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.
Regards
-Venkatachala Sarma
댓글 수: 2
Venkatachala Sarma
2016년 3월 8일
Please take a look at this example.
Try using triggered subsystem with clock block to track time and implement the embedded function as a pre-emptable task using the example in the link above.
Hope this helps.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!