Effacer les filtres
Effacer les filtres

How to using global variables in reference models

6 vues (au cours des 30 derniers jours)
Michael Frandsen
Michael Frandsen le 21 Sep 2011
I am starting to build up a model an actuator control system. Previously I have made everything in one big system only by use sub system blocks. To avoid problems with redundant copied blocks I wanted to use reference models but runs into problems about defining and use global system constants.
A simple version of my model could be viewed as following where each () represent a reference model:
- System
- Hardware
- Software
- (Regulator)1
- (Regulator)2
- (Actuator)1
- (Motor)
- (Actuator)2
- (Motor)
Each of the models has several parameters defining behavior and some parameters are shared among several blocks. Example some parameters used in motor are also used in regulator and software use a certain sample time that also needs to be used in each regulator and so on.
At first I thought I could use my previous method by defining all as matlab variables in the InitFcn of overall system but then I get errors in each reference model that variable is not defined. Then I created local variables in each reference model and transferred the parameters as model arguments but got error about you cannot have sample time as model argument.
I need some advice how to organize my system so I only have to update global constants in one location. What am I doing wrong? How can I get around the problems I face as example defining sample time in global variables?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 21 Sep 2011
See "global tunable parameters" and "Global nontunable parameters" in the document or at this link. http://www.mathworks.com/help/toolbox/simulink/ug/f4-141787.html
  2 commentaires
Michael Frandsen
Michael Frandsen le 22 Sep 2011
I think the limitations to the reference model is to big and I have to use libraries instead if I want to avoid the redundant copies. Correct me if I am wrong but I cannot make a reference model that have different sample times in every instance.
Reference models is most useful for combining systems rather than structure single systems.
Fangjun Jiang
Fangjun Jiang le 22 Sep 2011
Yes, whether using model reference of library depends on your use case. Regarding different execution rate for each instance of the model reference, I think it can be done. You can make the model reference a triggered model reference and trig it using Function Call Generator. You might need to set the internal model correctly to avoid potential conflict.

Connectez-vous pour commenter.

Plus de réponses (1)

Michael
Michael le 23 Sep 2011
You're right that you can not parameterize the sample-time of a referenced model using model arguments. But if the referenced model is single-rate, and doesn't specify any sample time information, the model can inherit a sample time from the context it is used in.
You can also use a single base workspace variable to set the sample time of blocks in the referenced models, but you can't do it in the InitFcn of the top model. But you need initialize all of these workspace variables using some type of setup script, or in the post-load function of the top model.

Catégories

En savoir plus sur Component-Based Modeling 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