Update Simulink blocks values in realtime mode

2 Ansichten (letzte 30 Tage)
Fabio Rossi
Fabio Rossi am 29 Mär. 2017
Beantwortet: Omanshu Thapliyal am 31 Mär. 2017
Hi guys! I'm working on a simulink simulation. I want to run this simulation for a lots of time with cyclical parameters blocks update.
I'm able to pause the model, run the script that elaborates some values, update these parameters and then continue the simulation(as explained in PauseSimulation ). But this solution isn't efficient for my porpouse because it spends too much time to run the script. The same thing happens if I try to use the Simulink function block.
So my idea is to run the simulation and the script in parallel mode when new parameters are needed. My pc is a dual-core: the simulation should use a core and the script the another core. To perform this action I use the 'batch' command inside Assertion block so it runs my script on a separate worker. In this way the simulation should continue without pausing too much time and when the script is completely executed the new values are updated in Simulink blocks. Is this a possible solution to make the model 'real-time'?
Obviously I found some problems. The assertion block works fine but I'm not sure that my script is run from batch command. The values aren't updated nevertheless the simulation proceed until the end. I think it is also a workspaces problem. Simulation and script have different workspaces and so it is possible that the 'set_param' command in the script isn't executed..
So, my questions are:
Is it possible to run a script in batch mode from Simulink block?
How to refer Simulation and script to the same workspace? or how to update Simulink blocks values from a script run in batch mode?
Are there other ways to reach my goal?
Thanks for attention,
Fabio

Antworten (1)

Omanshu Thapliyal
Omanshu Thapliyal am 31 Mär. 2017
A possible way to run a script/function in batch mode in Simulink is to use model callbacks in Simulink. This was you can have pre-load functions (PreLoadFcn), post-load functions (PostLoadFcn), close functions (CloseFcn), stop function (StopFcn), etc. associated with the model. These callback values get assigned into the MATLAB base workspace and Simulink can access them real-time. In addition to having model callbacks, you can have block callbacks as well.
This link sheds more insight upon controlling blocks programmatically.
To choose which workspace to store data to, you can refer here. To change workspace data from a Simulink model, you can see here.

Kategorien

Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by