0% found this document useful (0 votes)
49 views13 pages

PID Controller Design For Inverted Pendulum On A Cart

The document details the design of a PID controller for an inverted pendulum on a cart, including physical parameters and linearization at the pendulum angle of zero. It presents MATLAB and Simulink models for both linear and nonlinear systems, showcasing the response of the pendulum angle to impulse disturbances. Additionally, it briefly mentions a combined PID controller for cart position tracking, with specified parameters.

Uploaded by

Hein Thiha Kyaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views13 pages

PID Controller Design For Inverted Pendulum On A Cart

The document details the design of a PID controller for an inverted pendulum on a cart, including physical parameters and linearization at the pendulum angle of zero. It presents MATLAB and Simulink models for both linear and nonlinear systems, showcasing the response of the pendulum angle to impulse disturbances. Additionally, it briefly mentions a combined PID controller for cart position tracking, with specified parameters.

Uploaded by

Hein Thiha Kyaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PID Controller design for inverted pendulum on a cart

Figure 1 Principal diagram of IP

Physical parameters

(M) Mass of the cart 1.096 kg


(m) Mass of the pendulum 0.1096 kg
(b) Coefficient of friction for cart 0.1 N/m/sec
(l) Length to pendulum center of mass 0.0034 m
(I) Mass moment of inertia of the pendulum 0.25 kg.m^2
(F) Force applied to the cart
(x) Cart position coordinate
(𝜃) Pendulum angle

Linearization is done at, 𝜃=0.


PID Controller design using MATLAB
% state space model and transfer function model
M = 1.096;
m = 0.1096;
b = 0.1;
I = 0.0034;
g = 9.8;
l = 0.25;

d = I*(M+m)+M*m*l^2; %denominator for the A and B matrices

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

% PID controller design (K)


figure(1)
Kp = 50;
Ki = 36;
Kd = 8;
K = pid(Kp,Ki,Kd); % PID controller
P = feedback(sys_tf(2),K);% sys_tf(2) is Transfer function from Pendulum angle to input U
t=0:0.01:10;
impulse(P,t)
title('Response of Pendulum angle to an Impulse Disturbance Input');
grid

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 =

From input to output...


0.8831 s^2 + 1.569e-15 s - 23.14
1: ---------------------------------------
s^4 + 0.08831 s^3 - 27.89 s^2 - 2.314 s

2.361 s - 3.429e-17
2: -----------------------------------
s^3 + 0.08831 s^2 - 27.89 s - 2.314
Continuous-time transfer function.

Figure 3 Pendulum angle response using MATLAB


PID Controller design using Simulink
Linear Simulink model
1
ẍ = [u − N − bẋ ]
M
1
θ̈ = ̅ [Nl + Plθ]
I
N = m(ẍ − lθ̈)

P = mg

Figure 4 Linear Simulink model


In order to save all of these components as a single subsystem block, first select all of the blocks
and right click on the selected area, then select Create Subsystem from Selection from the menu.
Your model should appear as follows
Then,
1 Remove input and output block from the above figure
2 Add a Pulse Generator block from the Simulink/Sources library
3 Add a Scope block from the Simulink/Sinks library.
4. Add the PID block from the Simulink/continuous library and , double click on the pid block and
enter the pid parameters.
Kp = 50, Ki = 36, Kd = 8.

Figure 5 Block diagram of pendulum system with PID controller

After running the Simulink model and double click on pendulum angle scope you will get the response
below.
Figure 6 Pendulum angle response

Nonlinear Simulink model of inverted pendulum


1
ẍ = [u − N − bẋ ]
M
1
θ̈ = ̅ [Nl cos 𝜃 + Plsinθ]
I
N = m(ẍ + l sin 𝜃 𝜃̇ 2 − lcosθθ̈)

P = m(g − 𝑙 cos 𝜃𝜃̇ 2 − 𝑙 sin 𝜃 𝜃̈)


Figure 7 Nonlinear Simulink model of Pendulum system

Follow the same approach as in the linear model, the nonlinear model as subsystem is shown below.

Figure 8 Nonlinear Simulink block with PID controller


Response of pendulum angle by nonlinear Simulink model, which is almost identical to the pendulum
angle response obtained by matlab above shown in figure 3.
Figure 9 Response of pendulum angle to the nonlinear model.
Extracting State space and transfer function model from
nonlinear Simulink model

Steps to extract linear model from nonlinear model

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

PID controller for cart position


(This is not required for assignment)
To achieve tracking requirement for cart position, a combined pid controller is used as
shown in the block diagram of figure 11.

Figure 11 combined PID controller for inverted pendulum


Parameters for cart position PID controller are:
Kp=2.5, Ki=0.01, Kd=0.6.

Figure 12 Response of pendulum angle

Figure 13 Cart position response

You might also like