Simulation of Inverted Pendulum Using Neural Networks For Identification

You might also like

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

SIMULATION OF INVERTED PENDULUM USING NEURAL

NETWORKS FOR IDENTIFICATION

Mohandas K P and Suresh Paritala


Department of Electrical Engineering
National Institute of Technology Calicut
India PIN 673601
(email:kpmdas@yahoo.com)

ABSTRACT ^ ^
y − y = P(u ) − P (u ) ≤ ε, u ε U ..(2)
Inverted pendulums are highly nonlinear devices For identification of complex nonlinear systems
with strong tendencies to be unstable. Artificial series-parallel model is the best [1], which is shown
neural networks being capable of describing
in Fig 2. Here Tapped Delay Lines (TDL) are used to
nonlinear phenomena can be used to simulate such
systems. Using SIMULINK model, an inverted feed the delayed samples of the input and out of the
pendulum dynamics are simulated using resilient plant to the neural network for modeling purpose.[4]
back propagation neural networks. The results
show good match between predicted and actual 2. MATHEMATICAL MODELING OF
outputs.
INVERTED PENDULUM
1.INTRODUCTION An inverted pendulum mounted on a motor-driven
cart is shown in Fig 3. This is a model of the attitude
The ability of neural networks to control of a space booster on takeoff (The objective
approximate large classes of nonlinear functions Of the attitude control problem is to keep the space
make them prime candidates for use in dynamic booster in a vertical position). Also a metaphor of
models for the representation of nonlinear plants. The inverted pendulum is often used to explain the
fact that static and dynamic back-propagation principle of legged motion of a robot, since it is
methods can be used for the adjustment of parameters unstable in nature and controls its motion indirectly
also makes them attractive in identification and using the external force generated as reaction forces.
control. Discrete-time systems which can be The inverted pendulum is unstable in that it may fall
represented by difference equations can be described over any time in any direction unless a suitable
by: control force is applied. Here we consider a one-
x(k + 1) = φ( x(k ), u(k )) dimensional problem that the pendulum moves only
…(1) in one direction that is either to the left or right of the
y (k ) = ψ (x(k ), u(k ))
equilibrium point.
Identification: When the functions Φ and ψ in (1)
are unknown, the problem of identification of the The dynamical equations for the inverted pendulum
unknown system (referred to as the plant) arises. This system will be derived using “Lagrange Equations “.
can be formally stated as follows: The Lagrange equations use kinetic and potential
The input and output of a time-invariant, causal energies of the system to determine the dynamical
discrete-time dynamical plant are u (.) and y (.) equations of the inverted system. Fig .4 shows the
respectively, where u (.) is a uniformly bounded free body diagram of the inverted pendulum system.
function of time. The plant is assumed to be stable
with a known structure but with unknown values of The kinetic energy (KE) of the system is the sum of
the parameters. The objective is to construct a the K.E of each of the masses. The KE, T1 of the cart
suitable identification model (Fig.1) which when is,
subjected to the same input u (k) as the plant, 1
T1 = M y 2 …. (3)
produces an output ŷ (k) which approximates y (k) in 2
the sense described by The pole can move in both the horizontal and vertical
directions, so the pole KE is T2 given as

621
T2 =
1
2
(
M y 22 + z 22 ) …(4)
equations for the inverted pendulum system,
which are
From the fig.4,
y 2 = y + l sin θ …(5) (M + m )y + ml cos θ θ − ml sin θ θ 2 = f
⇒ y = y + lθ cos θ …. (6) …(19)
2
And
z 2 = l cos θ …(7)
ml cos θ y + ml 2 θ − mgl sin θ = 0 . …(20)
⇒ z 2 = − lθ sin θ …(8)
The total K.E of the system is, The mathematical model of the inverted
1
[
T = T1 + T2 = M y 2 + m y 22 + z 22
2
( )] pendulum has thus been developed. Using the
eqns (.19) & (20) a non-linear model for the
…(9) inverted pendulum is constructed in MATLAB.
Substituting the eqns (6) & (8) in (9) The non-linear mathematical model of the
inverted pendulum is shown in Fig 5
⇒T=
1
2 


( ) (
2
M y 2 + m  y + lθ cosθ + − lθ sin θ )2 

In the Fig.5 f1 (u) and f2 (u) are:
=
1
2
1
[
M y 2 + m y 2 + l 2θ 2 cos 2 θ + 2 yθ l cosθ + l 2θ2 sin 2 θ
2
] f1(u)=(g*u(2)+u(3)*((-u(1)-
1
2
1
[
⇒ T = M y 2 + m y 2 + l 2 θ 2 + 2 yθ l cos θ (10)
2
] m*l*u(4)*u(4)*u(2))/(M+m)))/(l*(4/3-
(m*u(3)*u(3))/(M+m)))
Now, the potential energy of the system is stored in
the pendulum and is f2(u)= (u(1)+m*l*(u(4)*u(4)*u(2)-
u(5)*u(3)))/(M+m)
V = mgz 2 = mgl cos θ (11)

Now, the Lagrangian function is, 3. STABILIZATION OF INVERTED


1 PENDULUM USING FEEDBACK
L = T − V = (M + m ) y 2 + mlyθ cos θ LINEARISATION
2
…(12)
1 2 2 The angle of the pendulum in open loop
+ ml θ − mgl cos θ
2 configuration goes unstable and falls over. One
The state space variables of the system are y and θ, so of the requirements in system identification is
the Lagrange equations are: the collection of ‘information rich’ input/output
d  ∂L  ∂L data. The open loop response of the inverted
 − = f ..(13) pendulum, pendulum angle does not give us
