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!