Passing information between level-2 matlab s-functions
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to model a two step chemical process using simulink and s function for each step. 5 outputs from step 1 are connected to the 5 inputs of step 2. I initialize the outputs of step 1 in its s function using read in parameters. When I initialize the state variables of step 2, which uses outputs from step 1, the values of the output the output variables of step 1 inside step 2 initialization are zero. What can I do to fix this?
Thanks. Girish
0 comentarios
Respuesta aceptada
Jarrod Rivituso
el 12 de Abr. de 2011
Some background info that you may find useful...
- Simulink goes through an "initialization" phase prior to starting its simulation loop. Here it will call certain S-function methods for each block, such as the method that will initialize the state variables (for MATLAB S-functions, I believe this is the InitializeConditions block method).
- During the simulation loop, Simulink typically first computes all block outputs, then it will go back and compute updates to state values. This is the typical "Output" and "Update" functions.
One key thing to note is that the initialization part comes prior to any block outputs being produced. On that note, it sounds based on your description that you are trying to use a block input value during the initialization phase of the simulation. This is not going to work for you.
Each block must set its own initial state values based on initial conditions. You could use some MATLAB code outside of the S-functions to pass the correct initial values to each, if that is necessary.
1 comentario
Jarrod Rivituso
el 12 de Abr. de 2011
Note that you can use the block sorted order to determine which block executes first. To do this, select Format -> Block Displays -> Sorted Order. The sorted order is determined automatically by Simulink based on which blocks rely upon which other blocks.
To be more clear, my suggestion is that you do the following
1. Write a MATLAB script that calculates the initial conditions for each block in the base workspace
2. Use the initial conditions calculated in the base workspace as parameter arguments to their appropriate S-functions.
3. In each S-function's "Initialize" method, set the initial values of the internal states to the parameter values of the S-function.
4. Use the state values in the "Outputs" method as you require.
Does that make sense?
Más respuestas (1)
Girish
el 12 de Abr. de 2011
4 comentarios
Jarrod Rivituso
el 13 de Abr. de 2011
Generally, continuous state blocks will have the following kind of flow during the simulation loop:
Outputs – creates the block output using the current value of the continuous state
Derivatives – creates the derivative of the block using the current value of the input signal, and possibly other factors as well
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!