Report For Mathwork Fileexchange PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Mobile Inverted

Pendulum
Analysis and Simulation

IIEE Visionaries
Document Version 1.0
Contents

ABOUT THE AUTHOR………………………………………………………………………………………………………………………....i

TECHNICAL ADVISORS……………………………………………………………………………………………………………………..…ii

PREFACE……………………………………………………………………………………………………………………………………………iii

1 APPLICATIONS OF MOBILE INVERTED PENDULUM......................................................................... 1


2 MATHEMATICAL MODEL................................................................................................................. 2
2.1 SYSTEM DYNAMICS ................................................................................................................. 2
2.1.1 LINEAR MODEL OF THE DC MOTOR ................................................................................ 2
2.1.2 INTERMEDIATE BODY DYNAMICS ................................................................................... 5
3 ANALYSIS AND SYSTEM COMPENSATION DESIGN .......................................................................... 9
3.1 SYSTEM ANALYSIS ................................................................................................................... 9
3.1.1 IMPULSE RESPONSE OF UNCOMPENSATED OPEN LOOP SYSTEM .................................. 9
3.2 SYSTEM COMPENSTATION DESIGN: ..................................................................................... 10
3.2.1 RLTOOL .......................................................................................................................... 10
3.2.2 USING RLTOOL .............................................................................................................. 10
3.2.3 STARTING RLTOOL......................................................................................................... 11
3.3 FINDING COMPENSATION GAIN ........................................................................................... 13
3.4 MINIMUM COMPENSATION GAIN ........................................................................................ 15
3.5 FINDING PID PARAMETERS ................................................................................................... 16
4 SIMULINK MODEL AND SIMULATION ........................................................................................... 17
4.1 FEEDBACK CONTROL SYSTEM SIMULATION: ........................................................................ 17
4.2 BLOCK DESCRIPTIONS: .......................................................................................................... 17
4.3 SIMULATION DESCIPTION: .................................................................................................... 17
4.4 OBSERVATION: ...................................................................................................................... 17
5 CONCLUSION ................................................................................................................................. 21
6 Bibliography .................................................................................................................................. 22
7 APPENDIX ...................................................................................................................................... 23
7.1 MATLAB CODE:...................................................................................................................... 23

1
ABOUT THE AUTHOR
This document “Mobile inverted
pendulum Analysis and Simulation” is
the collection of MATLAB simulation
(scripts and SIMULINK model) and its
result useful for analyzing the
behavior of mobile inverted
pendulum.

This collection was developed by:

MIR TAHA ALI


Mir Taha Ali is currently the student
of Industrial Electronics Engineering,
PCSIR, NEDUET, Karachi, Pakistan of
B.E degree program in the field of
Industrial Electronics Engineering.

The author can be approached at:

E-MAIL:

mirtahaali@iiee.edu.pk

MAILING ADDRESS:
MIR TAHA ALI,
C/o Institute of Industrial Electronics
Engineering (IIEE), PCSIR. ST-22/C,
Block 6, Gulshan-e-Iqbal, Karachi -
75300, Pakistan.

i
Technical advisors
Engr. Ashab Mirza
Associate Professor at IIEE
Postgraduate Course & Research
Work, PNEC, NUST.
MS (Aerospace Engr.) ENSAE,
Toulouse, France
BE (Electronics) NEDUET, Karachi
Email: ashab@iiee.edu.pk

Engr. Sajid Hussain


Chief Instructor at IIEE
M.E (Industrial Control and
Automation), UIT, Karachi
B.E (Industrial Electronics), IIEE,
Karachi
Email: sajid@iiee.edu.pk

ii
PREFACE
This document “Mobile inverted pendulum Analysis and Simulation” is the collection of
MATLAB simulation (scripts and SIMULINK model) and its result useful for analyzing the
behavior of mobile inverted pendulum.

This report was developed as a part of final year project design report for the B.E program
of INSTITUTE OF INDUSTRIAL ELECTRONICS ENGINEERING, KARACHI, PAKISTAN.

