Modifying state in S-function

2 vues (au cours des 30 derniers jours)
Thiago Marinho
Thiago Marinho le 12 Juil 2011
Hello guys,
I am working with Level- 2 M files S-functions and I have a problem trying to modify the state.
As in a switching controller ( state jumps) I want to assign manually the value of the state after a certain condition.
So I tried to do something like
block.ContStates.Data = mynewthing;
but it looks like this is completely ignored by the simulation. I have know idea of making it work.
I have seen a class called SimState and function a function called SetSimState in the s-function template but I don't know how to use it and I am having trouble finding documentation on it.
Does someone know how to do this?
Thanks!

Réponses (1)

Titus Edelhofer
Titus Edelhofer le 13 Juil 2011
Hi Thiago,
you cannot directly set the continues states, they are computed by numerical integration. You can only compute the derivative (see function Derivatives in MATLAB\toolbox\simulink\blocks\msfuntmpl.m). If you would have discrete continuous states, then take a look at the function Update, where you set the discrete state (DWork) to whatever you want ...
Titus
  2 commentaires
Thiago Marinho
Thiago Marinho le 19 Juil 2011
Hi Titus,
Thank you for your answer.
If you cannot directly set the states, how can one deal with state switching systems in continuous time ?
Thiago
Titus Edelhofer
Titus Edelhofer le 25 Juil 2011
It depends on what is "continuous" for you: a continuous state is the x in some differential equation like x' = 2*x. This state does not switch (only the differential equation might switch, but this can be done). If you have something like x = g(x, y), where y is the input and x is the x of the timepoint before, you can do this (see my answer above). Simulink can model both in one system ...

Connectez-vous pour commenter.

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by