Example of PID-controller in discrete standard form
Simple examples of PID-controller and how one can simulate simple dynamic model (discrete).
Contents
Define Parameters
a=[1 -0.5]; % define process b=1; % define process y=zeros(1,60); % initialize output u=zeros(1,60); % initialize input r=[zeros(1,10), ones(1,50)]; % setpoint vector e=zeros(1,60); % initialize error signal integral=zeros(1,60); % initialize integral signal derivative=zeros(1,60); % initialize derivative signal K_part=zeros(1,60); % initialize variable for saving the proportional part values K=0.4; % Proportional gain Ti=2; % Integral time Td=0.1; % Derivative time
Simulate and Plot Results (PID-control)
for t=3:60, e(t)=r(t)-y(t-1); % error between setpoint and output integral(t)=integral(t-1)+e(t); % calculate integral action derivative(t)=e(t)-e(t-1); % calculate derivative action K_part(t)=K*(r(t)-y(t-1)); % save value of the proportional part u(t)=K*(e(t)+(1/Ti)*integral(t)+Td*derivative(t)); % PID-control law y(t)=0.5*y(t-1)+u(t); % simulate process end subplot(3,1,1), plot(y), title('Output'), grid on, hold, plot(r,'r'); subplot(3,1,2), plot(u), title('Input'), grid on, subplot(3,1,3), plot(e), title('Error'), grid on figure, subplot(3,1,1), plot(derivative), title('Derivative part'), grid on, subplot(3,1,2), plot(K_part), title('Proportional part'), grid on, subplot(3,1,3), plot(integral), title('Integral part'), grid on
Current plot held