The challenge of balancing an inverted pendulum has drawn an interest on researchers all
around the world due to its uniqueness. And now inverted pendulum alike behavior
systems are developed for different uses and applications.

The technique of controlling inverted pendulum is used in the FLIGHT SIMULATION OF


ROCKETS OR MISSILES because the center of drag of rocket is above its pivot point hence
the SIMULATION OF ROCKETS OR MISSILES because the center of drag of rocket is above its
pivot point hence the system always tries to move from its desired direction. Also this type
of controlling technique is used in such systems in which the system body should remain
stationary and the base of system is in motion i.e. is Tank . The detail of this paper can be
find out in the bibliographic section.

CONTENTS OVERVIEW
This report comprises of sections

 SECTION 1 introduction of mobile inverted pendulum and its major possible


applications.
 SECTION 2 explores the mathematical model of mobile inverted pendulum.
 SECTION 3 analyzes the mathematical model that consists of pole/zero and root
locus plot of system and its possible system compensation design.
 SECTION 4 provides the SIMULINK model for mobile inverted pendulum. The system
use PID control technique to control the multivariable of the system.
 SECTION 5 explores conclusion of entire simulation and result.

iii
1 APPLICATIONS OF MOBILE
INVERTED PENDULUM

The self-balancing robot is a system similar to the classical mechanical system of an inverted
pendulum on a cart. It is an interesting system to control since it is relatively simple, yet
non-linear and unstable. Following are the main points that define the need of the project
are:
 The system of two wheel balancing robot is a good platform for researchers to
investigate the efficiency of various controllers in control system. [1]
 Conventional vehicles are based on three or four wheels, which has more parts and
less degree of freedom. The idea of TWBR can be applied to this problem. For
example, a motorized wheelchair utilizing this technology would give the operator
greater maneuverability and thus access to places most able bodied people take
granted. [2]
 The idea of TWBR can be applied to various problems, such as designing walking
humanoid robot, robotic wheelchairs and personal transport systems.
 The main advantages of making a two wheeled vehicles is that it have less parts than
conventional three or four wheeled vehicles, and due to less parts it has less weight
and due to less weight, its fuel consumption is less and it is considered to be fuel
efficient and eco-friendly vehicle. The two-wheeled robot is the combination of
wheeled mobile robot and inverted pendulum system. It also brings the concept of
creating a transporter for human. [3]

1
2 MATHEMATICAL MODEL

2.1 SYSTEM DYNAMICS


The two-wheeled inverted pendulum is an unstable system. Unlike conventional inverted
pendulum, it is more difficult to balance the pendulum on two wheels. In order to get it
balanced, we must understand the wheel dynamics and the dynamics of the pendulum
body.

2.1.1 LINEAR MODEL OF THE DC MOTOR

The torque produced by motor can be given as,

(1)
i = Current through motor coil
kM = motor torque constant
= motor torque
The back electromagnetic force produced by the coils can be given as

̇ (2)
Ve = Back EMF
Ke = Back EMF constant
According to Kirchhoff’s law, the sum of voltages in the circuit must be zero. Hence the
voltages present in the circuit are due to resistance of coil, inductance of coil and back EMF.

(3)

Va = Applied Voltage
L = Inductance of motor coil
R = Resistance of motor coil
To make the equation simpler, we have neglected the inductance of motor. Equation (3) can
be rewritten as,

̇ (4)

2
Newton’s law of motion states that the sum of all toques produces on the shaft is linearly
related to the acceleration of the shaft by the inertial load of armature IR. Hence the
statement can be written as,

∑ ̇ (5)

= Motor Torque
= Applied Torque
= Rotor inertia or Wheel inertia
Torque due to friction of motor shaft is neglected in equation (5).

̇ (6)

Substituting equation (4) into equation (6) and rearranging, we get the equation for torque,

(7)
( ̇ )

Let, = TR
TR = Applied torque on right wheel.
Figure (3) showing the free body diagram of right wheel. Free body diagram of the left
wheel will be similar to right wheel.

Figure- 1: Vectors Diagram of Wheels with Loads

The force (Fy) on the wheel in the horizontal direction can be given as:-

