Ball and Beam Nonlinear System Identification
Ball and Beam Nonlinear System Identification
Ball and Beam Nonlinear System Identification
TERM PROJECT
Bar z 503101613
Prof.Dr.Can ZSOY
JANUARY 2012
Contents
1. 2. Introduction ........................................................................................................................ 1 Dynamical Modelling of the System .................................................................................. 2 2.1. 2.2. 2.3. 3. Modelling Motor Dynamics ........................................................................................ 2 Modelling System Dynamics....................................................................................... 2 State-Space Representation ......................................................................................... 4
Nonlinear System Identification Algorithms ..................................................................... 6 3.1. 3.2. NLARX Model ............................................................................................................ 6 IDNLGREY Model ..................................................................................................... 6
4.
System Identification of the Ball&Beam System .............................................................. 7 4.1. 4.2. Gathering Real Output Data Values ............................................................................ 7 System Identification According To Step Input .......................................................... 9 NLARX Model ..................................................................................................... 9 IDNLGREY Model ............................................................................................ 10 Comparing NLARX and IDNLGREY Models .................................................. 11
System Identification According To PRBS Input ..................................................... 12 NLARX Model ................................................................................................... 12 IDNLGREY Model ............................................................................................ 13 Comparing NLARX and IDNLGREY Models .................................................. 14
Conclusion ........................................................................................................................ 15
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.
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 is neglected. term that 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)
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 disturbances, the dynamics of the ball and beam system can be obtained by Lagrangian method which is based on kinetic and potential energies of the system. Details about how to find differential equations according to Lagrangian method will not be given here. Mass of the ball Radius of the ball Lever arm offset Gravitational Acceleration Length of the beam Balls moment of 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)
With defining into (2.5) equation, equations that describes system and model dynamics can be represented as follows. ( ) ( ( ) ) ( ) (2.7a)
(2.7b)
Some equations will be established into the equations in order to simplify outlook of the statespace representation of the system as
With selected state variables, state equations can be shown as below. where, ( ) (2.9)
The nonlinear and linear functions are expressed in terms of variables called regressors, which are functions of measured input-output data. The predicted output equation ( ) ( ( )) of a nonlinear model at time t is given by the following general
where ( ) represents the regressors. is a nonlinear regression command, which is approximated by the nonlinearity estimators.
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.
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.
InitialStates = [0;0;0;0];
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.
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)']);
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
12
Validation Plot
13
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); nn = selstruc(V,0); %\ % | -> Model Order Estimation %/ 17
% NLARX Model sys = nlarx(ze,nn,'wavenet'); figure compare(zv,sys) % IDNLGREY Model Order Parameters = [1 1 4]; % Model orders [ny nu nx].
InitialStates = [0;0;0;0]; 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 figure compare(zv,nlgr2) figure compare(zv,sys,nlgr2) %1.4f\n', [ptrue'; getpvec(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-13656695-2,1999. [9] Matlab Product Help, [MATLAB]
20