You are on page 1of 6

FROM SIMULATION TO HARDWARE IMPLEMENTATION

OF A PID CONTROLLED SYSTEM FOR A NEW


CONTROL ENGINEERING LABORATORY
Dockhorn M+, Haas OCL#, Wöstenkühler G~
+~
Department of Automation and Computer Science,
Hochschule Harz (University of Applied Studies and Research)
Friedrichstrasse 57-59, D-38855 Wernigerode, Germany
+
E-mail: u18455@hs-harz.de
~
E-mail: gwoestenkuehler@hs-harz.de
# Control Theory and Application Centre, Coventry University,
Priory Street, Coventry, CV1 5ED, U.K.
E-mail: o.haas@coventry.ac.uk

Keywords: PID, controller, simulation, LabVIEW, appropriate model should describe the behaviour of the
Matlab/Simulink, dSpace, crane, inverted pendulum system within a specified accuracy. There are many models
available to simulate the system behaviour. The best
Abstract approximation is the simplest model that meets the demands.
In addition, especially in case of modelling known systems,
This paper describes the steps from data acquisition, the model parameters should represent meaningful
simulation of the system, development of the PID controller parameters.
circuit, and implementation of the controller applied to a real A simple practical approach has been used. This is also
system as a reference for control engineering studies at based on small inherent nonlinearities. A theoretical
Coventry University. The students of this subject should learn approximation e.g. based on root mean square errors (RMSE)
to use different programs for a control task of an electrical can be applied in further activities.
supplied mechanical system. In this laboratory the used pc is The system can be divided into sub parts, which makes it
equipped with a 6024 PCI data acquisition board from easier to develop the overall model.
National Instruments. LabVIEW provides an interface
between the program and the external control signals. The pc 1.1 Model of carriage
is also equipped with a DS1104 board from dSpace, which
provides also the facility to gather and generate digital as well For the model of the carriage it is necessary to eliminate the
as analogue signals. The system which should be simulated influences of the pendulum (to remove the pendulum from the
and controlled is the “Bytronic Pendulum Control System” carriage). The used system has a build in position controller.
with the “Bytronic Pendulum Control Unit” [1]. This system Based on the analogue position controller inside the control
can be used in crane mode and in inverted pendulum mode unit the carriage will reach the set point in dependence of the
which gives the opportunity of two different control tasks. settings of its gain and feedback values. It is not possible to
set the speed or acceleration of the motor directly. If the
position input value exceeds +7 or goes below −7 volts the
1 Modelling carriage will reach the limits of the usable mechanical range
of the rail. With the open loop response data from the carriage
To create a suitable model in Matlab/Simulink it is necessary it is possible to determine the transfer function of the build in
to collect reference data for design and approval. The position controller:
response of the system in open loop condition can be obtained 250
G CP ( s ) = (1)
using LabVIEW [2] or dSpace [3]. Typical methods to 0.8 ⋅ s + 18 ⋅ s + 250
2

analyse a system from gathered data is to calculate step and/or The relation between the position and the speed is:
frequency response functions. For statistically significance dx
and for reduction of measurement deviations, the data x& = (2)
dt
collection has to be repeated 3 to 5 times with the same input
This relation together with the transfer function of the
signal.
position controller leads to
Based on the reference data it is possible to decide the
250 ⋅ s
kind of transfer function, which has comparable GS ( s ) = (3)
characteristics. A comparison between simulated reference 0.8 ⋅ s + 18 ⋅ s + 250
2

data and the measured output signals of the model leads to as a function of the speed with the set position as the input
suitable parameter values of the transfer function. An parameter. To match the output value of the tachometer,
which is used to measure the speed, it is necessary to modify 1.4 Model of inverted pendulum
the equation to
−25 ⋅ s The pendulum is a stable system with a simplified transfer
GCS ( s ) = (4)
0.8 ⋅ s + 18 ⋅ s + 250
2 function of:
1 ω0 2
1.2 Model of pendulum Gp1 ( s) = = (8)
1 + s 2 / ω0 2 s 2 + ω0 2
A model describing the mechanical displacement of a The poles of the equation are on the left side of the imaginary
pendulum uses the period time T and the damping factor d. axis of the s plane and the parameters can be calculated using
With the measured time period it is possible to estimate the the measured time period.
natural frequency ω0. An inverted pendulum is an instable system, so at least
2⋅π one pole is on the right half of the s plane. Converting the
ω0 ≈ (5) transfer function provides two poles on the right side of the
T imaginary axis of the s plane based on the measured time
ω0 2 period and this leads to the transfer function of
Gp1 ( s ) = (6)
s 2 + 2 ⋅ d ⋅ ω0 ⋅ s + ω0 2 − ω0 2
The open loop step response of the pendulum as reference
Gip1 ( s ) = (9)
s 2 − ω0 2
data allows to adjust the value of the model parameter d.
for the inverted pendulum by disregarding the damping and
ω0 = 6.22 Î G ( s) = 38.7008
(7)
p2 the nonlinearly of the real system. To include damping the
d = 0.032 s + 0.2 ⋅ s + 38.7008
2
following transfer function can be used. This description has
only one pole on the right side of the s plane for a damping
1.3 Model of crane value above zero.
− ω0 2
After the definition of the models for the carriage and the Gip 2 ( s ) = 2 (10)
pendulum the next step is to include the influences of the s + 2 ⋅ d ⋅ ω0 ⋅ s − ω0 2
carriage to the pendulum. To eliminate the offset and to adjust
the right amplitude an additional gain to the model values of
the pendulum and a subtraction of the position from the 2 PID control implementation in
output values of the pendulum like in figure 1 can be used.
The plot shows that the output of the model matches the Simulink
reference output of the real system (reference angle).
This chapter describes the simulation of the PID control loop
for the crane and the inverted pendulum model.

