Sunteți pe pagina 1din 23

ISTANBUL TECHNICAL UNIVERSITY

MECHANICAL ENGINEERING DEPARTMENT

SYSTEM DYNAMICS & CONTROL

MAK 591E
DYNAMICAL SYSTEMS MODELLING

TERM PROJECT

BALL AND BEAM


NONLINEAR SYSTEM IDENTIFICATON

Barış Öz
503101613

Prof.Dr.Can ÖZSOY

JANUARY 2012
Contents

1. Introduction ........................................................................................................................ 1
2. Dynamical Modelling of the System .................................................................................. 2
2.1. Modelling Motor Dynamics ........................................................................................ 2
2.2. Modelling System Dynamics....................................................................................... 2
2.3. State-Space Representation ......................................................................................... 4
3. Nonlinear System Identification Algorithms ..................................................................... 6
3.1. NLARX Model ............................................................................................................ 6
3.2. IDNLGREY Model ..................................................................................................... 6
4. System Identification of the Ball&Beam System .............................................................. 7
4.1. Gathering Real Output Data Values ............................................................................ 7
4.2. System Identification According To Step Input .......................................................... 9
4.2.1. NLARX Model ..................................................................................................... 9
4.2.2. IDNLGREY Model ............................................................................................ 10
4.2.3. Comparing NLARX and IDNLGREY Models .................................................. 11
4.3. System Identification According To PRBS Input ..................................................... 12
4.3.1. NLARX Model ................................................................................................... 12
4.3.2. IDNLGREY Model ............................................................................................ 13
4.3.3. Comparing NLARX and IDNLGREY Models .................................................. 14
5. Conclusion ........................................................................................................................ 15
Appendix A - ballbeamsys.m ................................................................................................... 16
Appendix B - ballbeam_ode.m................................................................................................. 19
References ................................................................................................................................ 20

i
Table Of Figures

Figure 1 - Ball And Beam Example ........................................................................................... 1

Figure 2 – Ball and Beam Modelling ......................................................................................... 3

Figure 3 – Beam Angle and Motor Position Relationship ......................................................... 4

Figure 4 – Nonlinear ARX Structure ......................................................................................... 6

Figure 5 – Ball and Beam Simulink Subsystem ......................................................................... 7

Figure 6 – Matlab Function Block Parameters ........................................................................... 7

Figure 7 – Simulink Diagram with Step Input ........................................................................... 8

Figure 8 – Simulink Diagram with PRBS Input ........................................................................ 8

Figure 9 – Gathered Info for Step Input ..................................................................................... 8

Figure 10 – Gathered Info for PRBS Input ................................................................................ 8

Figure 11 – NLARX Validation Plot for Step Input System ..................................................... 9

Figure 12 - IDNLGREY Validation Plot for Step Input System ............................................. 10

Figure 13 - NLARX and IDNLGREY Model Comparison for Step Input System ................. 11

Figure 14 - NLARX Validation Plot for PRBS Input System ................................................. 12

Figure 15 - IDNLGREY Validation Plot for PRBS Input System ........................................... 13

Figure 16 - NLARX and IDNLGREY Model Comparison for PRBS Input System .............. 14

ii
1. Introduction
The ball and beam system is widely used because that many important classical and modern
design methods can be studied based on it. The system is a steel ball rolling on the of a long
beam. One side of the beam is fixed, the other side is mounted on the output shaft of an
electric motor and so the beam can be tilted by applying an electrical control signal to the
motor amplifier. The system has a very important property that it is open-loop unstable. So
that, it is known as worth to simulate with some control algorithms.

Figure 1 - Ball And Beam Example

1
2. Dynamical Modelling of the System
Modelling of this system can be divided two parts as Modelling Motor Dynamics and
Modelling System Dynamics as follows.

2.1. Modelling Motor Dynamics


Modelling the DC servomotor can be divided into electrical and mechanical subsystems. The
electrical system is based on Kirchhoff’s Voltage Law,

̇ ̇ (2.1)

Where is input voltage, is aramture current, and are the resistance and
inductance of the armature, is back electromagnetic force constant and ̇ is angular
velocity. In order to simplify the modelling and as in most DC motor modelling methods, the
term that ̇ is neglected.

The mechanical subsystem is

