How to using global variables in reference models
Show older comments
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?
Accepted Answer
More Answers (1)
Michael
on 23 Sep 2011
0 votes
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.
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!