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 :
- 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.
- 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.
- I choose storage class "define" for code generation and gave a custom name for the header file.
- 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.
- Unfortunately, the simulink.parameter object doesn't support this ( at least within my knowledge).
- 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
- 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.