How to using global variables in reference models
6 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Fangjun Jiang
2011-9-21
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 个评论
Fangjun Jiang
2011-9-22
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.
更多回答(1 个)
Michael
2011-9-23
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Component-Based Modeling 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!