̈ ̇) (2.2)
(

Where is gear ratio, is the effective moment of inertia, is viscous friction


coefficient, and is the torque produced at the motor shaft. The electrical and mechanical
subsystems are coupled to each other through an algebraic torque equation

(2.3)

Where is the torque constant of the motor. Assuming that there is no backlash or electric
deformation in the gears, the work done by the load shaft equals the work done by the motor
shaft, , where is the torque on the frame of the ball and beam system. So the DC
motor model becomes

(2.4)
̈ ( ) ̇

2.2. Modelling System Dynamics


A ball is placed on a beam where it is allowed to roll with 1 degree of freedom along the
length of the beam. A lever arm is attached to the beam at one end and a servo gear at the
other. As the servo gear turns by an angle theta, the lever changes the angle of the beam by
alpha. When the angle is changed from the horizontal position, gravity causes the ball to roll
along the beam. The whole system can be seen on Figure 2.

2
Figure 2 – Ball and Beam Modelling

For this problem, we will assume that the ball rolls without slipping and friction between the
beam and ball is negligible. The constants and variab for this example are defined is shown at
Table 1.

In the absence of friction or other Mass of the ball


disturbances, the dynamics of the ball and Radius of the ball
beam system can be obtained by Lagrangian Lever arm offset
method which is based on kinetic and Gravitational
potential energies of the system. Details Acceleration
about how to find differential equations Length of the beam
according to Lagrangian method will not be Ball’s moment of
given here. inertia
Table 1 – Model Coefficients
So, the Lagrangian equation of motion for the ball is given by the following,

(2.5)
( ) ̈ ( ̇)

Where r is the ball position coordinate, and is the beam angle coordinate. It shoulde be
taken account that beam angle and motor position is not the same, but there is also a
relationship between these variables. It can be easily seen from Figure 3 and so the
relationship equation is

(2.6)

3
Figure 3 – Beam Angle and Motor Position Relationship

With defining into (2.5) equation, equations that describes system and model dynamics can
be represented as follows.

( ) ̈ ( ) ( ̇) (2.7a)

̈ ( ) ̇ (2.7b)

2.3. State-Space Representation


With equations numbered (2.7a) and (2.7b), a state-space representation of the system can be
represented. The state variables chosen as;

̇ ̇

Some equations will be established into the equations in order to simplify outlook of the state-
space representation of the system as

So that, (2.7a) and (2.7b) equations becomes

(2.8a)
̈ ( ) ( ̇)

̈ ̇ (2.8b)

4
With selected state variables, state equations can be shown as below.

̇
̇ ( )
(2.9)
̇
̇

where,

5
3. Nonlinear System Identification Algorithms
Two system identification algorithms will be applied to ball and beam system.

3.1. NLARX Model


NLARX command is an estimating algorithm that is used for nonlinear black-box systems. Its
main syntax can be seen as below.

m = nlarx(data,[na nb nk],Nonlinearity)

where na,nb and nk are orders of the system and Nonlinearity is the algorithm choice, default
wavelet network. NLARX parameter estimation model has some user defined algorithms as
Wavelet Network, Sigmoid Network, Binary-Tree etc. In this article, Wavelet algorithm will
be used.

The Nonlinear ARX structure models dynamic systems using a parallel combination of
nonlinear and linear blocks, as shown in the following figure.

Figure 4 – Nonlinear ARX Structure

The nonlinear and linear functions are expressed in terms of variables called regressors, which
are functions of measured input-output data.

The predicted output of a nonlinear model at time t is given by the following general
equation

̂( ) ( ( ))

where ( ) represents the regressors. is a nonlinear regression command, which is


approximated by the nonlinearity estimators.

3.2. IDNLGREY Model


IDNLGREY is an object that represents the nonlinear grey-box model. Its main syntax can be
seen as below.

m = idnlgrey('filename',Order,Parameters,InitialStates,Ts)

where order is a vector with three entries [Ny Nu Nx], specifying the number of model
outputs Ny, the number of inputs Nu, and the number of states Nx, Parameters and
InitialStates are initial parameter and state values, Ts is the sampling time.

6
4. System Identification of the Ball&Beam System
4.1. Gathering Real Output Data Values
First of all, output data values of ball and beam system should be gathered from the original
system. To simulate the original system, a SIMULINK model should be created because that
the system is nonlinear and cannot be modelled in m-files.

While creating SIMULINK model, a subsystem, that contains Lagrangian Function Block of
the original system, will be modelled as the first step and named ‘Ball and Beam Model’. This
process can be seen at Figure 5 and Figure 6.

Figure 5 – Ball and Beam Simulink Subsystem

Figure 6 – Matlab Function Block Parameters

With creating another model and using the subsystem we created, SIMULINK modelling can
be completed.

While the original system is simulated with a step input, two types of inputs will be used in
this article in order to study on how consistency are system identification models under
different input types. These two models can be seen at Figure 7 and Figure 8.

7
Figure 7 – Simulink Diagram with Step Input

Figure 8 – Simulink Diagram with PRBS Input

The interface that included in ballbeamsys.m provides more simplier study on MATLAB
command window.

Iddata objects that contain , real output datas and PRBS signals that composed with idinput
command, are shown at Figure 9 and Figure 10 with respect to input types.

Figure 9 – Gathered Info for Step Input Figure 10 – Gathered Info for PRBS Input

8
4.2. System Identification According To Step Input
4.2.1. NLARX Model
As discussed at Chapter 3.1, NLARX command has a main syntax as,

m = nlarx(data,[na nb nk],Nonlinearity)

Because that system is nonlinear, it is impossible to assign na,nb and nk initially. So,in order
to define model orders, struc command, that generates model-order combinations for single-
output ARX model estimation, is embedded into getstruc command to compute and compare
loss functions. However, through selstruc command, best structure for model orders can be
found spontaneously.

Iddata object z definitely has merged into two parts that named ze for estimation process and
zv for validation process.

Estimated model has named as ‘sys’, validation plot can be seen as below.

Figure 11 – NLARX Validation Plot for Step Input System

9
4.2.2. IDNLGREY Model
There are two ways to obtain idnlgrey model. It can be done with using Nonlinear Grey-Box
Model in System Identification Toolbox in Simulink, or .m file can be used too. In this article,
.m file model has chosen.

As seen at Chapter 3.2, Idnlgrey command needs some of properties to create a model.
According to state-space equations of the system (Equation 2.9), the values have assigned,

Order = [1 1 4]; % Model orders [ny nu nx].

Parameters = [p_1;p_2;p_3;p_4]; % Initial parameter vector.

InitialStates = [0;0;0;0]; % Initial initial states.

In order to compute parameter estimation, model properties have to be set fixed.

nlgr.Parameters(1).Fixed = true;

nlgr.Parameters(2).Fixed = true;

nlgr.Parameters(3).Fixed = true;

nlgr.Parameters(4).Fixed = true;

Idnlgrey model uses state-space equations, so that an ode-file should be assigned. Created
ode-file has given at Appendix B.

In order to obtain better estimation, maximum iteration, tolerance and absolute and relative
error tolerances have set different values from their defaults.

After these adjustments, idnlgrey model has simulated with pem algorithm.

Figure 12 - IDNLGREY Validation Plot for Step Input System

10
Also, parameter estimation can be compared with real parameters using the command

ptrue = [p_1;p_2;p_3;p_4];

fprintf(' %1.4f %1.4f\n', [ptrue'; getpvec(nlgr2)']);

Its results are as follows,

7.0000 7.0072

0.0006 0.0057

-50.0190 -50.0180

8.5034 8.5093

4.2.3. Comparing NLARX and IDNLGREY Models


Finally, a comparison has been done between estimated models. Comparison plot has shown
at Figure 13.

Figure 13 - NLARX and IDNLGREY Model Comparison for Step Input System

Even though, IDNLGREY model has estimated parameters not so bad, and it is expected that
it performs better than NLARX model, validation graph shows that NLARX model has
performed better than IDNLGREY model for this simulation.

11
4.3. System Identification According To PRBS Input
Because that, at every simulation, PRBS input has randomed at different values, simulation
graphs may change.

4.3.1. NLARX Model


All process will be repeated for PRBS input.

Figure 14 - NLARX Validation Plot for PRBS Input System

12
4.3.2. IDNLGREY Model
Parameter Estimation

7.0000 11.2684

0.0006 0.0036

-50.0190 -9.4894

8.5034 0.7059

Validation Plot

Figure 15 - IDNLGREY Validation Plot for PRBS Input System

13
4.3.3. Comparing NLARX and IDNLGREY Models

Figure 16 - NLARX and IDNLGREY Model Comparison for PRBS Input System

14
5. Conclusion
NLARX Model gives a perfect fit for nonlinear models, however IDNLGREY Model is
expected to perform better, it could not be reached that. It should be tried onto different
systems to check if it estimates better or worse than NLARX command or there are any
mistakes while modelling the system.

Anyway, system identification has performed well especially for step input system with a fit
value that %99.83. This model can be usable for further control studies.

15
Appendix A - ballbeamsys.m
clear,clc

%Model Coefficients

J = 9.99e-6;

d = 0.03;

L = 1.0;

g = -9.8;

R = 0.015;

m = 0.111;

p_1=-(m*g*(R^2))/(J+m*(R^2));

p_2=(m*(d^2)*(R^2))/(J*(L^2)+m*(L^2)*(R^2));

p_3=-50.019;

p_4=8.5034;

% Creating PRBS Input

u=idinput(400,'rbs');

t=1:1:400;

up=[transpose(t) u];

%User Interface

fprintf('%s\n %s\n %s\n %s\n %s\n',...

'Select the input type of the original system ',...

'Enter 1 for Step Input.',...

'Enter 2 for PRBS Input.',...

'Enter 0 to Quit.',...

'--------------------------------------------------')

while true

Type = input('Input Type: ');

if (Type==1) || (Type==2) || (Type==0)

16
break;

else

disp('Invalid selection for demo type.')

disp('Enter 1 for Step Input, 2 for PRBS Input (0 to Quit).')

disp(' ')

end

end

fprintf('Please Wait...\n')

% Simulation of the Simulink Model

switch Type

case 1

sim('ballbeamstep');

case 2

sim('ballbeamprbs');

otherwise

disp('Quitted From Ball&Beam Model System Identification')

return;

end

z=iddata(yr,u,1);

figure

plot(z)

ze = z(1:200); % Estimation Data

zv = z(201:400); %Validation Data

NN = struc(1:10,1:10,1:10); %\

V = arxstruc(ze,zv,NN); % | -> Model Order Estimation

nn = selstruc(V,0); %/

17
% NLARX Model

sys = nlarx(ze,nn,'wavenet');

figure

compare(zv,sys)

% IDNLGREY Model

Order = [1 1 4]; % Model orders [ny nu nx].

Parameters = [p_1;p_2;p_3;p_4]; % Initial parameter vector.

InitialStates = [0;0;0;0]; % Initial initial states.

nlgr.Parameters(1).Fixed = true;

nlgr.Parameters(2).Fixed = true;

nlgr.Parameters(3).Fixed = true;

nlgr.Parameters(4).Fixed = true;

nlgr = idnlgrey('ballbeam_ode', Order, Parameters,InitialStates,0);

nlgr.Algorithm.MaxIter=50;

nlgr.Algorithm.Tolerance=0.0001;

nlgr.Algorithm.SimulationOptions.AbsTol = 1e-8;

nlgr.Algorithm.SimulationOptions.RelTol = 1e-7;

nlgr2= pem(ze,nlgr, 'Display', 'Full');

ptrue = [p_1;p_2;p_3;p_4];

fprintf(' %1.4f %1.4f\n', [ptrue'; getpvec(nlgr2)']);

figure

compare(zv,nlgr2)

figure

compare(zv,sys,nlgr2)

18
Appendix B - ballbeam_ode.m
function [dx, y] = ballbeam_ode(t, x,u, p1,p2,p3,p4, varargin)

% Output equation.

d = 0.03;

L = 1.0;

y = x(1);

% State equations.

dx = [x(2);

p1*(sin((d/L)*x(3)))+p2*((x(4))^2)*x(1);

x(4);

p3*x(4)+p4*u(1)];

19
References
[1] Ball and Beam – Experiment and Solution, Quanser Consulting, 1991.
[2] Ball and Beam Modelling, Carnegie Mellon University Libraries [Online]
http://www.library.cmu.edu/ctms/ctms/examples/ball/ball.htm
[3] Franz-Josef Elmer, Basic Terms Of Nonlinear Dynamics. [Online]
http://www.elmer.unibas.ch/pendulum/bterm.htm
[4] Henry B., Lovell N., Camacho F., Nonlinear Dynamics Time Series Analysis.
[5] Verdult V., Nonlinear System Identification: A State-Space Approach, Ph.D.Thesis,
University Of Twente, 2002.
[6] Cazzolato B.Dr., Derivation of the Dynamics of the Ball and Beam System, September
2007.
[7] Rugh, W.J., Nonlinear System Theory,The Johns Hopkins University Press, 1981.
(ISBN 0-8018-2549-0)
[8] Ljung L., System Identification: Theory for the User, Prentice Hall Ptr, ISBN 0-13-
656695-2,1999.
[9] Matlab Product Help, [MATLAB]

20

S-ar putea să vă placă și