Variant Subsystem for code generation

조회 수: 6 (최근 30일)
BCP
BCP 2020년 10월 21일
댓글: BCP 2020년 10월 26일
Hi all,
I'm trying to contemplate the idea of using "Variant Subsystem" instead of regular "if" or "Switch" cased in terms of code generation efficieincy. I will try to describe breifly my situation.
Goal: To generate C code for a complete model.( which contains plenty of referenced models and subsystems)
Use case: I have defined mutiple Look up tables and I would like to pick one for my calculation based upon the user request. Hence, the selection will always come from outside the model.
Modelling Method :
  1. I created a variant subsystem with all different Look up tables in it. Using the variant manager I have defined a control expression for each case like "Type == 1" , Type == 2 and etc.
  2. I have defined a simulink.parameter object "Type" in the model referenced datadictionary. I have to give a value without which my parameter is empty.
  3. I choose storage class "define" for code generation and gave a custom name for the header file.
Issues:
  1. Like mentioned in the use case, the variable "type" is coming from outside the model. Hence, it would be ideal to dynamically update the parameter " type" based upon the inport signal.
  2. Unfortunately, the simulink.parameter object doesn't support this ( at least within my knowledge).
  3. So it's deadend for me. But interestingly after reading some documentation and doing some research. I found that I can use the define statements generated by the autocoder to configure the "type" parameter during runtime.
I also tried a workaround by defining a simulink.variant object and simulink.signal in the data dictionary. I have referred to this defined signal in the simulink.variant expression and used this variant directly in my variant configuration. However, I have the following error.
Unsupported data type 'undefined' for object 'InputSignal' in variant Type1 condition expression
'InputSignal == 1' used by block 'TCC_TrendCorrection/CalcBathMass_Kg/Variant Subsystem'.
Only Integer, Boolean and Enumerated types are allowed.
For code generation, you can use normal MATLAB variables or [Simulink.Parameter's. ' ...
'When Simulink.Parameters are used, they must have one of the following custom storage classes:]
- Define or ImportedDefine with header file specified
- CompilerFlag
- SystemConstant (AUTOSAR.Parameter)
- User-defined custom storage class that defines data as a macro in a specified header file
But I was just contemplating, should I really do this. As this involves lot of work. Instead ditch the idea of variant subsytem and use the regular switch or if-else expressions for choosing a specific look up table.
I really appreciate your feedback, suggestions or ideas on this topic.
Thank you all guys in advance for your contribution.

채택된 답변

Mark McBroom
Mark McBroom 2020년 10월 24일
Variant subsystems only support compile time selection of a variant subsystem via #ifdef macros inserted in the genearted code around each variant subsystem. If you want to switch between different lookup tables at runtime, you will need to use an if, switch or similar construct.
Thanks.
mark.
  댓글 수: 1
BCP
BCP 2020년 10월 26일
Thanks for the answer Mark.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by