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

%%
% 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.
%
% To open the test harness from the command line, use:

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*.
%
% To change the value from the command line, use:

shiftLogicMask = Simulink.Mask.get('ShiftLogic_InportHarness/shift_logic');
maskParamValue = shiftLogicMask.Parameters.Value;
shiftLogicMask.Parameters.Value = '4';   % Set to 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

%%
details

%% Update the Parameter to the Main Model
%
% 1. In the test harness, on the *Harness* tab, click *Push Changes*.
%
% 2. In the main model, double-click the shift_logic subsystem. The
% parameter value is updated.
%
% To push the change using the command line, use:

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

%%
details

%% 
close_system('sltestCar',0);


%% 
% Copyright 2012 The MathWorks, Inc.