Is there a good method to tune structure parameters during simulation?

2 Ansichten (letzte 30 Tage)
I have a model with a number of masked subsystems in it (the subsystems are instantiated from a user-defined library). For each of these subsystems, I create a struct in the base workspace containing a number of fields, corresponding to the particular subsystem's parameters. The various parameters are used inside the subsystem by dereferencing the fields of the struct. Here is an example for a subsystem mySys1, with three parameters:
mySys1.G = 1.23;
mySys1.p0 = 100;
mySys1.x = 0.77;
The block (masked subsystem) has a mask parameter named 'paramStructure', whose value is set to 'mySys1'. Inside the block, I access the parameters using the dereferencing syntax: paramStruct.G, etc.
So far, so good - I define the structs in the base workspace, and the model simulates as expected. However, tuning the values of these parameters during a simulation is problematic. Here are the approaches I've tried:
  1. Simply changing the value of the struct variable in the base workspace. This has no effect because Simulink copies the values from the base workspace during initialization.
  2. Making the base workspace variable a Simulink.Parameter object whose Value is set to the contents of the struct, and with the CoderInfo.StorageClass set to something other than 'auto'. Similar to (1) above, changes to this object's Value property do not carry over to the simulation.
  3. Changing the base workspace variable, then using: set_param(myPath,'paramStructure','mySys1'). This has no effect when mySys1 is either a struct or a Simulink.Parameter object.
  4. Using set_param(myPath,'paramStructure',mySys1) (i.e. passing the mySys1 variable instead of its name string as the third argument to set_param). This gives the following error: 'Invalid setting in SubSystem block (mask) '(my path)' for parameter 'paramStructure''. Generally speaking, set_param() requires that the third (value) argument be a string, and I don't know of a way to represent a struct as a string.
  5. The only method that I have had success with is to set the value of 'paramStructure' to some other value, then set it back to the name of the parameter structure in the same call to set_param(). An example: after changing the value of the base workspace variable, I call: set_param(myPath,'paramStructure','0','paramStructure','mySys1')|It seems that this works by forcing Simulink to pull a fresh copy of the base workstation variables into the subsystem's workspace. A variation on this is to call |set_param() on another parameter of the same masked subsystem.
In summary, method 5 works, but seems very kludgy. Does anyone have an alternate method of tuning a parameter structure in Simulink? Is there some other approach to the problem that I'm missing?
Thanks in advance for any ideas/advice.
Some additional info: I am using the model both in Simulink and as a standalone executable generated with Simulink Coder. The parameter structs do show up in the generated code and are tunable there - it is just Simulink that requires the method I described above.
I'm using R2012b (with Simulink 8.0).
Some pertinent documentation links:
  1 Kommentar
Paul
Paul am 9 Jan. 2013
I don't have an answer to your question, but have for a long time been curious about tuning block parameters. Would you mind explaining what your application is where you modify block parameters external to the simulation while the simulation is executing?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kaustubha Govind
Kaustubha Govind am 7 Jan. 2013
Every time you change a parameter value in the workspace, you need to run set_param('modelname', 'SimulationCommand', 'update') or Ctrl+D on the model window, to make Simulink notice the new workspace values.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by