2.1 Crane model control loop


The position of the weight is defined by the location of the
carriage and the angle of the pendulum (the length of the
pendulum is constant). The problem is the influence of the
carriage to the pendulum. The important condition is the
angle of the pendulum and that the swinging of the pendulum
with the weight is limited if the carriage moves to a new
location.
To control only the angle makes it easy to reach the 90
degree position (vertical position) as fast as possible, also if
there is a disturbance. It is not possible to move the system to
a defined location and to stop it there.
To move the weight to a defined position another control
loop is necessary. This controller uses the fact that the
carriage must accelerate to keep the pendulum in an angle
different from 90 degrees. It will set the angle in dependence
of the position and speed of the carriage. It is possible to use
the speed output of the carriage and the actual position for the
controller to reach the new set point. The set point defines the
new position, a speed value of zero, and an angle of 90
Figure 1: plot and model of the crane, final implementation degrees. The dependence of speed and position is taken into
account by adding a gain module as shown in the model
diagram in figure 2.
Figure 2: closed loop of the crane model

With the settings for the two PID controllers the response of
the system looks like in the plot below. The plot in figure 3 2.2 Inverted pendulum model control loop
shows the changing position of the carriage with a small
overshoot together with the speed of the carriage. The output The problem for the inverted pendulum is nearly the same as
of the position controller sets the angle as shown in figure 3 for the crane. There is only one difference: the inverted
together with the measured angle of the pendulum. A faster pendulum is an instable system.
transition is possible with a larger usable angle but this Using only the first controller for the angle leads to the
depends on the allowed limits. correct angle. Based on the instability a small disturbance is
enough that the carriage must move to keep the pendulum in
the vertical position. Finally the carriage will reach the
mechanical limits and the pendulum will fall down. With the
second controller for speed and position the pendulum swings
more and more till it reaches the limits again.
One solution to get it stable is to separate the controller for
the speed and the position. At the end there is one controller
for the position with a speed output. The second controller for
the speed will produce the set angle. The third controller will
actually move the carriage to reach the set angle. With those
controllers it is possible to reach a position but the system
will oscillate around the set point.
By changing the limits of the speed controller it is
possible to observe that the oscillation will be less for smaller
limits. For a faster reaction higher limits are necessary. A
solution is to use variable limits, which are calculated using
the position difference. The whole system with the controller,
the variable limits and the model of the inverted pendulum is
shown in figure 4.

Figure 3: plots of angle, position and speed;


crane model; closed loop

Figure 4: closed loop of the inverted pendulum model


The response of the closed loop model is shown in figure 5. controllers. The two plots show the signals of the controller
The first plot displays the position of the carriage to the set and can be used to assess the implementation of the control
point changing. The second plot describes the angle and the loop in LabVIEW based on the output of the controlled model
oscillation of the pendulum. The third one represents the in figure 3.
speed.

Figure 6: LabVIEW program front panel to control the


position of the car with no swinging of the pendulum

The plot shows similar traces of the set point behaviour of the
real system and the simulation. Reasons for the differences
could be the nonlinear influences of the real pendulum.
Based on the two controllers it has also a good response to
a disturbance. For a disturbance at the pendulum weight (hard
hit at the pendulum), the carrier ran in the same direction to
catch the pendulum (angle controller). With the values of the
speed and the wrong position of the weight the controller for
the position set the angle to move the weight back to the set
position as shown in figure 7.

Figure 5: plot of position, speed and angle


inverted pendulum closed loop

3 PID control implementation in