dt  ∂y  ∂y
enough information on the pendulum system.
The pendulum falls over too quickly. In order to
d  ∂L  ∂L adequately model the inverted pendulum it is
− =0 ...(14)
dt  ∂θ  ∂θ necessary to stabilize it using a feedback
∂L controller. Using a feedback controller, the
But = 0. …(15) output data will contain more information
∂y describing the process [2].

∂L Developing a controller for the non-linear


= ml sin θ − mlyθ sin θ . ..(16)
∂θ pendulum is more difficult. Linear control
techniques such as the PID, full-state feedback
∂L were tested but had no success in controlling the
= (M + m ) y + mlθ cos θ …(17) non-linear pendulum [3]. A feedback
∂y
linearisation controller was developed to control
the non-linear pendulum system. Feedback
∂L linearisation cancels the non-linearities in the
= ml cos θ y + ml 2θ …(18)
∂θ pendulum system so that the closed loop system
Substituting the eqns from (15) to (18) in (13) & is more linear.
(14), we obtain the non-linear dynamical

622
The following equations give a control law 5. MODEL VALIDATION USING THE
developed for the inverted pendulum controller. TRAINED NETWORK
The first four equations (Eq. 21- 24) are entered
into the main equation. The main equation (Eq. The trained network model of SIMULINK
25) calculates the required force, U to keep the version is generated using the command
pendulum stable. ‘gensim’ (net,-1). This NN model used in
3 parallel with inverted pendulum model and
h1 = g sin θ … (21) compared the responses of both models with
4l
3 different seeded band limited white noise. The
h2 = cos θ … (22) results show excellent match between the actual
4l
and predicted outputs.
 •2 3 
f1 = m l sin θ θ − g sin 2θ  … (23)
 8  6. CONCLUSIONS
 3 
f2 = M + m 1 − cos 2 θ  … (24)
 4  Neural networks were utilized to model the
nonlinear pendulum. Prior to identification of the
nonlinear pendulum, the process is stabilized
f2 • 
u=  h1 + k1 (θ − θ d ) + k 2 θ + c1 ( y − y d ) + c 2 y •  − f 1 using feedback control. The feedback control
h2   removes some of the nonlinearities of the process
…(25) so detuned controllers were used which allows
the process to exhibit more of its dynamics. This
For the simulations M, m, l, g are set to the improves results in better quality of the data used
values of the pendulum model. The following in the system identification. Different sizes of
numeric values are used: M = 0.5 Kg, m = 0.2 static feed forward networks were trained using
Kg, l = 0.3 m, g = 9.81 m/s, k1 = 25, k2 = 10, C1 the input/output data from the nonlinear
= 1, C2 = 2.6. Also yd = 0 meters and θd = 0 rad, pendulum. The feed forward (FF) networks were
which are the desired position of the cart and generated in SIMULINK for testing. The feed
angle of the pendulum respectively. forward networks show similar dynamics to the
The inputs to this controller are the 4 output pendulum model and a low mean square error
states of the non-linear pendulum model. The (MSE).
control law calculates the correct magnitude and
force to keep the pendulum stable. 7. REFERENCES
[1]. K .S.Narendra and K Parthasarathy,"
4. IDENTIFICATION OF INVERTED Identification and control of Dynamical systems
PENDULUM WITH FEED-FORWARD using neural networks " IEEE Transactions On
NEURAL NETWORK Neural Networks, Vol.1, No.1, March1990,
pp.4-27.
A neural network is developed, which models
the 1 input and 4 output states. The diagram [2] Ljung, L: System Identification-Theory for
below shows the nonlinear pendulum with the user, Prentice Hall (1987)
control law. (Fig.6) In this example feed-forward
networks will be utilized to model the multi- [3] Marvin Bugeja,” Non-Linear Swing-Up and
output system. Stabilizing Control of an Inverted
Pendulum System” EUROCON 2003 Ljubljana,
For developing the NN Model of inverted Slovenia
pendulum, feed forward network with 3 layers is
selected. The number of neurons in the input [4]Partial Recurrent Neural Networks for
layer, hidden layer and output layer are 15,5and Identification & Control of Non-linear System,
4 respectively. The type training used is Resilient IASTED . International conference on control
Back propagation (trainrp). and applications, Honolulu, USA, Aug
1998,pp65-68

623
Fig 1 Identification
Fig.2 Identification of nonlinear plants using
neural networks

Fig .3: Inverted Pendulum System


Fig.4.Freebodydiagramoftheinvertedpendulum

Fig 5 SIMULINK Non-linear model of inverted pendulum

624
Fig 6 SIMULINK model of the nonlinear control law

Fig 7 SIMULINK diagram of nonlinear pendulum/controller used for collecting

625
Fig .8 Error variation while training

Fig 9(a) Pendulum angle (rad)

Fig 9(b) Angular velocity of pendulum Fig 9(c) Variation of cart position (m)

Fig.9 (d) Variation of cart velocity (m/s)

626
Fig.10: SIMULINK diagram of identified neural network model with the actual model

Fig 11(c) Actual output cart position and neural


network predicted cart position
Fig 11(a) Actual output angle and neural network
predicted output angle (rad)

Fig 11(d) Actual output cart velocity neural


Fig 11(b) Actual output angular velocity and network predicted output cart velocity
neural network predicted output angular
velocity

627

You might also like