Control Tutorials for MATLAB and Simulink - Inverted Pendulum_ PID Controller Design
Control Tutorials for MATLAB and Simulink - Inverted Pendulum_ PID Controller Design
ROOT LOCUS
Related
FREQUENCY
Tutorial
Links
STATE-SPACE
Intro to
DIGITAL
PID
Control
SIMULINK PI Control
Activity
MODELING
CONTROL Related
External
SIMSCAPE Links
MATLAB
PID Video
PID Intro
Video
Contents
System structure
PID control
In this page we will design a PID controller for the inverted pendulum
system. In the design process we will assume a single-input, single-output
plant as described by the following transfer function. Otherwise stated, we
will attempt to control the pendulum's angle without regard for the cart's
position.
(1)
where,
(2)
Pendulum should not move more than 0.05 radians away from the
vertical
For the original problem setup and the derivation of the above transfer
function, please consult the Inverted Pendulum: System Modeling page.
System structure
The structure of the controller for this problem is a little different than the
standard control problems you may be used to. Since we are attempting to
control the pendulum's position, which should return to the vertical after the
initial disturbance, the reference signal we are tracking should be zero. This
You may find it easier to analyze and design for this system if we first
rearrange the schematic as follows.
The resulting transfer function for the closed-loop system from an
input of force to an output of pendulum angle is then determined to be
the following.
(3)
Before we begin designing our PID controller, we first need to define our
plant within MATLAB. Create a new m-file and type in the following
commands to create the plant model (refer to the main problem for the
M = 0.5;
m = 0.2;
b = 0.1;
I = 0.006;
g = 9.8;
l = 0.3;
q = (M+m)*(I+m*l^2)-(m*l)^2;
s = tf('s');
PID control
the output.
Kp = 1;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);
T = feedback(P_pend,C);
Now we can begin to tune our controller. First let's examine the response of
the closed-loop system to an impulse disturbance for this initial set of control
gains. Enter the following code to the end of your m-file and run in the
MATLAB command window. You should generate the response plot shown
below.
t=0:0.01:10;
impulse(T,t)
This response is still not stable. Let's begin to modify the response by
increasing the proportional gain. Increase the variable to see what effect
it has on the response. If you modify your m-file to the following where =
100 and run in the command window, you should get the response plot
shown below.
Kp = 100;
Ki = 1;
Kd = 1;
C = pid(Kp,Ki,Kd);
T = feedback(P_pend,C);
t=0:0.01:10;
impulse(T,t)
axis([0, 2.5, -0.2, 0.2]);
title({'Response of Pendulum Position to an Impulse Disturbance';'
1.64 seconds, which is less than the requirement of 5 seconds. Since the
steady-state error approaches zero in a sufficiently fast manner, no
additional integral action is needed. You can set the integral gain constant
to zero to see for yourself that some integral control is needed. The peak
control. After some trial and error it is found that a derivative gain of =
20 provides a satisfactory response. Modifying your m-file as follows and re-
running should produce the response plot shown below
Kp = 100;
Ki = 1;
Kd = 20;
C = pid(Kp,Ki,Kd);
T = feedback(P_pend,C);
t=0:0.01:10;
impulse(T,t)
does not move more than 0.05 radians away from the vertical. Since all of
At the beginning of this page, a block diagram for the inverted pendulum
system was given. The diagram was not entirely complete. The block
representing the response of the cart's position was not included because
is in place. To see this we need to consider the full system block diagram
as shown in the following figure.
(4)
(5)
where,
(6)
are still defined) will generate the response of the cart's position to the
same impulsive disturbance we have been considering.
constant velocity. Therefore, although the PID controller stabilizes the angle
International License.