PID Controller Design For Inverted Pendulum On A Cart
PID Controller Design For Inverted Pendulum On A Cart
Physical parameters
A = [0 1 0 0;
0 -(I+m*l^2)*b/d (m^2*g*l^2)/d 0;
0 0 0 1;
0 -(m*l*b)/d m*g*l*(M+m)/d 0]
B = [ 0;
(I+m*l^2)/d;
0;
m*l/d]
C = [1 0 0 0;
0 0 1 0]
D = [0;
0]
G=ss(A,B,C,D);
sys_tf = tf(G) % Transfer function of the system
A =
0 1.0000 0 0
0 -0.0883 0.6339 0
0 0 0 1.0000
0 -0.2361 27.8916 0
B =
0
0.8831
0
2.3607
C =
1 0 0 0
0 0 1 0
D =
0
0
sys_tf =
2.361 s - 3.429e-17
2: -----------------------------------
s^3 + 0.08831 s^2 - 27.89 s - 2.314
Continuous-time transfer function.
P = mg
After running the Simulink model and double click on pendulum angle scope you will get the response
below.
Figure 6 Pendulum angle response
Follow the same approach as in the linear model, the nonlinear model as subsystem is shown below.
1. Save the nonlinear Simulink model given in figure 7 above with name,
“pendulum’’.
2. Run nonlinear Simulink model and write the MATLAB code in command
window.
[A,B,C,D]=linmod2('pendulum')
After running the code you will get the system matrices as below, which is
similar to the system matrices given above, but in different form.
A =
0 0 0 1.0000
0 0 1.0000 0
0 27.8916 0.0000 -0.2361
0 0.6339 -0.0000 -0.0883
B =
0
0
2.3607
0.8831
C =
1 0 0 0
0 1 0 0
D =
The pendulum angle response using the above matrices is shown in figure 10,
which is almost similar to the responses obtained above.
A = [0 0 0 1.0000;
0 0 1.0000 0;
0 27.8916 0.0000 -0.2361;
0 0.6339 0.0000 -0.0883]
B = [0;
0;
2.3607;
0.8831]
C = [ 1 0 0 0;
0 1 0 0]
D =0
G=ss(A,B,C,D);
sys_tf = tf(G)
% PID controller design (K)
figure(1)
Kp = 50;
Ki = 36;
Kd = 8;
K = pid(Kp,Ki,Kd);
P = feedback(sys_tf(2),K);% closed loop system
t=0:0.01:10;
step(P,t)
title('Response of Pendulum angle to an Impulse Disturbance Input');
grid
Figure 10 pendulum angle response