How do I update Simulink model parameters during a simulation?
97 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
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
Voir également
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!