%% Simulation and Code Generation For Tunable Parameters 
%
% This example shows how to map tunable parameters that are defined as
% Simulink.Parameter objects in the MATLAB(R) workspace to structured text
% code. 
%   Copyright 2011-2021 The MathWorks, Inc.


%% Open Model
% 
mdl = 'plcdemo_tunable_params_slparamobj';
open_system(mdl);
%
% This model uses three parameters K1, K2 and K3 defined in the
% MATLAB base workspace as Simulink.Parameter object.
%
%%
%
% In this model:
%
% * K1 has 'Model default' storage class
% * K2 has 'ExportedGlobal' storage class
% * K3 has 'ExportedGlobal' storage class and 'Const' custom storage class
%
open_system('plcdemo_tunable_params_slparamobj/SimpleSubsystem');
%
%
% Define the parameters K1, K2, and K3 and their storage classes by running
% the following script before simulation and code generation.
%
type setup_tunable_params
%
%% Generate PLC Code
% Open the *PLC Coder* app, select the |SimpleSubsystem| block, and on the
% *PLC Code* tab click *Generate PLC Code*.
%
% To generate code using the MATLAB command line, enter:
%
%   generatedFiles = plcgeneratecode('plcdemo_tunable_params_slparamobj/SimpleSubsystem');
%     
% After the code generation, the Diagnostic Viewer window 
% is displayed with hyperlinks to the generated code files.
% You can open the generated files by clicking on the links.

%% Tunable Parameter Mapping in Generated Code
% In the generated Structured Text code for compatible IDE targets:
%
% * K1 is mapped to a Function Block local variable
% * K2 is mapped to a global variable
% * K3 is mapped to a global constant
% 
% For the RSLogix 5000 Add On Instruction (AOI) format:
%
% * K1 is mapped to an AOI local tag
% * K2 and K3 are mapped to AOI input tags
% 
% For the RSLogix 5000 Routine format:
%
% * K1 is mapped to routine instance tag
% * K2 and K3 are mapped to global program tags
% 
%% See Also
%
%%
%
% * <docid:plccoder_ug#bsft9hy Block Parameters in Generated Code>
% * <docid:plccoder_ug#bshrs3x Control Appearance of Block Parameters in
% Generated Code>
