Executing Simulink Code before the Simulation
2 views (last 30 days)
Im am working on a model, which dynamically creates a Route consisting of various parts, which are characterized by a starting point (xyz_start) and an end point (xyz_end). The Route can be created by assembling those parts. Since I want to provide this (static) Route information to other parts of my simulation, I want to calculate the Route information before the actual simulation and store it in a data store memory. The calculation of the Route should not be executed during the simulation. My idea was to make this possible by enabled subsystems and an init parameter, which is 1 while the initialization and 0 while the simulation.
I know I have to work with Callback Functions but how can I execute the Code before the Simulation (e.g. for a specific time period) and change the init parameter after that, so that the Route informations are calculated and stored in the data store memory?
The model is attached. Thanks a lot for your help!
Note to the Data Store Memory: The Size is calculated by the count of Blocks with the Tag 'Strecke'. Rows: Blocks columns: 1 - block (1 if it is already taken, 0 if not) 2 - x-start of block 3 - y-start of block
A Jenkins on 19 Sep 2014
1) You can use a Clock block with a Compare to Constant block to control blocks to only execute during parts of the simulation.
2) Alternatively, you could separate your simulations, so that your Main Simulation calls your Initialization Simulation before it even begins. In your MainSimulation.mdl, go to File->Model Properties->Callbacks->InitFcn, and add
Then you proabably need to add ToWorkspace and FromWorkspace blocks to pass the data between the two simulations.