∑ ̈ (8)

3
Fy = Force on wheel in horizontal direction
Mw = Mass of wheel
Y = Linear displacement in horizontal direction
̈

HfR = friction force between wheel and ground.


HR = horizontal reaction force (9)
Sum of forces around the center of the wheel gives;

∑ ̈ (10)

Mo = Total moment of force on wheel


Iw = Moment of inertia of wheel
Θw = Angular displacement of wheel
̈ (11)
TR = Torque due to motor on right wheel
RW = Radius of wheel
From equation (7), motor torque can be given as,
(12)
( ̇ )

VR = Applied voltage on the right motor


So, equation (11) becomes;

̈ (13)
( ̇ )

̈
( ̇ ) (14)

Equation (14) is substituted into (9) to get the equation for the left and right wheels

For the left wheel,


̈ (15)
̈ ( ̇ )

For the Right wheel,

4
̈ (16)
̈ ( ̇ )

Because the linear motion is acting on the center of the wheel, the angular rotation can be
transformed into linear motion by simple transformation [4],
̇ ̇

̇
̇
For the left wheel,
̈
̈ ( ̇)
(17)

For the right wheel,


̈
̈ ( ̇) (18)

Adding equation (17) and (18) together yields,

[ ] ̈ ( ̇) (19)

Equation (13) is the first equation of motion of the system.

2.1.2 INTERMEDIATE BODY DYNAMICS

Consider Figures (1) which represent the free body diagrams of the IB. Applying the
Newton’s second law of motion in the Y direction yields

∑ ̈ (20)

Fy = Sum of forces in the horizontal direction


Mp = Mass of structure and payload
Sum of forces in the horizontal direction will be:
∑FY = Horizontal reactive forces + force producing linear acceleration

∑ ̇ ̈ (21)

= Tilt angle of pendulum

5
L = Length of frame
HR,HL = Horizontal reaction forces between the IB and wheel axle
Considering the sum of the applied forces in a direction perpendicular to the rod gives,
∑F↑ = Horizontal reaction forces + vertical reaction forces + force due to linear
acceleration
̈ (22)
G = Gravitational force
PR, PL = Vertical reaction forces between the IB and wheel axle
Finally, equating the sum of the applied moments yields,

∑ ̈ (23)

= Moment of Inertia of frame.

̈ (24)
Torque due to each motor is:

( ̇ ̇)
(25)
Putting (25) in (24), we get,

( ̇ ̇ ) (26)

Adding equation (26) with (22) to remove HR, HL, PR and PL,

( ) ̈

( ̇) (27)

Putting the value of (HR+ HL) from equation (21) into (19), we get,

6
̈

( ̇) ̇
(28)

Rearranging equations (27) and (28) gives the non-linear equations of motion of the system,

( ) ̈ ( ̇)
(29)
̈

[ ] ̈ ( ̇)
(30)
̈ ̇

The above two equations (29) and (30) can be linearized by assuming θ =π+ , where
represents a small angle from the vertical upward direction. Since, we do not want the
pendulum to get tilted at angle greater than 15 degrees.

( )

The linearized equation of motion is,

( ) ̈ ( ̇) ̈ (31)

[ ] ̈ ̇ ̈ (32)

In order to get the state space representation of the system, equations (31) and (32) are
rearranged,

7
̈
̈ ( ̇)
( ) ( )
(33)

( ) ( )

̈ ( ̇)
[ ] [ ]
(34)
̈
[ ]

By substituting equation (33) into equation (31), substituting equation (34) into equation
(31) and after a series of algebraic manipulation the state space equation for the system is
obtained [5].

̇
̈ ̇
[ ] [ ]
̇
̈ ̇
[ ]

[ ]

Where

[ ] [ ]

In the model above, it is assumed that the wheels of the vehicle will always stay in contact
with the ground and that there is no slip at the wheels. Cornering forces are also considered
negligible.

8
3 ANALYSIS AND SYSTEM
COMPENSATION DESIGN

3.1 SYSTEM ANALYSIS


