%% Control Design using State-Space Models
% For this example, design a 2-DOF PID controller with a target bandwidth of 0.75 rad/s for a system represented by the following matrices:
% A = \left[ {\begin{array}{*{20}{c}}
% -0.5&-0.1\\
% 1&0
% \end{array}} \right],\quad B = \left[ {\begin{array}{*{20}{c}}
% 1\\
% 0
% \end{array}} \right],\quad C = \left[ {\begin{array}{*{20}{c}}
% 0&1
% \end{array}} \right],\quad D = 0.
% Create a state-space object sys using the ss command.

A = [-0.5,-0.1;1,0];
B = [1;0];
C = [0,1];
D = 0;
sys = ss(A,B,C,D)

% Using the target bandwidth, use pidtune to generate a 2-DOF controller.

wc = 0.75;
C2 = pidtune(sys,'PID2',wc)

% Using the type 'PID2' causes pidtune to generate a 2-DOF controller, represented as a pid2 object. The display confirms this result. The display also shows that pidtune tunes all controller coefficients, including the setpoint weights b and c, to balance performance and robustness.
% For interactive PID tuning in the Live Editor, see the Tune PID Controller Live Editor task. This task lets you interactively design a PID controller and automatically generates MATLAB code for your live script.
% For interactive PID tuning in a standalone app, use PID Tuner. See PID Controller Design for Fast Reference Tracking for an example of designing a controller using the app.
% Copyright 2019 The MathWorks, Inc.