MATLAB: Simulink Test: update constant block in iteration

iterativemodelparameterssetvariablesimulink testtesting

I created a Simulink Model and I would like to use the Test Manager in Simulink Test to run numerous test cases on a Speedgoat (realtime test).
For some test cases I would like to use Scripted Iterations in Test Manager in order to change the speed.
The speed is defined in a constant block.
The problem:
I try to set the contents of that constant block in scripted iterations using setVariable('Name', 'Value', 'Source', 'MainTestModel/SpeedBlock','Value', k)
While executing the testcase "Real time normal shift chain" , I get an error : Invalid parameter 'MainTestModel/SpeedBlock/Value'.
What am I doing wrong?
How can I change the value of the constant block in iterations?
Is it also possible to use a struct in the constant block and still update using "setVariable" ?

Best Answer

The idea is to make use of the "Parameter Overrides" section of the "Real time normal shift chain" in the Simulink Test Manager.
Please follow the steps below:
  1. Select the test "Real time normal shift chain"
  2. Open "Parameter Overrides" section
  3. Click "Refresh" at the bottom of the table. This will actually build the real-time application and retrieve all the available parameters in the model
  4. Note down the name of the parameter set / workspace variable that corresponds to the model element 'MainTestModel/SpeedBlock'. It is likely named 'Speed' based on what I see of your model.
  5. Now you may override this value as follows:
>> setVariable(testItr, 'Name', 'Speed', 'Value', num2str(k));
in your test iterations.
Note that the "Source" argument is not needed here as the 'Speed' variable is already associated with the model element 'MainTestModel/SpeedBlock'.