Professional Documents
Culture Documents
Final Thesis Paper Auto
Final Thesis Paper Auto
Final Thesis Paper Auto
ACKNOWLEDGEMENT
2
ABSTRACT
In this thesis, a control system design to stabilize the ball and beam system,
which is a non-linear system, is observed. The main purpose of this project is to
control the ball at a desired position on the beam by using a suitable controller, either
by PID or LQR controller. First, a mathematical model for the ball and beam system
is developed, and then, based on that model, an effective controller for the system is
designed. The system consists of a ball and beam mechanism, a dc servo motor and a
dc motor with gearbox, a position sensitive detector (PSD) sensor and an Arduino
controller. The open-loop unstable system is stabilized by feeding back the actual
position of the ball, measured from position sensor, into the controller which
compares the actual position with the desired position set by the user, and outputs a
control voltage signal to the dc servo motor based on the programmed control
algorithm. The torque generated by the motor drives the beam, and the rotation of the
beam changes the ball position until it reaches the desired set point value. The control
methods used are Proportional-Integral-Derivative (PID) control and Linear Quadratic
Regulator (LQR) control. The control design for the controller is implemented as
much as possible to minimize the error, that is, the difference between the desired
position and the actual position of the ball on the beam. In this project, a graphical
user interface (GUI) is also provided to allow the user to open the Simulink model in
order to start and stop the system as well as to set the desired ball position and plot the
experimental results through that GUI platform. The software used to develop
programs, block diagrams and graphical user interface is Matlab/Simulink with
Arduino I/O interface.
iii
TABLE OF CONTENT
Title Page
ACKNOWLEDGEMENT..........................................................................................i
ABSTRACT...............................................................................................................ii
LIST OF FIGURES..................................................................................................vi
LIST OF TABLES..................................................................................................viii
CHAPTER 1...................................................................................................................1
INTRODUCTION......................................................................................................1
CHAPTER 2...................................................................................................................6
BACKGROUND RESEARCH..................................................................................6
2.4.1 UI Layout................................................................................................16
2.4.2 UI Programming......................................................................................16
2.4.3 Graphical User Interface for Ball and Beam Control System.................17
2.5 Summary........................................................................................................17
CHAPTER 3.................................................................................................................18
CHAPTER 4.................................................................................................................36
CHAPTER 5.................................................................................................................54
5.1 Discussion......................................................................................................54
v
5.2 Conclusion......................................................................................................55
5.3 Future Work...................................................................................................56
REFERENCES.........................................................................................................57
APPENDICES..........................................................................................................60
APPENDIX A..........................................................................................................61
APPENDIX B..........................................................................................................65
APPENCIX C...........................................................................................................67
APPENDIX D..........................................................................................................72
vi
LIST OF FIGURES
Figure Page
Figure 4.12. Block Diagram for Single Set Point PID Control Experiment...............45
Figure 4.13. Single Set Point PID Control Experimental Result.................................45
Figure 4.14. Two Set Points PID Control Experimental Result..................................46
Figure 4.15. Circuit Diagram for LQR Control Experiment........................................47
Figure 4.16. Block Diagram for LQR Control Experiment.........................................47
Figure 4.17. LQR Control Experimental Results.........................................................48
Figure 4.18. Root Locus of Closed Loop System........................................................49
Figure 4.19. Nyquist Plot of Closed Loop System.......................................................50
Figure 4.20. Bode Diagram of Closed Loop System...................................................50
Figure 4.21. Graphical User Interface for Ball and Beam Control System.................51
Figure 4.22. Initialization Time before Control Process in PID Control.....................52
Figure 4.23. Deviation of Output Response in PID Control Experiment....................53
Figure 4.24. Deviation of Output Response in LQR Control Experiment...................53
Figure B.1. HG Servo Sub-system...............................................................................65
Figure B.2. RC Servo Sub-system...............................................................................65
Figure B.3. Ball Position Detection Block Diagram....................................................66
Figure B.4. Block Diagram for I-PD+FF Controller....................................................66
viii
LIST OF TABLES
Table Page
CHAPTER 1
INTRODUCTION
studying nowadays by many researchers because it is really a very useful theory for
control system approach.
3
Some ball and beam control systems use only the ball position as the feedback
signal and the motor control voltage is derived based on that information. In such
system, only the ball position is controlled. This type of control system is used in PID
control of this experiment. Some systems take information from both ball position
sensor and the motor angular position sensor. In such systems, both the ball position
and the motor angular position are controlled. LQR control system of this experiment
used this type of control system. The block diagrams for both PID and LQR control
systems are shown in Figure 1 .1 and Figure 1 .2.
In the ball and beam control system in this experiment, a ball and beam
mechanism made of Tayami tool kit, a position detective infrared sensor, an Arduino
controller, an RC servo motor and a dc motor with high power gearbox is used. Two
types of control methods, proportional integral derivative (PID) control and linear
quadratic regulator (LQR) control, are observed. PID control is in the form of
proportional derivative type PID controller with feed-forward term called I-PD+FF
controller. LQR control is implemented by inserting a scale factor to eliminate steady-
state error. RC servo is used in PID control experiment while high power gearbox dc
motor is used for LQR control experiment. In LQR control, both ball position and
motor angular position are controlled but in PID control, only the ball position is
controlled since built-in position control circuit inside RC servo provide angular
position control of the motor. The software used to develop programs and block
diagrams as well as to create graphical user interface is Matlab/Simulink linked with
Arduino I/O interface library.
4
control experiment even without understanding the program codes and Simulink
diagrams.
Figure 1.3. Graphic User Interface for Ball and Beam Control System
1.4 Implementation
First, mathematical modeling of the system, including calculation of transfer
function and state equations, is done. Then, mechanical and electronic components to
create ball and beam experimental setup are assembled. To control the ball at desired
position, the ball position feedback information from the position detective sensor is
important to be exact so that the control input can be correctly determined by the
controller. To achieve this fact, the sensor calibration is carefully carried out to obtain
exact position information. After that, the position of the ball is measured to test the
exactness of the position sensor. Also, motor parameters, namely gain K and time
constant T, which are to be used in LQR control experiment, are determined by step
response method. After all the preparation required for the experiment is done, Matlab
programs and Simulink block diagrams for PID and LQR control methods are
developed and the experiment is carried out. Frequency response plot of the system is
also observed. Moreover, the components are selected and associated callback
functions are defined to create a desired GUI window. Finally, PID and LQR control
experiment are carried out through created graphical user interface.
CHAPTER 2
BACKGROUND RESEARCH
(a) (b)
(c) (d)
Figure 2.4. Ball and Beam Systems: (a) Hirsch’s System (1999), (b) Lieberman’s
System (2004), (c) Arroyo’s System (2005), (d) Quanser’s System (2006)
In the first configuration, the beam rotates through its central axis, and since
the motor is directly attached to it, the motor output shaft angle and the beam angle
can be considered to have the same value. So, the mathematical model of this type of
system is simple because the ratio between beam angle and motor angle is not taken
into account while calculating transfer function of the system. This type of
configuration is the one used in the systems of Hirsch (1999), Lieberman (2004) and
Arroyo (2005).
The second configuration is the one used in ball and beam system of Quanser
(2006) called ‘Ball and Beam Module’. In this type, the beam rotates through the
pivot point located at one end of the beam, being driven by the motor attached at the
other end. This can be said to have a more complex system configuration because the
ratio between beam angle and motor angle is required to consider for modeling the
system and calculating its transfer function, based on the point at which the lever arm
is attached to the beam.
The two basic configurations for ball and beam system are shown in Figure 2
.6, in which the first configuration shows the beam supported at center and the second
configuration represents the beam supported at each end of the beam.
11
(a) (b)
Figure 2.6. Two Basic Configurations for Ball and Beam System Model: (a) Beam
Supported at Center (b) Beam Supported at Both Ends
PID controller, PI-D controller and I-PD controller have the same disturbance
effect but the target value response characteristics are different. In PID control, the
difference between target value and actual output value is multiply by proportional,
integral and differential elements, the sum of which becomes the control input to the
controlled object. Therefore, the deviation changes in the same manner as the target
value. When the target value changes in a step-like manner, the deviation also
changes with the step-like manner, and since the slope of the step is infinite, the
differentiator will generate very large impulse-like signal. This can pose a sudden
load to the actuator, and can cause residual vibration by exciting the resonance
characteristics of the controlled object. To avoid these problems, the PI-D controller
and the I-PD controller, which are typed as Two-Degree-of-Freedom control system.
13
In PI-D control, the input to the differential term is only the actual output, and
not the difference between target value and actual output as in the case of PID control.
Therefore, when a step input is applied as target value, there is no differentiation for
the step input which can avoid impulse-like control input. However, the deviation of
the actual value from the target value is fed to the proportional and integral element,
so when the target value is changed in a stepwise manner, the control input also
changes with a stepwise manner. Therefore, it is necessary to eliminate step-like
change of the control input. This problem can be solved a method in which only the
integrator acting on the deviation between the actual output and the target input. This
type of controller is called I-PD controller as shown in Figure 2 .10.
(2.1)
(2.2)
In equation ( 2 .1) and ( 2 .2), each term, other than the sum of all terms,
separately represents proportional, integral and derivative parts of the controller.
Therefore tuning of PID gains can be performed for all types of PID controllers
whether they are in the form of P control, PD control, PI control, PID control or PI-D
and I-PD control.
Among different PID tuning methods, manual tuning, limit sensitivity method
and pole assignment methods are studied and the most suitable method for the system
is selected. In manual tuning method, PID gains are determined by trial-and-error with
minimal analytic analysis using step responses obtained by simulation or by actual
testing on the system. The values of PID gains are adjusted and decided based on their
characteristics to obtain a system with desired specifications. The effects of PID gains
on the system output response is described in Table 2 .1.
15
PID Gain Rise Time Settling Time Percent Overshoot Steady State Error
Decrease Small Change Increase Decrease
In limit sensitivity method, ultimate gain (KC) and ultimate period (TC) are first
determined from the system response under defined condition, and then, PID gains are
calculated by the defined equations as described in . This method is the same as the
closed loop concept of Ziegler-Nichols PID tuning.
The following steps described how to perform the limit sensitivity method:
Gain KP is increased until the output is in sustained vibration. This gain on the
border of instability is defined as ultimate gain, KC
The period of sustained vibration, termed as TC, is taken from system response
Calculate the gain values using the defined equations
Apply some fine-tuning so that output response can be in desired conditions
P control - -
PI control -
PID control
In pole assignment method, PID gains are designed to achieve the desired
properties which will make the closed-loop poles in a desired stable region. This is
16
why this process is known as pole assignment method. PID gains are calculated by
equating the roots of closed loop control system to the desired poles. Therefore,
unlike manual tuning and limit sensitivity methods, this method uses not only the
transfer function of the controller but it also uses the transfer function of the
controlled object to calculate the required PID gains.
The advantages of pole assignment method over manual tuning and limit
sensitivity method is that the PID gains can directly obtained from the transfer
function of the closed loop system. There is no need to take data from the system
response, as in the case of limit sensitivity method, which can include some error
according to inexact reading of data. Also, the time required to tune PID gains is
reduced since it is not required to repeat the control process in order to determine the
gains based on the system response, as in the case of manual tuning method.
Moreover, no adjustment is required to carry out manually. Since the gain values are
calculated based on the desired poles, the system response can be obtained with the
desired characteristics. Hence, pole assignment method is considered to be the best
tuning method among the three methods that have been studied. Therefore, in this ball
and beam control system, pole assignment method is selected to tune the PID gains.
PC = [B AB A2 B … An-1B] (2.3)
(2.4)
In this equation, Q and R represent the weighting matrices where Q is the state
weighting matrix and R is the control weighting matrix. To design LQR controller, it
is important to choose the values of Q and R. Since R is a control weighting matrix, if
control input u is a scalar, R becomes a scalar. In this system, the control input is the
(2.5)
18
(2.6)
(2.7)
(2.8)
UI layout
UI programming
2.4.1 UI Layout
User interface layout provides a set of tools for creating the user interface. By
using the layout editor, GUI can be easily created by clicking and dragging
components such as the buttons, sliders, pop up menu, static text and edit text, etc. By
saving the created UI layout, Matlab produces two files, namely, .fig file, which is a
19
figure of created GUI window, and .m file, in which callbacks functions associated to
the used components are to be programmed.
2.4.2 UI Programming
User interface programming includes a program file containing callback
functions that control how UIs behave. m.file for UI programming is automatically
created upon saving the UI layout. It contains callback functions for each component
used in UI layout. Only the programmers have to do is to write codes in callback
functions which can make the program act in the desired way.
2.4.3 Graphical User Interface for Ball and Beam Control System
The GUI used in this ball and beam control system includes a ball and beam
model to display the ball and beam system configuration which uses “patch”
command to create each ball and beam component. A description box is provided to
instruct the users how to use the GUI control panel in terms of static text components.
A ball position slider together with a Set Position and Reset buttons are created to
select and set/reset the ball position into the Simulink block diagram. To do this
function the value from slider is taken by “get” command and is set into the Simulink
blocks by “set_param” command. It also contains a radio button panel to select
experiment method and Open Simulink button to open Simulink model of the selected
method. The selected method is checked by using “switch/case” command and the
associated Simulink block is opened by “open_system” command. But, GUI only
opens the Simulink block diagram and start/stop function is done in the Simulink
model. It also contains an axis together with Plot Output and Clear Axes buttons to
plot the output response and clear it. Here, the data are first logged into the
workspace from the scope of the Simulink block, then, is imported to GUI by
“evalin” (evaluate expression in work space) command and is plotted and clears
simply by “plot” and “cla” commands.
2.5 Summary
In this chapter, first, a brief history of ball and beam control system is
described. The two basic configurations of ball and beam control system are
explained and a configuration which is used in this thesis is discussed. Then, PID and
20
LQR control methods for the ball and beam control system is considered. This
includes types of PID controller, PID tuning method as well as LQR gain and
weighting matrices. PID and LQR control methods are explained with associated
equations to find the gain values for both PID and LQR control. Also, a brief
explanation about graphical user interface (GUI) is expressed together with how GUI
is created for this ball and beam control system.
21
CHAPTER 3
DESIGN AND CALCULATION
V a (t )
(3.9)
(3.10)
23
= Resistance
= Inductance
= Armature Current
Vb(s) = Back electromotive force
11
(3. )
(3.12)
(3.13)
(3.14)
(3.15)
(3.16)
(3.17)
(3.18)
(3.19)
(3.20)
This is the motor transfer function, where K is the gain and T is the time
constant of the dc motor. The values of K and T are to be calculated by step response
method in experiment section of next chapter.
Figure 3.14. Free Body Diagram for Forces Acting on the Ball
The force summation equation for the forces acting in the inclined x-direction
is:
(3.21)
(3.22)
(3.23)
27
(3.24)
(3.25)
For the small beam angle, using the small angle approximation, , then
(3.26)
(3.27)
Let (3.28)
Then, the transfer function of the ball and beam system can be written as:
(3.29)
28
In this ball and beam control system, a hollow steel ball is used. Therefore,
equation (for hollow ball) ( 3 .31) is selected. Also, the beam
length is 42 cm and the ball does not move more than a few tens of centimeters, so the
unit of position is set to ‘cm’. Therefore, to match with the unit of ‘cm’, the value of
Kb is to be multiplied by 100 which is conversion from meter to centimeter. Then, the
value of Kb becomes (3/5) (100g).
(3.32)
In ball and beam control system, the value of Kθ is used to calculate the
required motor angle which makes the ball position to be at the desired set point. To
get the motor angle, the beam angle, which is determined by the controller, is multiply
by 1/Kθ.
(3.33)
(3.34)
(3.35)
(3.36)
Taking the ratio between beam angle and motor angle from equation
( 3 .32),
(3.37)
(3.38)
(ball position)
(ball speed)
31
(3.39)
(3.40)
(3.41)
(3.42)
Let the input ‘u’ be the input voltage to the motor ‘va’ and the output ‘y’ be the
ball position ‘x1’. Then, the state equation of the system is:
(3.43)
(3.44)
(3.45)
(3.46)
(3.47)
(3.48)
, , ,
For I-PD+FF controller used in this ball and beam control system, the PID
gains and the feed-forward gain are tuned by using pole assignment method. First, the
block diagram for the closed loop control system is considered. Then, the closed loop
transfer function is calculated and the roots of closed loop system are equated with the
desired poles to obtain the system response with desired characteristics. This can also
be done by comparing the characteristic equations of the closed loop control system
and the desired poles. The detail calculation of the gain values using pole assignment
method is explained below.
From equation ( 3 .29 ), the transfer function
of the ball and beam system is . Therefore, the block diagram of the closed loop
control system using I-PD+FF controller becomes as shown in Figure 3 .16.
From Figure 3 .16, the closed loop transfer function of the system is:
(3.49)
(3.50)
Let the poles be p1, p2, p3 with damping ratio ( ) and natural frequency ( ).
(3.51)
(3.52)
(3.53)
(3.54)
(3.55)
(3.56)
(3.57)
(3.58)
34
the value of so that the slow pole is eliminated from the system.
(3.59)
Now, all the gain values , , and are obtained. The values of
In this ball and beam control system with PID control method, the values of
and are selected as 0.6 and 1.5 respectively. These values are mostly used in
control systems because they can provide good system response. With these values, a
system response with a settling time about 4.44 seconds, and percent overshoot of
9.48% is obtained. The value of is set as 0.5. This settling time and percent
overshoot is obtained in response of system model but may have some deviation in
(3.60)
(3.61)
(3.62)
(3.63)
described in previous chapter. The weights q1, q2, q3 and q4 are corresponding to the
state variables: ball position, ball velocity, motor angular position and motor angular
velocity. In order to find the LQR gain matrix F, these weighting matrices have to be
selected to yield the best system response.
Since the ball and beam control system is a position control system, the goal is
to reduce the error between the desired ball position and actual ball position. In other
words, it is desired to reduce the error of state variable x1, the ball position. Moreover,
the control input u, the voltage input to the motor is desired to be smaller. Based on
these facts, the state weighting matrices are selected by the following two criteria:
The values of Q and R obtained for this ball and beam control system is:
(3.64)
(3.65)
(3.66)
Appendix C. This function computes gain N by using state matrices and LQR gain
matrix F. The value of gain N as obtained by using Matlab function
‘rscale(A,B,C,D,F)’ is described in equation ( 3 .67).
(3.67)
power gear box motor ( ) is 40, and the number of teeth of gear on the
potentiometer knob ( ) is 36. Therefore, the ratio between the potentiometer output
angle ( ) and the motor angle ( ) with respect to the teeth ratio is:
(3.68)
(3.69)
(3.70)
(3.71)
(3.72)
(3.73)
(3.74)
constant
But, when the noises and error which may contain in sensor reading are taken
into account, the relationship between the output voltage and the distance is no longer
the same as the one described above in equation
38
(3.75)
(3.76)
The approximate equation given above is the relation of x and y for a single
measurement. So, if N number of measurements is made, then x and y is represented
as data pairs (xi , yi) where ( i = 1,2,3,…..,N ).
Assign a formula error to the data pairs of (xi , yi) and applied to equation
( 3 .76).
(3.77)
(3.78)
where X1 = c, X2 = -b, X3 = a + bc
39
(3.79)
Let
(3.80)
(3.81)
(3.82)
Here, the term is a scalar and does not change when transposed,
therefore it can be written as:
(3.83)
40
(3.84)
This is considered according to the nature of the curve for output voltage and
distance which has a decreasing slope, therefore, the value of X obtained by equating
the partial differentiation of the J equation to zero gives the minimum value for X.
(3.85)
Equation ( 3 .85) is solved by the partial differential formulas
given in equation ( 3 .86) and equation
(3.86)
(3.87)
(3.88)
Now, equation ( 3 .88) is equated with zero so that the
minimum value of X denoted by X opt can be found.
(3.89)
(3.90)
41
Since the values of Y and A can be obtained from known data of output
voltage and distance, the values of the parameters, a, b, and c, are calculated
respectively from the entities of matrix X.
(3.91)
(3.92)
(3.93)
3.7 Summary
In this chapter, the mathematical modeling of the ball and beam system,
including transfer function for motor model and ball and beam model as well as state
space equations, are calculated. The moment of inertia of the ball is selected
depending on the type of ball used in the system. The relation between the beam angle
and the motor angle is also considered. Moreover, PID gains and LQR gain, together
with the weighting matrices Q and R as well as the scale factor N, are calculated.
Then, equation for the angle detection unit is found out to obtain the motor angular
position. Similarly, equations for PSD sensor are calculated in order to obtain the
parameters of the sensor which are required in finding the actual ball position.
42
CHAPTER 4
EXPERIMENT AND RESULTS
The complete experimental setup of the ball and beam system assembly used
in this experiment is shown in Figure 4 .18.
Lever Arm
Assembly
Beam
PSD Sensor Assembly
Sensor Support
Support Post
Assembly
Assembly
HG Servo Spirit Level
Arduino RC Servo
Controller
Base Adjust Screw
Assembly
increment, and voltage measurements are made 500 times for each distance. Then, the
average value of the voltage among 500 times is recorded with respect to its distance.
Finally, a graph of ‘voltage in volts’ versus ‘distance in cm’ is drawn using the
recorded data values. Here, the calibration process is repeated until the best result is
obtained and that best fit result is taken as final value for the parameters. This process
is done with the help of Matlab program in order to get précised results. The data
values of measured voltages with respect to placed distances is described in Table
4 .4. Figure 4 .21 shows the graph of recorded data values in terms of output
voltage in volts versus distance in centimeter.
Table 4.4. Recorded Data Values for Voltage Measurement and Distances
Distance (cm) Output Voltage (V) Distance (cm) Output Voltage (V)
6 3.159638 22 0.901173
8 2.722845 24 0.798065
10 2.206090 26 0.719189
12 1.803050 28 0.636940
14 1.555670 30 0.570968
16 1.329257 32 0.501965
18 1.167928 34 0.448055
20 1.024624 36 0.406872
40
Measured
35
30
25
Distance [cm]
20
15
10
0
0 0.5 1 1.5 2 2.5 3 3.5
Voltage [V]
30
25
Distance [cm]
20
15
10
0
0 0.5 1 1.5 2 2.5 3 3.5
Voltage [V]
a = 36.678947 (4.94)
b = 0.522710 (4.95)
c = - 3.660378 (4.96)
previous chapter. A block diagram for ball position detection part is created in
Simulink as part of position control experiment and is used in both PID and LQR
control experiments. The block diagram of position detection part is shown in Figure.
Here, the signal pin of PSD sensor is connected to analog pin A2 of Arduino
controller.
First, the feedback gain Kp_id is adjusted until the system response becomes
somewhat oscillatory. During testing to find best fit feedback gain value, the
experiment is repeated only twice. When the best value for feedback gain is found, the
experiment is repeated 8 times and the results together with their average value are
plotted. The output waveform during experiment is shown in Figure 4 .25, and the
plot of 8 repetitions together with their average value is shown in Figure 4 .26.
In this experiment, the feedback gain values from 0.085 to 0.125 are tested,
and the best result occur at gain value of 0.12. After the stabilization feedback gain is
obtained, the motor parameters are derived with the use of Matlab function
‘fminsearch’ which calculates the squared integral error and returns the value. The
equation for squared integral error (J) is:
97
(4. )
where, y [k] = actual step response data obtained in the experiment
ysim [k] = response of a model with consideration of influence of discretization
of controlled object
To find motor parameters, gain K and time constant T, a function is created to
define feedback gain and step response data obtained in above experiment. Since the
sampling period of 20 ms is not extremely short and the experimental setup is
subjected to a digital control with that sampling time, the values of gain K and time
constant T obtained may be slightly different from the actual values. Therefore, the
influence of the discretization of controlled object, which is the process of converting
continuous time signal to discrete time signal, is to be considered in this experiment.
The motor parameters are derived by a comparison plot of actual step response data
with response of a model with consideration of influence of discretization of
controlled object as expressed in equation (4.4), the equation of integral squared error.
50
Here, the time length for fitting, which is the time range where the calculated response
from the model agrees with the experimental data, is required to find by repeating
trials in order to obtain the best fit values of motor parameters. In this experiment, the
time length is taken as 1.6 seconds. The plot for comparison table and the obtained
motor parameter values are described below. Matlab program together with created
function to perform motor parameter derivation is expressed in Appendix A.
K = 202.335440 (4.98)
T = 0.362771 (4.99)
Figure 4.29. Block Diagram for Single Set Point PID Control Experiment
As shown in Figure 4 .30, the actual ball position follows the desired set
point position in an acceptable range although there is some deviation. Therefore, it
can be said that single set point PID control experiment perform effective control
actions in order to control the ball position at a desired set point. Here, the reference
signal line is not visible because it is totally identical with the model ball position
signal. Other than desired set point position of 20 cm, other set point values can also
be tested and checked whether the control of the ball position is effective as desired.
53
In Figure 4 .31, ‘pulse generator’ means reference position, ‘ball and beam’
means actual ball position and discrete LPF means model ball position respectively. It
can be seen from the results that the actual ball position follows the reference position
with only a little deviation. Also, the nature of model response and actual response is
very close to each other. Therefore, the performance for two set points PID control
experiment can be considered to have acceptable results.
54
Now, the experimental results for LQR control experiment will be explained.
Before carrying out the experiment, the controllability of the open loop system is
tested by a Matlab program, described in Appendix C. Then, since the result proves
that the system is controllable, LQR control experiment is carried out. Figure 4 .34
shows the experimental results for LQR control experiment. First plot represents ball
position plot for set point and actual value, second plot is the motor output response
and the third plot shows the controlled input into the motor. In this figure, it can be
seen that the actual ball position follows the set point position very well. The results
can be considered to be better than the results from PID control experimental results.
This can be because LQR control experiment controls both the ball position and the
motor position. Also, the use of scale factor N eliminates the steady-state error.
4.6 Root Locus and Frequency Response of Ball and Beam Control System
After the experimental results for both PID and LQR control experiments are
explained, the root locus and the frequency response of the ball and beam control
system is to be considered. The system in LQR control experiment is used to
determine the frequency response of the closed loop control system because the
transfer function of RC servo motor used in PID control experiment, which is required
to find the closed loop system transfer function, is difficult to find.
The system stability will now be discussed by means of root locus and
frequency response of the ball and beam system. First, the root locus of the closed
loop system is considered as shown in Figure 4 .35. The poles of the system are
-17.3736, -4.3697 and -1.4443 ± 1.1279 i, respectively. It can be seen that the system
is stable since all the poles of the system lies in the left half of the plane.
30
Imaginary Axis (seconds -1)
20
10
-10
-20
-30
-40
-50 -40 -30 -20 -10 0 10 20 30 40
-1
Real Axis (seconds )
plane does not encircle (-1, 0) point”. In this ball and beam system, since there is no
poles in the right half s-plane and the contour does not encircle the point (-1, 0), the
system is said to be stable.
0.8
0.6
0.4
Imaginary Axis
0.2
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.5 0 0.5 1 1.5
Real Axis
System: c_sys
Magnitude (dB)
-50
Gain Margin (dB): 14.1
At frequency (rad/s): 3.44
-100 Closed loop stable? Yes
-150
-200
90
0
Phase (deg)
System: c_sys
-90 Phase Margin (deg): -180
Delay Margin (sec): Inf
-180
At frequency (rad/s): 0
-270 Closed loop stable? Yes
-360
10 -3 10 -2 10 -1 10 0 10 1 10 2 10 3
Frequency (rad/s)
4.7 Graphical User Interface for Ball and Beam Control System
The Graphical User Interface (GUI) for ball and beam control system includes
ball and beam system model, description for ball and beam GUI control panel, a ball
position slider to set the ball position, radio button panel to select whether to carry out
PID or LQR control experiment, an axes to plot ball position output response, as well
as Set Position, Open Simulink, Plot Output and Clear Axes buttons to set ball
position, to open Simulink block diagrams, to plot system output response and to clear
output response plot, respectively. The created GUI for the ball and beam control
system is shown in Figure 4 .38. GUI for ball and beam control system is created
only by single set point experiment both for PID and LQR control experiments.
Figure 4.38. Graphical User Interface for Ball and Beam Control System
The limitations of the GUI used in this system are as described below:
GUI only open the Simulink block diagrams and experiment can only be
started and stopped from Matlab/Simulink model
Output response can be plotted only when simulation process is completed,
real-time plot of the system is not available
System model is only to show the configuration of ball and beam system,
animation of the system is not created
59
deviations are considered as undesired errors occurred during ball and beam control
experiment.
4.9 Summary
In this chapter, the experimental setup of the ball and beam control system,
which is composed of mechanical and electrical components, is first described. Before
the control experiment, the results for sensor calibration process and motor parameter
identification process are explained with associated plots from Simulink scope. Then,
PID and LQR control experimental results are explained and discussed. Limitations
and deviations occurred during the experiment are also described by associated
figures. Moreover, the root locus and the frequency response plots of the system are
61
also shown and explained based on their nature. The graphical user interface of the
ball and beam control system is presented with its functions and options.
62
CHAPTER 5
DISCUSSION AND CONCLUSION
5.1 Discussion
In this thesis, modeling and control of ball and beam system using Arduino
and Matlab/Simulink software is carried out. For modeling of the ball and beam
system, Newtonian method, which considers force and torque equations, is used. The
transfer function and the state equations of the system, which are to be used in control
system design, are calculated. To control the ball and beam system, PID and LQR
control methods are studied in order to design I-PD+FF controller and LQR controller
with scale factor N, respectively. The values of PID gains are determined by pole
assignment method and that of LQR gain is considered by Riccati equation. Then,
program codes and block diagrams of the ball and beam control system for both PID
and LQR control experiment are developed and the experiment is carried out.
In PID control experiment, single set point and two set points inputs are tested
while in LQR control, only single set point input experiment is carried out. Although
there are some limitation and deviation during the experiment, both PID and LQR
control experiments are considered to have desired control action which gives
acceptable results for controlling the ball position at a desired reference point. After
both PID and LQR control experiments yield output results with desired
characteristics, these experiments are carried out through a graphical user interface
control panel. The output responses of the ball and beam control system are also
plotted in that GUI window.
In this thesis, Arduino I/O library is used to interface Arduino controller and
Matlab/Simulink software. Arduino controller is just an interface for inputs and
outputs of the system. All the programs and Simulink models are developed and run
in Matlab/Simulink software and are not built into the Arduino controller. A USB
cable is required to connect Arduino controller and the PC in which Matlab/Simulink
63
software is installed. With Arduino I/O library, it is not available to develop real-time
application of the system.
64
If a library, called Arduino Support Package, is used, Simulink models and the
associated programs can be built into the Arduino controller. And so, the experiment
can either be carried out only using the Arduino controller or be connected to Matlab
in order to the monitor the real-time system response. In this case, the USB cable is to
import and export real-time data to and from Arduino controller and Matlab software.
This is termed as Run on Target Hardware (RoTH) process with which the real-time
application of the system can be available.
5.2 Conclusion
For the control of the ball position at a desired reference point, the results for
LQR control experiment are better compared to that of PID control experiment.
Moreover, initialization time in LQR control experiment is relatively short compared
to that occur in PID control experiment. For both PID and LQR control experiments,
it is found that the control of ball position at the middle of the beam, i.e., 21 cm,
achieve the best control action. However, the output response for controlling the ball
position at other points along the beam also gives acceptable results. But, there is a
limitation that the ball position control process cannot be carried out for the distances
from 6 cm to 36 cm because of inexactness of the sensor reading at that position.
Also, the deviation of actual ball position from desired reference position sometimes
occurs during the experiments for both PID and LQR control methods.
For graphical user interface, there exist some limitations, too. The GUI control
panel only opens the Simulink model, but, the simulation process is started and
stopped through that Simulink model in order to carry out the experiment. The output
response of the system can only be plotted after all the simulation process is
completed. Also, the ball and beam system model is just to show the configuration of
the ball and beam system. However, the GUI contains such useful options as a
colourful graphic figure for ball and beam model, a description for ball and beam
control panel, a selection for experimental method, a ball position set slider and a plot
of experimental results together with associated pushbuttons.
Therefore, it can be concluded that the output response for both PID and LQR
control experiment as well as the features of the graphical user interface in the ball
and beam control system of this thesis are considered to achieve acceptable output
results as desired.
65
REFERENCES
[17Ahm] Ahmed A.M., A.Taifour Ali, Almahdi H.A., Osama A.Taha and
A.Naseraldeen A, Design and Implementation of Ball and Beam
System using PID Controller, Suden University of Science and
Technology, SciEP, Vol.3, No.1, 1-4 (2017)
[17San] Santosh Anand and Rajkishore Prasad, Dynamics and Control of Ball
and Beam System, IJRITCC, Vol.5, Issue 5, June, (2017)
[14Car] Carlos G.Bolivar Vincenty and Gerson Beauchamp Baez, Modeling the
Ball and Beam System from Newtonian Mechanics and from Lagrange
Methods, LACCEI, July, (2014)
67
[13Sit] Sitki KOCAOGLU and Hilmi KUSCU, Design and Control of PID-
controlled Ball and Beam System, International Science Conference,
November, (2013)
[12Car] Carion Pelton, Take Home Labs and the Ball and Beam System,
Oklahoma State University, (2012)
[11Ric] Richard C.Dorf and Robert H.Bishop, Modern Control Systems, 12th
Edition, (2011)
[10Moh] Mohd Fuaad Rahmat, Herman Wahid and Norhaliza Abdul Wahab,
Application of Intelligent Controller in a Ball and Beam Control
System, International Journal on Smart Sensing and Intelligent
Systems, Vol.3, No.1, March, (2010)
[09Tom] Tom Trapp and Wil Selby, Ball and Beam Final Report, Massachusetts
Institute of Technology, (2009)
[07Wei] Wei Wang, Control of a Ball and Beam System, The University of
Adelaide, Department of Mechanical Engineering, June, (2007)
[96Mat] The Math Works.Inc, Building GUI with MATLAB, December, (1996)
68
APPENDICES
70
APPENDIX A
10 2.206090
12 1.803050
14 1.555670
16 1.329257
18 1.167928
20 1.024624
22 0.901173
24 0.798065
26 0.719189
28 0.636940
30 0.570968
32 0.501965
34 0.448055
36 0.406872 ];
x = mydata(:,2);
y = mydata(:,1);
N = length(x);
A = [x,y,ones(N,1)];
Y = [x.*y];
X = A\Y;
a = X(1)*X(2)+X(3);
b = -X(2);
c = X(1);
fprintf('a = %f\n',a);
fprintf('b = %f\n',b);
fprintf('c = %f\n',c);
yfit = a./(x+b)+c;
figure(1)
plot(x,y,'*',x,yfit);
xlabel('Voltage [V]')
ylabel('Position [cm]')
legend('Measured','Calculated')
axis([0 3.5 0 40])
72
function J = myfunc(x,y,t,ts,Kp_id);
K = x(1); T = x(2); P = tf([0 0 K],[T 1 0]); Pd = c2d(P,ts,'zoh');
Ld = Pd*Kp_id;
Gd = feedback(Ld,1);
ysim = step(Gd,t);
J = norm(y-ysim,2);
73
Amplitude r
Period r_cyc/0.02
Pulse width r_cyc/0.04
74
APPENDIX B
RC servo motor:
APPENCIX C
wf=2*pi*3;
78
Fc = wf^2/(s^2+2*0.7*wf*s+wf^2);
Fd = c2d(Fc,ts,'tustin');
[numlpf,denlpf] = tfdata(Fd,'v');
a = 36.678947;
b = 0.522710;
c = -3.660378;
open_system('constant_bb_pid_rc_sl');
open_system('constant_bb_pid_rc_sl/Ball position');
Codes for two set point PID experiment are the same as single set point except
the reference for ball position:
r1 = 15; r2 = 25;
Amplitude r2-r1
Period r_cyc/0.02
Pulse width r_cyc/0.04
K = 202; T = 0.32;
K_b = (3/5*9.8)*100;
K_theta = (pi/180)*(2.1/15);
A = [0 1 0 0 ;
0 0 K_b*K_theta 0 ;
0 0 0 1 ;
0 0 0 -1/T];
B = [0 ; 0; 0; K/T];
co = ctrb(A,B);
unco = length(A)-rank(co);
if (unco==0)
79
Fc = wf^2/(s^2+2*0.7*wf*s+wf^2);
Fd = c2d(Fc,ts,'tustin');
[numlpf,denlpf] = tfdata(Fd,'v');
a = 36.678947;
b = 0.522710;
c = -3.660378;
open_system('bb_lqr_con_sl');
open_system('bb_lqr_con_sl/Scope')
function[Nbar]=rscale(a,b,c,d,k)
error(nargchk(2,5,nargin));
nargin1 = nargin;
if (nargin1==2),
[A,B,C,D] = ssdata(a);
K = b;
elseif (nargin==5),
A=a; B=b; C=c; D=d; K=k;
else error('Input must be of the form (sys,K) or (A,B,C,D,K)')
end;
s = size(A,1);
Z = [zeros([1,s]) 1];
N = inv([A,B;C,D])*Z';
Nx = N(1:s);
Nu = N(1+s);
Nbar = Nu + K*Nx;
K_theta = (pi/180)*(2.1/15);
A = [0 1 0 0 ;
0 0 K_b*K_theta 0 ;
0 0 0 1 ;
0 0 0 -1/T];
B = [0 ; 0; 0; K/T];
C = [1 0 0 0];
D = 0;
Pbb = ss(A,B,C,D);
Q = diag([100 20 20 1]);
R = 1000;
F = lqr(Pbb,Q,R)
N = rscale(A,B,C,D,F)
Ac = A-B*F; Bc = B*N; Cc = C; Dc = D;
[num den] = ss2tf(Ac,Bc,Cc,Dc);
c_sys = tf(num,den);
figure(1)
rlocus(c_sys)
title('Root Locus of the System')
figure(2)
bode(c_sys)
grid
title('Bode Plot of the System')
figure(3)
nyquist(c_sys)
title('Nyquist Plot of the System')
82
APPENDIX D
% Create Ball
v = 2*pi*(0:.05:.95)';
ball_x=bb_radius*sin(v);
ball_y = bb_radius*(1+cos(v));
x = bb_length/2;
patch(ball_x+x,ball_y,'y');
% Create Beam
beam_x = bb_length*[0 1 1 0]';
beam_y = bb_width*[0 0 -1 -1]';
patch(beam_x,beam_y,'c');
% Create Fulcrum
pivot_x = [0 0 0.5 0.5]';
pivot_y = [-bb_width -8.5 -8.5 -bb_width]';
patch(pivot_x+(x-0.25),pivot_y,3);
block_x = [0 0 4 4]';
block_y = [-8.5 -10 -10 -8.5]';
patch(block_x+(x-2),block_y,3);
piv_x = 0.5*sin(v);
piv_y = 0.5*(1+cos(v));
x = bb_length/2;
patch(piv_x+x,piv_y-bb_width,'r');
%Create motor
motor_x = [0 0 4 4]';
motor_y = [-8 -10 -10 -8]';
patch(motor_x+(3/4)*bb_length,motor_y+0.5,'k');
motorb_x = [0 0 5 5]';
motorb_y = [-9.5 -10 -10 -9.5]';
patch(motorb_x+((3/4)*bb_length)-0.5,motorb_y,'c');
%Create arm
armxbar = [0 0 0.7 0.7]';
armybar = [-bb_width -8.5 -8.5 -bb_width]';
patch(armxbar+(3/4)*bb_length+3,armybar,3);
arm_x = [0 0 3 3]';
arm_y = [0 0.5 0.5 0]';
84
patch(arm_x+(3/4)*bb_length+0.5,arm_y-8.7,'r');
xcen = 0.3*sin(v);
ycen = 0.3*(1+cos(v));
patch(xcen+(3/4)*bb_length+2,ycen-8.7,'y');
guidata(hObject, handles);
switch get(get(handles.method_button,'SelectedObject'),'Tag')
case 'pid_button'
open_system('bb_pid_con_sl')
case 'lqr_button'
open_system('bb_lqr_con_sl')
otherwise
end
guidata(hObject,handles);