%% PID for a double integrator (0.5/s^2)
% © 2025, Antonio Sala, Universitat Politecnica de Valencia. All rights reserved.
% Videos:
%  https://personales.upv.es/asala/YT/V/dintPIDplace.html  [Spanish]
% https://personales.upv.es/asala/YT/V/dintPIDplaceEN.html  [English]
%

syms s %Symbolic Toolbox
vpa(expand((s+1.2)^3),5) %desired polynomial
s=tf('s'); %Control Toolbox
%Theory is in a handwritten annex.
G=2/s^2;
Kp=4.32/2;
Kd=3.6/2;
Kib=1.728/2;
K=(Kd*s^2+Kp*s+Kib)/s;
CLref=feedback(G*K,1) %setpoint to output TF
zpk(CLref) 
CLdu=feedback(G,K); %input disturbance to output TF
zpk(CLdu)
step(CLref), grid on, xline(2.5,'g')
yline([0.95 1.05],'r:')
step(CLdu), grid on, xline(2.5,'g')

% To change to "ideal form" K_c\cdot (1+T_ds+K_i\frac{1}{s}).

Kc=Kp
Ki=Kib/Kc
Td=Kd/Kc