MATLAB Examples

Check Component and Push Parameter to Main Model

This example shows a basic workflow of updating a parameter in a test harness, checking the synchronization between the test harness and main model, and pushing the parameter change from the test harness to the main model.

Contents

This example also includes programmatic steps.

Open the model sltestCar. The model includes a transmission shift controller algorithm and simplified powertrain and vehicle dynamics.

open_system('sltestCar');

Update the Mask Parameter in the Test Harness

1. Open the test harness. Click the badge on the shift_logic chart and select the ShiftLogic_InportHarness test harness. The test harness is set to synchronize only when you push to or rebuild from the main model.

sltest.harness.open('sltestCar/shift_logic','ShiftLogic_InportHarness');

2. Double-click the shift_logic subsystem. For Delay before gear change (tick), enter 4. Click OK.

shiftLogicMask = Simulink.Mask.get('ShiftLogic_InportHarness/shift_logic');
maskParamValue = shiftLogicMask.Parameters.Value;
shiftLogicMask.Parameters.Value = '4';   % Set the new parameter value

Check Synchronization between Test Harness and Main Model

On the command line, run the sltest.harness.check function.

[comparison,details] = sltest.harness.check('sltestCar/shift_logic',...
    'ShiftLogic_InportHarness');

The results show that the component under test is different in the test harness due to the updated mask parameter.

comparison
comparison =

  logical

   0

details
details = 

  struct with fields:

     overall: 0
    contents: 1
      reason: 'The contents of harnessed component and the contents of the component in the main model are same, but they differ in terms of block or mask parameters.'

Update the Parameter to the Main Model

1. In the test harness, select Analysis > Test Harness > Push Component and Parameters to Main Model.

2. In the main model, double-click the shift_logic subsystem. The parameter value is updated.

sltest.harness.push('sltestCar/shift_logic','ShiftLogic_InportHarness')

Re-check Synchronization between Test Harness and Main Model

On the command line, update the main model and test harness. Then, run the sltest.harness.check function.

set_param('sltestCar','SimulationCommand','update');
set_param('ShiftLogic_InportHarness','SimulationCommand','update');
[comparison,details] = sltest.harness.check('sltestCar/shift_logic',...
    'ShiftLogic_InportHarness');

The results show that the component under test is the same between the test harness and the main model.

comparison
comparison =

  logical

   1

details
details = 

  struct with fields:

     overall: 1
    contents: 1
      reason: 'The checksum of the harnessed component and the component in the main model are same.'

close_system('sltestCar',0);