%% Convert 1-DOF PID controller to 2-DOF
% Design a 1-DOF PID controller for a plant.

G = tf(1,[1 0.5 0.1]);
C1 = pidtune(G,'pidf',1.5)

%
% Convert the controller to two degrees of freedom.

C2 = make2DOF(C1)

%
% The new controller has the same PID gains and filter constant. It also contains new terms involving the setpoint weights b and c. By default, b = c = 1. Therefore, in a closed loop with the plant G, the 2-DOF controller C2 yields the same response as C1.

T1 = feedback(G*C1,1);
CM = tf(C2);
T2 = CM(1)*feedback(G,-CM(2));
stepplot(T1,T2,'r--')

%
% Convert C1 to a 2-DOF controller with different b and c values.

C2_2 = make2DOF(C1,0.5,0.75)

%
% The PID gains and filter constant are still unchanged, but the setpoint weights now change the closed-loop response.

CM_2 = tf(C2_2);
T2_2 = CM_2(1)*feedback(G,-CM_2(2));
stepplot(T1,T2_2,'r--')

% Copyright 2015 The MathWorks, Inc.