LabVIEW Figure 7: LabVIEW program front panel to control the
position with a disturbance at the pendulum weight
After the simulation of the different controllers and the tuning
of the controllers, the next step is to apply the solutions to the
real system using LabVIEW. 3.2 Inverted pendulum LabVIEW control

3.1 Crane LabVIEW control Like the crane the program behaviour to control the inverted
pendulum as shown in figure 8 is also based on the solution of
The program behaviour shown in figure 6 is based on the the simulation with the measured angle for advanced
simulation. With the user interface it is possible to set the new adjustment. Figure 8 shows the set point following with an
position for the carrier and to change the gain values of the oscillation. The angle sensor causes a non-ideal behaviour. It
consists basically of a variable resistor. The output signal
depends on perpendicular movements of the desired direction
and its calibration is sensitive to mechanical stress like hitting
a border.

Figure 10: dSpace experiment layout to control the crane

Figure 8: LabVIEW program front panel to control the


4.2 Inverted pendulum dSpace control
inverted pendulum
The implementation is also based on the simulation. Only the
adjustable limits are not implemented. The user can set the
Figure 9 shows the behaviour of the inverted pendulum
position and the different gain values within the controller as
controller to a disturbance at the pendulum weight. Like the
well as the adjustment value for the measured angle. In
crane the carrier will run to catch the dropping pendulum.
LabVIEW the angle shown in the plot is before and in dSpace
Based on the current position and the current direction of
after the adjustment has been done, which is the reason for the
movement the new angle will be calculated to move the
different values at the axis. In working operation it is possible
weight back to the set position.
to see in this diagram the influence of this adjustment.

Figure 9: LabVIEW program front panel to control the


inverted pendulum with a disturbance

Figure 11: dSpace experiment layout to control the inverted


4 PID control implementation in pendulum
dSpace
The implementation of the controller for the real system can
5 Comparison of dSpace and LabVIEW
also be realised with an other program, e.g. dSpace. The
Both programs have in general similar features. In LabVIEW
students have to apply different possibilities to connect a
the programs are divided in the “Front Panel” (user interface
system to the pc and to get experience of advantages and
or in/out ports for sub-“instruments”) and in the “Block
disadvantages of the different programs. Therefore the
Diagram” (functional description of the instrument). By
controller has also been implemented in dSpace.
placing a chart on the “Front Panel” it will automatically
appear in the “Block Diagram”. The components can be
4.1 Crane dSpace control included by drag and drop from a toolbox and the data
connections are defined by drawing “wires”. dSpace use
The implementation is based on the simulation similar to the
mainly Simulink to implement the algorithm. In the library of
LabVIEW controllers. The user can change the gain values
Simulink are also special blocks available for the connection
for the controllers. The response of the system is shown in
between dSpace and its external interfaces. For an output of
figure 10. The controller in dSpace has the same behaviour
10 volts the Simulink model must represent an output value of
for the set point following and for a disturbance. The plot of
one. This is confusing for beginners and might cause an
the angle shows an offset, which is based on an inaccurate
unexpected behaviour within the experiment. With the “Real
calibration of the sensor.
Time Workshop” of Simulink the model description can be
converted into special files. In dSpace it is necessary to
include those files for building up a layout and to connect the
different parts of the layout with the model parameters
(system description files).
Both programs were used by a non experienced person, so
this comparison outlines the experiences and represents not a
benchmark.
For education purpose focusing on the connection
between the pc as controller and an external electrical system
LabVIEW should be preferred. For beginners it is easier to
get results as a motivating feedback. The transfer of measured
data from LabVIEW to Matlab/Simulink is difficult and also
the implementation of controllers.
Even for smaller problems it is more expensive to create
an experiment with dSpace. The transfer of data from a
dSpace environment to Matlab/Simulink is easier. If the
students have simulated the controller with time discrete
models they can easy replace the simulation model with the
real world by using the in- and outputs of the dSpace board.
This can be directly used for an experiment.

Acknowledgements
I thank my parents for unconditional support during my study
program and internship.

I express thanks to Dr Keith Burnham for the opportunity to


realise my internship at the “Control Theory and Application
Centre (CTAC)” at Coventry University (UK).

Many thanks to the whole team of CTAC and all my friends


in Coventry for the fruitful cooperation.

References
[1] Bytronic: http://www.bytronic.net/pcs.htm
[2] National Instruments: http://www.ni.com/labview/
[3] dSpace: http://www.dspace.de/
[4] Ken Dutton, Steve Thompson, Bill Barraclough (1997)
The Art of Control Engineering, Prentice Hall
[5] Matlab/Simulink help, examples and tutorials
[6] LabVIEW help, examples and tutorials
[7] dSpace help, examples and tutorials

You might also like