3.1.1 IMPULSE RESPONSE OF UNCOMPENSATED OPEN LOOP SYSTEM

The system response can be observed by its impulse response that is applying impulse input
to the system.
Because the system is inherently unstable, an impulse input applied to the open loop
system will cause the tilt angle and position of the robot to rise unboundedly. This results in
the robot falling. As shown in figure-4. [6]
In order to find the problem, we must observe the system poles location.
Plotting the Pole-Zero Map of the system verifies that the system is unstable as shown in
figure-5 as there is a pole on the right-hand plane of the plot. Ideally, all poles should be on
the left-hand plane of the plot for the system to be stable.
The poles of the system are located at 0, -0.006, 13.519, -13.521.

Figure- 2: Impulse Response of Uncompensated System

9
Figure- 3: Pole/Zero Plot of Uncompensated System

3.2 SYSTEM COMPENSTATION DESIGN:


In order to design PID control system, we have to find its parameters, so we are using root
locus technique.
The compensator designing has been done with Matlab rltool.

3.2.1 RLTOOL

RLTOOL is a tool in MATLAB, which provides a GUI for performing Root Locus analysis on
Single Input Single Output (SISO) systems, which are the class of systems we cover in E105.
RLTOOL is a component of the broader SISO Design Tool in MATLAB, which can also do Bode
and Nyquist analysis.

3.2.2 USING RLTOOL

RLTOOL provides a fast, easy, and useful way to design compensators, and see their
influence on the root locus drawn in the complex plane. With RLTOOL, we can quickly add,
remove, and move compensator poles and zeros, or change proportional gains, and see the
result on the location of the closed loop poles of the system. In addition, RLTOOL can bring

10
up plots of system responses to reference or disturbance inputs, so we can verify the
performance of our compensator-plant system.

3.2.3 STARTING RLTOOL

RLTOOL can be called with a variety of command arguments. Type ‘help rltool’ at the MATLAB
command prompt to see the options available. Typically, we’ll create a plant transfer function ’G’ in
MATLAB first, and then import it to RLTOOL with the command [7]:
>> rltool (G)
Steps for compensation design:
 Type rltool(G) in MATLAB command window
 Control and Estimation Tools Manager window and corresponding SISO design window
appears.
The root locus of uncompensated system is given in figure-7:
From the graph, it is observed that the there is always a pole exists on right have plane.
Hence the system will be unstable at any value of compensated gain. So in order to make
the system stable we have design the root locus such that all pole must exists on left hand
side.
Since because there is a zero exists at origin the loci goes to infinity. So to remove zero at
origin, we add pole at origin.
 Go to Compensator Editor Tab in Control and Estimation Tools Manager window.
 Right Click Pole/Zero Dynamics area>Add Pole/Zero>Integrator. Figure-7
The root locus is then shown in figure-8.
The loci going to infinity on right half plane as in figure-8. The system is still unstable at
all the value of compensation gain.

11
Figure- 4: Root locus of uncompensated system

Figure- 5: Control and Estimation Tools Manager Window

12
Figure- 6: Root locus after adding an integrator

Since loci goes to infinity in right half plane, we have to add zero on left hand side, which
will attract loci toward it. Adding zero at -10.
 Right click Pole/Zero Dynamics area>Add Pole/Zero>Real Zero. Figure-9
Adding another zero at -10, figure-10, in order to get a part of locus where all the roots are
at left hand side.
This is the root locus of compensated system. As shown there is a part of root locus where
all the roots are on left hand side of plane. So in order to find the root where system
response is best, we have to find the compensation gain where the system response is best.
The system response is best when damping ration is considered to be approx. 0.7.

3.3 FINDING COMPENSATION GAIN


In order to find compensation gain, we find the gain at damping ratio 0.726 because 0.726
damping is good response; hence we find the gain as shown in figure-10 using rltool in SISO
design window by dragging mouse over roots.

13
Figure- 8: Root Locus after adding zero at -10

Figure- 7: Root Locus after adding another zero at -10

14
Figure- 9: : Compensation gain selection

Hence compensation equation is found to be:

