Variant Subsystem for code generation

3 views (last 30 days)
BCP
BCP on 21 Oct 2020
Commented: BCP on 26 Oct 2020
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.

Accepted Answer

Mark McBroom
Mark McBroom on 24 Oct 2020
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!