필터 지우기
필터 지우기

How to using global variables in reference models

조회 수: 6 (최근 30일)
Michael Frandsen
Michael Frandsen 2011년 9월 21일
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?

채택된 답변

Fangjun Jiang
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
Michael Frandsen
Michael Frandsen 2011년 9월 22일
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 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
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.

카테고리

Help CenterFile Exchange에서 Component-Based Modeling에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by