(35)

Gain: 1.15e+04
Pole: 11.4+11i
Damping factor: 0.726
Natural Frequency(rad/s):15.8
Overshoot(%):3.62

3.4 MINIMUM COMPENSATION GAIN


Minimum compensation gain is the minimum gain at which all the root are on the left hand
side and after further decreasing it the system root goes to right hand side of complex
plane. Minimum compensation gain is found by dragging cursor over the root locus to the
point where the real axis part is zero as shown in figure-12.
Minimum compensation gain was found to be:

15
Figure- 10: Minimum Compensation Gain

Gain: 3.97e+03
Pole: 0.981i
Damping factor: -0.000737
Natural Frequency(rad/s):9.98
Overshoot(%):inf

3.5 FINDING PID PARAMETERS


In order to find parameters of PID equation we have to compare PID equation with
compensation equation find section (2.3.4).

(36)

Comparing equation (35) and (36)


Kc = 1400, Kp=10, Ki = 100, Kd = 1

16
4 SIMULINK MODEL AND
SIMULATION

4.1 FEEDBACK CONTROL SYSTEM SIMULATION:


Simulink Model of control system is shown in Figure-13. The control loops consists of PID
controllers to control the tilt angle and displacement of robot. The disturbance block is used
to add disturbance in to system in term of force.

4.2 BLOCK DESCRIPTIONS:


 PID Controller: PID controller for tilt angle control
 PID Controller1: PID controller for displacement control
 Compensation Gain Blocks: Provides compensation gains to PID controllers
 Saturation Block: To limit upper and lower levels of PID controller (here it is 40 and -40)
 System Model: State space representation of plant
 Dumux Block: Demux the output of state space block into to output (x and θ)

4.3 SIMULATION DESCIPTION:


Parameters of PID controller of Tilt angle is collected from section 3.5. The parameters of PID
controller1 are tuned using trial and error method to get least steady state time and least steady
state error.

4.4 OBSERVATION:
As shown in figure-14, a step input of one-tenth of meter is applied, the system remain
stable and bounded.
The displacement reaches 0.1 meter in about 0.1 seconds and steady state error remain less
than 1%.
The tilt angle reaches 0 degree in 0.15 seconds and the steady state error remains less than
1%.
There is no such effect of disturbance of 10N observe red on system response.
Steady State Error of displacement = 0.1%

Steady State Error of Tilt Angle = 0.15%.

17
Percentage Overshoot of displacement = 1%

Percentage Overshoot of Tilt Angle = 3%

For large value of displacement, it was observed that system gets unstable for large step
input. So we have to observe the response by giving ramp input because it varies the input
slowly. The Response is shown in figure -15. It was observed that system remain stable and
bounded for giving ramp input.

Figure- 11: Control loop of TWBR system

18
Figure- 12: System response to step input

Figure- 13: System response to ramp input

19
Steady State Error of displacement = 0.01%

Steady State Error of Tilt Angle = 0.2%.

Percentage Overshoot of displacement = 0.001%

Percentage Overshoot of Tilt Angle = 3%

20
5 CONCLUSION

Also we have concluded following points:


 System remains stable for values up to 0.1 meter of displacement step input.
 System gets unstable for large step input of displacement
 To apply large value of displacement, we must apply staircase input because it varies
linearly and slowly and robot remains stable.
 The tilt angle should remain less than 2-5% otherwise the TWBR system will become
unstable.

21
6 Bibliography

[1] Khaled M K Goher and M O Tokhi, "MODELLING, SIMULATION AND BALANCE CONTROL OF A
TWOWHEELED," Department of Automatic Control and Systems Engineering, The University of
Sheffield, Sheffield, ISBN/ISSN,.

[2] M. O. Tokhi and N. H. Siddique, K. M. Goher, "Dynamic modeling and control of a two wheeled
robotic vehicle with a virtual payload," ARPN Journal of Engineering and Applied Sciences, vol. VI,
pp. 7-8, March 2011.

