Generating code for a subsystem accepting structure parameter

16 visualizaciones (últimos 30 días)
Sinan Pakkan
Sinan Pakkan el 10 de Jul. de 2012
Hi,
I'm trying to generate code (using S-function target TLC) for a subsystem with several components accepting parameters, which are fields of a Matlab variable of type structure. I would like the structure parameter fields be tunable in the generated code. - Non-tunable rate transition, ZOH, etc. blocks' parameters are not fields of this structure. - Tunable parameter syntax restrictions in Constant source blocks (such as avoiding [,] and structure referencing) are followed. - A Simulink.Parameter object with value struct is defined in the Base Workspace. - When building the subsystem, this parameter is checked to be "tunable".
However, During the build process Matlab returns a warning in the command window telling me that the the parameter X, which is my structure parameter, is not a built-in type therefore cannot be tunable. Apart from this issue the build process turns out to be OK.
Any ideas what may have gone wrong?
Thanks in advance, Sinan Pakkan
  4 comentarios
Sinan Pakkan
Sinan Pakkan el 11 de Jul. de 2012
I've seen the comment of Kaustubha Govind in Matlab help as well. Therefore, I made sure that there exists no non-numeric fields in the structure.
In fact, the Simulink.Parameter object definition is what bugs me. The procedure I followed is: From model explorer interface, I "add Simulink parameter" to the Base workspace and in the value field I select the structure variable that is available in the Matlab Base workspace at the moment. When this variable is selected "<1x1 struct>" expression is displayed in the Value field of the "add parameter dialog" while the DataType field shows "struct" automatically.
About giving "more detail regarding how I have defined the structure", I can tell that it's a multi-level (a few fields of the structure are themselves structures) 1x1 variable of type "struct" with all numeric entries not even including NaN values. But I'm not sure if this is the question you were asking(?)
Babak
Babak el 1 de Ag. de 2012
- Not all block's parameters are tunable.. for example sampling time cannot be tunable - you also need to create a Simulink.Bus object and set the DataType of the Simulink.Parameter object as the Bus object you just created... this way in the generated code, the structure's fields appear correctly. -MATLAB spits warning for some of the Tunable parameters still if they are places inside a vector like [a,b] or are in the form of a power like a.^3.

Iniciar sesión para comentar.

Respuestas (1)

TAB
TAB el 12 de Jul. de 2012
Editada: TAB el 12 de Jul. de 2012
I think problem is due to you are using multi-level (a few fields of the structure are themselves structures) structure.
See the structure parameter limitations here.
Try using a structure which contains numerical values in all the fields.
MyStruct.Value1 = 100;
MyStruct.Value2 = 200;
MyStruct.Value3 = 500;
MyParam = Simulink.Parameter;
MyParam.Value = MyStruct;
I can't test this feature because I am far behind in the race and using R2007a. *:-(*
  2 comentarios
Sinan Pakkan
Sinan Pakkan el 12 de Jul. de 2012
I just realized this limitation "You cannot define individual substructures or fields within a structure parameter as tunable." and tried generating code with a very simple model (a subsystem including a single gain, which accepts a structure field dereferenced as s.f1).
Result is the same...-> "parameter is not a built-in type, therefore cannot be made tunable".
BTW I'm not quite sure if I get the concept "Associate a Simulink.Parameter object with the structure parameter..." which is written on the same page you refer to. What I did was: Create a Simulink.Parameter object; Select the structure parameter as the "Value" field of this object; replace, in the model, the structure parameter with the Simulink.Parameter object created; Generate code...
TAB
TAB el 12 de Jul. de 2012
Editada: TAB el 16 de Jul. de 2012
Does model build successfully after your changes ?

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by