%% Tune PI Controllers by Using Field Oriented Control Autotuner
% 
% This example computes the gain values of the PI controllers within the speed and current controllers by using the Field Oriented Control Autotuner block. For details about field-oriented control, see <docid:mcb_gs#mw_2d6dd8ca-938f-44d3-8334-f5e42bf4b73b Field-Oriented Control (FOC)>.
% 
% The example supports simulation only. When you simulate the example, the model uses the crude values of gains for the PI controllers to achieve the steady state of speed-control operation.
% 
% The model begins tuning only in the steady state. It introduces disturbances depending on the controller goals (bandwidth and phase margin), in the controller output. The model uses the system response to the disturbances, to calculate the optimal controller gain.
% 

% Copyright 2020 The MathWorks, Inc.

%% Model
% 
% The example includes this model:
% 
% * *mcb_pmsm_foc_autotuner*
% 
% You can use this model only for simulation. You can use the open_system command to open the Simulink(R) model:
%%
open_system('mcb_pmsm_foc_autotuner.slx');
%%
% 
% *Required MathWorks(R) Products for Simulation*
% 
% * Motor Control Blockset(TM)
% * Simulink Control Design(TM)
% 
%% Prerequisites
% 
% *1.* Obtain the motor parameters. 
% We provide default motor parameters with the Simulink(R) model that you can replace with the values from either the motor datasheet or other sources.
% 
% However, if you have the motor control hardware, you can estimate the parameters for the motor that you want to use, by using the Motor Control Blockset parameter estimation tool. For instructions, see
% <docid:mcb_gs#mw_5020c0a3-3cde-4f36-bebc-21090973f8f5 Estimate Motor Parameters by Using Motor Control Blockset Parameter Estimation Tool>.
% 
% The parameter estimation tool updates the _motorParam_ variable (in the MATLAB(R) workspace) with the estimated motor parameters.
% 
% *2.* If you obtain the motor parameters from the datasheet or other sources, update the motor parameters and inverter parameters in the model initialization script
% associated with the Simulink(R) models. For instructions, see
% <docid:mcb_gs#mw_dd32d1fd-68d8-4cfd-8dea-ef7f7ed008c0 Estimate Control Gains from Motor Parameters>.
% 
% If you use the parameter estimation tool, you can update the inverter parameters, but do not update the motor parameters in the model initialization script. The script automatically extracts motor parameters from the updated _motorParam_ workspace variable.
% 
% *Note:* In addition to the preceding products, you also need these products to use the parameter estimation tool:
% 
% * Embedded Coder(R)
% 
% * Embedded Coder(R) Support Package for Texas Instruments(TM) C2000(TM) Processors
% 
%% Simulate and Run Model to Compute PI Controller Gains
% 
% *1.* Open the target model.
% 
% *2.* Click *Run* on the *Simulation* tab to simulate the target model.
% 
% *3.* Observe the computed PI controller gain values in the Display blocks available in the PI_Params_Display_and_Logging subsystem.
% 
% *4.* Update any target model with these gain values so that it brings the motor to a steady-speed state quickly.
% 