Effacer les filtres
Effacer les filtres

How do I update Simulink model parameters during a simulation?

97 vues (au cours des 30 derniers jours)
GLW
GLW le 9 Juil 2013
Commenté : yi yu le 6 Avr 2020
I have a Discrete PI controller Simulink model embedded within a triggered sub-system. I have a separate piece of embedded Matlab code which I am trying to use to update the PI controller parameters, such as the Gain, upper and lower limits etc.
In the embedded Matlab code, I have the following line:
GainValue_s(:) = GainValue_s+5.25;
assignin('base','GainValue',GainValue_s);
so I'm assigning the gain value to a workspace variable, this is updated periodically throughout the simulation.
In the Simulink model PI controller, the field for the 'Proportional (P):' gain value has the following:
evalin('base','GainValue')
The design compiles and simulates without any errors, however I think that the triggered subsystem only uses the first GainValue that it picks up from the base workspace, I know that the GainValue changes during the simulation but the output from the PI controller remains constant after the first trigger.
Any ideas if what I'm doing is valid or not, or is there a better way of updating these values on the fly?
Thanks

Réponses (1)

Kaustubha Govind
Kaustubha Govind le 10 Juil 2013
In general, what you're doing is considered bad practice. To understand why, please read How Do I Change a Block Parameter Based on the Output of Another Block? Ideally, you would want to use a PI Controller block that accepts the 'P' gain as an input signal rather than as a parameter. Your MATLAB Function block then then emit an output signal with the desired 'P' value that is routed to the input of the PI Controller block.
Having said that, when a value of a parameter changes in the base workspace, you need to run Ctrl+D on the model, or set_param('modelname', 'SimulationCommand', 'update'), for Simulink to pick up the new value from the workspace. Alternatively, you can directly run set_param on the PI Controller from the MATLAB code, to change the parameter value directly (instead of indirectly via the base workspace).
  1 commentaire
yi yu
yi yu le 6 Avr 2020
thank you very much, your answer solved my issues well

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by