Ball-And-Beam Laboratory System Controlled by Simulink Model Through Dedicated Microcontrolled-Matlab Data Exchange Protocol
Ball-And-Beam Laboratory System Controlled by Simulink Model Through Dedicated Microcontrolled-Matlab Data Exchange Protocol
Ball-And-Beam Laboratory System Controlled by Simulink Model Through Dedicated Microcontrolled-Matlab Data Exchange Protocol
Krzysztof Nowopolski
Poznań University of Technology
60-965 Poznań, ul. Piotrowo 3a, e-mail: Krzysztof.Nowopolski@put.poznan.pl
1. Introduction
Modern university courses of control theory should not focus only on control
systems simulations and textbook computational exercises. There is a rising
demand on impressive laboratory systems that can be easily configured and
reprogrammed for work with user-defined control strategies to develop students
engineering abilities. An objective of the design and research work described in
this paper is to develop a laboratory control system with an interface to Matlab
computing environment. The main requirements were: interface that allows to
implement control laws in an easy manner (graphical user interface is preferred),
compact size, low cost, simple design, minimalized number of sensors, utility for
education purpose. There are only a few classical systems, that can satisfy this
conditions, one of them is the presented ball-and-beam laboratory system.
The system consists of a ball rolling freely on a beam, which is driven by an
electric motor. The task is to keep the ball in one reference position rejecting
disturbances, or to track the reference position signal, tending to keep the control
310
K. Nowopolski / Ball –and–beam laboratory system controlled …
error at negligible level. Both accuracy and dynamic aspects of the control need to
be taken into consideration during design of the control strategy.
The system is unstable, underactuated and nonlinear and therefore it is treated
as an appreciated benchmark for various control strategies [1]. Owing to the
presented in the article microcontroller-Matlab data exchange interface, this
laboratory system can be easily adapted as control theory laboratory practice for
Control Engineering, Computer Science or Electrical Engineering students.
2. Laboratory system
2.1. Mechanical system
There are two basic mechanical layouts of the beam-and-ball system. First one,
shown in the Figure 1a, consists of an electric motor, connected directly through
its shaft to the beam, which center is located in the motor shaft axis. The main
principle of the second layout is shown in the Figure 1b. One end of the beam is
attached to a motionless rod, and the second one is connected to a moveable rod
(length L) attached to a disc (diameter 2R) driven by the motor. All mentioned
joints are fitted with ball bearings.
(a) (b)
Fig. 1. Two basic layouts of ball-and-beam system: a) beam driven by a rod,
b) motor shaft placed in the center of beam
condition, that the motor angle tends to 0, it can be assumed that moveable rod is
perpendicular to the beam, so trigonometric transformations are negligible in this
joint. Therefore, the relationship between motor shaft angular position α and beam
angular position β is approximated by formula 1.
R
β= α (1)
L
In order to increase the accuracy of angular positioning of the beam, an
additional gear is added between motor shaft and the disc.
Before the ball-and-beam mechanism was constructed, complex analysis of the
system operation, based on a computer model, was done. The model of ball
movement was derived explicitly from the Lagrange-Euler equations, presented
also in [2, 3]. Formula (2) describes relationship between ball linear position x and
beam inclination β. Ball mass, radius and momentum of inertia are represented by
parameters m, r and J respectively.
m g
xt sin t (2)
J
m 2
r
Due to mentioned complicated structure of the mechanical construction, the
system driving the beam (kinematic chain between motor and the beam) was
modeled by using Simscape SimMechanics toolbox. This powerful environment
allows to analyze kinematic properties of the modeled system after providing basic
parameters of bodies and joints that it contains, not going into details of
trigonometric transformations between parts of the system.
The assumed dynamics of the system was rather low, hence the application of a
stepper motor was acceptable. This way motor shaft position control is kept at
extremely simple level, since it can be run in an open loop, with no additional
encoders or other angular position sensors. The electrical stepper motor driving the
beam, was simulated using the following equations [4]:
T t K sin N cos N it
dit R it 1 ut K t sin N (3)
dt L L L cos N
Two-element vectors i and u represent respectively currents and voltages in
stepper motor windings. Basic motor parameters that have been taken into
consideration are: winding resistance R and inductance L, and motor constant K.
The motor constant is proportional to number of phases, stator poles and magnetic
flux of each pole. The output of the motor model is torque signal, that is multiplied
by the gear coefficient n and then feeds the SimMechanics system model. The
SimMechanics model output values are motor angular velocity ω and position θ.
These two values are multiplied by gear coefficient n to calculate the motor shaft
312
K. Nowopolski / Ball –and–beam laboratory system controlled …
The simulation model was derived and designed for three general reasons: to
analyze the behavior of the system, to choose the basic mechanical parameters of
the system (such as dimensions and masses of the beam, rod and disc, required
torque), and preliminary examine some basic and most promising control
strategies. P, PD and LQR control laws were implemented as the controller of the
simulation model. One of the basic conclusions of this simulation research was: it
is essential to bring the velocity to zero, not only control the ball position.
Therefore the most simple proportional controller will not allow to stabilize the
ball in a reference position.
Fig. 3. Overview of the built laboratory system: 1 – stepper motor (behind a metal plate),
2 – disc connected to the beam by a rod, 3 – beam, 4 – ball, 5 – infra-red position sensors
313
K. Nowopolski / Ball –and–beam laboratory system controlled …
uses physical layer of USB interface, but reports in operating system of the
computer as a virtual serial port (see Fig. 4). This way the simplicity of UART
usage and its very good Matlab implementation may be combined with universality
of the USB interface.
As it was mentioned in the section 2.2, the microcontrollers tasks are focused
on the acquisition of ball position and stepper motor positioning. Whole algorithm
of ball positioning and control law may be easily implemented and changed in real
time in the running computer simulation, using GUI. This user-friendly way of
operation is ensured by the data exchange protocol described below.
The data exchange protocol is very simple, but effective. Two sides of the
communication process are: microcontroller that works as a server and a PC which
is a client. There are only three different types of frames included in the protocol.
Each communication cycle is initiated by the client – the computer software.
The initiation frame contains two bytes. These values is characteristic for
transmission initiation and threaten in any other frame as inadmissible.
The microcontroller response contains six bytes: two integer values
representing measurements of voltage outputs of the ball position sensors, and the
third integer value – momentary position of the stepper motor shaft. The shaft
position is estimated by counting the number of step impulses, assuming, that
conditions of motor operation (limited rotational speed, small torques required to
pull up and hold the beam) do not allow to lose steps. If there is no server
(microcontroller) response, the initialization is repeated periodically.
After receiving the microcontroller response frame, Matlab control algorithm
computes new reference motor shaft position. This information is sent to
microprocessor system as a two-byte integer number, equal to the number of
315
K. Nowopolski / Ball –and–beam laboratory system controlled …
316
K. Nowopolski / Ball –and–beam laboratory system controlled …
Fig. 7. Non-linear, ambiguous ball position sensor characteristic with its approximation
317
K. Nowopolski / Ball –and–beam laboratory system controlled …
Fig. 8. Scheme of LQR controller designed for real laboratory system – two communication
blocks are highlighted in grey
Since the linearized model of the process includes only two state variables
(position and velocity of the ball, gathered in state vector x), the two-element K
gain vector is required to be used in an implementation of LQR control law, given
by the general equation 5 [5].
u K x T (5)
Position of ball is just multiplied by the first element of K vector. Velocity of
the ball is computed as a difference of momentary positions, filtered by a running
average filter with transfer function given by the equation 6.
N
1
G filter z z i
(6)
N i 0
The horizon of the filter N is set to 50 samples, due to presence of significant
disturbances in infra-red sensor measurements. These two values are summed and
then filtered again before being sent. The results of operation with two K different
values are shown in the figure 9. In the figure 9a the system operation with optimal
(among tested set) controller parameters is shown. Figure 9b presents system
operation when K vector values are too big – oscillations around reference value
are observed.
318
K. Nowopolski / Ball –and–beam laboratory system controlled …
(a) (b)
Fig. 9. Test of LQR control strategy with two K vector values: (a) K1=[30, 5000]T,
(b) K2=[40, 7000]T
System operation with PD and LQR control laws are very similar (Fig. 11).
Both of these algorithms control position as well as velocity of the ball.
Application of LQR algorithm provides a second degree of freedom. It is
noticeable in step switches between reference position. The PD control algorithm
forms then impulses in output control signal, which cause additional oscillations
319
K. Nowopolski / Ball –and–beam laboratory system controlled …
5. Conclusions
The objectives of the design and research work has been reached. The
laboratory system including hardware and software parts was designed and
launched. An inexpensive platform that can be utilized for educational purpose has
been built and basic control algorithms have been tested. These algorithms can be
utilized as one the first exercises in laboratory collage course. During system
operation no problems with communication have been encountered. The main
disadvantages, i.e. slow position sensor response and limited accuracy, are related
with application of low-cost infra-red sensors.
References
[1] Marton L., Hodel A.S, Lantos B., Hung J.Y., Underactuated Robot Control:
Comparing LQR, Subspace Stabilization, and Combined Error Metric Approaches,
Transactions on Industrial Electronics (Vol. 55), p. 3724-3730, Oct. 2008.
[2] B. Messnerk, D. Tilbury, Modeling the Ball and Beam Experiment, University
of Michigan 1997.
[3] Wenzhuo Chen, Xiaomei Sui, Yonghui Xing, Modeling and Modulation of Nonlinear
Ball-beam System Controller Based on Matlab, 9th International Conference on Fuzzy
Systems and Knowledge Discovery (FSKD), p. 2388-2391, 2012.
[4] S. Ossowski, Modelowanie i symulacja układów i procesów dynamicznych, Oficyna
Wydawnicza Politechniki Warszawskiej 2007.
[5] J. Sheng, J. Renner, W. S. Levine, A Ball and Curved Offset Beam Experiment,
American Control Conference, p. 402-408, 2010.
320