Simulink Test: update constant block in iteration

Illustration
elish_smith - 2021-09-02T11:04:49+00:00
Question: Simulink Test: update constant block in iteration

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" ?  

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

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'.
 
 

The For Iterator block, when placed in a Subsystem block, repeats the execution of a subsystem during the current time step until an iteration variable exceeds the specified iteration limit. You can use this block to implement the block diagram equivalent of a for loop in a programming language.

The output of a For Iterator Subsystem block cannot be a function-call signal. Simulink® displays an error message when the model update


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!