[3] Wei An and Yangmin Li, "Simulation and Control of a Two-Wheeled Self-Balancing Robot,"
International Conference in Robotics and Biomimetic (ROBIO), pp. 456-458, 2013.

[4] M. O. Tokhi and N. H. Siddique K. M. Goher, "DYNAMIC MODELING AND CONTROL OF A TWO
WHEELED," ARPN Journal of Engineering and Applied Sciences, vol. VI, pp. 37-39, March 2011.

[5] Rich Chi Ooi, "Balancing a Two-Wheeled," Faculty of Engineering and Mathematical Sciences, The
University of Western Australia, 2003.

[6] Rich Chi Ooi, "Balancing a Two-Wheeled," Engineering and Mathematical Sciences, The University
of Western Australia, 2003.

[7] Andrew C. Smith, "RLTOOL Tutorial," JULY 2007. [Online].


http://www.scsolutions.com/sites/default/files/publications/FPE6e_rltool_tutorial.pdf

[8] M. O. Tokhi and N. H. Siddique K. M. Goher, "Dynamic modeling and control of a two wheeled
robotic vehicle with a virtual payload," ARPN Journal of Engineering and Applied Sciences, vol. VI,
pp. 7-9, March 2011.

[9] Araki M, "PID control," Control systems, robotics, and automation, vol. II, pp. 1-5.

22
7 APPENDIX

7.1 MATLAB CODE:


%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Variable initialization
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Mp=1.13%1.13; %Mass of body(kg)
Iw=0.000039; %Inertia of the wheel(kg*m^2)
Ip=0.0041; %Inertia of the body(kg*m^2)
l=0.07;%0.07; %Length to the body's centre of mass(m)
g=9.81; %Gravity(m/s^2)
r= 0.051 %0.051; %Radius of wheel(m)
Mw=0.03; %Mass of wheel(kg)
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Motor's variables
Km = 0.0235;%0.0235%0.006123; %Motor torque constant (Nm/A)
Ke = 0.006087%0.0069203; %Back EMF constant (Vs/rad)
R = 3; %Nominal Terminal Resistance (Ohm)
% Va = voltage applied to motors for controlling the pendulum
%%%%%%%%%%%
%precalculation to simplyfy the system matrix
%Denominator for the A and B matrices
beta = (2*Mw+(2*Iw/r^2)+Mp);
alpha = (Ip*beta + 2*Mp*l^2*(Mw + Iw/r^2));
A = [0 1 0 0;
0 (2*Km*Ke*(Mp*l*r-Ip-Mp*l^2))/(R*r^2*alpha)
(Mp^2*g*l^2)/alpha 0;
0 0 0 1;
0 (2*Km*Ke*(r*beta - Mp*l))/(R*r^2*alpha) (Mp*g*l*beta)/alpha
0]
B = [ 0;
(2*Km*(Ip + Mp*l^2 - Mp*l*r))/(R*r*alpha);
0;
(2*Km*(Mp*l-r*beta)/(R*r*alpha))]
C = [1 0 0 0;
0 0 1 0]
D = [0;
0]
%Transfer function for state space model
disp('Transfer Function of the system')
[num,den] = ss2tf(A,B,C,D)
%Obtaining impulse response of system
T = 0:0.02:10;
U = zeros(size(T));
figure(1)

U(1) = 1; %input voltage

23
plot(T,U)
title('Impulse Input to the system')
ylabel('Amplitude')
xlabel('Time[s]')
axis([-1 2 0 1.2])
figure(2)
[Y,X] = lsim(A,B,C,D,U,T);
plot(T,Y);
title('Open loop impulse response of the system')
ylabel('Position[m], Angle[rad]')
xlabel('Time[s]')
legend('Vehicle position','Tilt angle')
axis([-1 2 0 100])
%==============================================
%pole/zero plot
figure (3)

xtf = tf([0.3129 0 -43.3383],[1 0.0373 -172.1160 -5.1726 0])


Qtf = tf([0.9428 0 0],[1 0.0373 -172.1160 -5.1726 0])

s = tf('s')

pzmap(Qtf)
%rltool rootlocus plot
rltool(Qtf)

24

You might also like