calculate pid controller output for a process with a set-point change in matlab

Assuming you have already designed the PID controller in MATLAB, you can use the pid and feedback functions to simulate the response of the closed-loop system.

First, define the plant transfer function, set-point, and time duration of simulation:

main.m
plant = tf([1],[1 1]); % example transfer function
setpoint = 5; % desired set-point
t = 0:0.1:10; % simulation time duration
126 chars
4 lines

Next, create the closed-loop system by combining the plant transfer function and the PID controller:

main.m
Kp = 1;
Ki = 2;
Kd = 0.5;
C = pid(Kp,Ki,Kd);
sys_cl = feedback(C*plant,1);
75 chars
6 lines

Finally, simulate the response of the system to a set-point change using the step function:

main.m
step(setpoint*sys_cl,t);
25 chars
2 lines

This should give you the step response of the closed-loop system with the PID controller included. The output of the function is the response of the system to the set-point change.

gistlibby LogSnag