Escolar Documentos
Profissional Documentos
Cultura Documentos
CONTROL SYSTEMS
Lect.univ. LUMINITA GIURGIU
ABSTRACT
This paper demonstrates the effect of the scheduling policy on the global control performance in the
case of three tasks running concurrently on the same CPU and controlling three different dynamic systems.
The simulation is realised in the TrueTime MatLab toolbox environment. The advances obtained in microelectronics have led to the situation where almost all control algorithms are realized by computers. More
than that, the controllers are often implemented as one or several tasks on a microprocessor with a real time
operating system. The operating system uses multiprogramming to multiplex the execution of the various
tasks. This is why embedded control systems are most often subject to limited computer resources that can be
viewed as shared resources for witch the tasks compete. Tasks interfere with each other through preemption
and blocking when waiting for common resources.
The continuous process output is sampled at regular time intervals and converted to digital
form by an A/D converter. The control algorithm reads the sampled process output and computes a
control signal that is converted back to analog form by a D/A converter. The D/A conversion is
usually performed by keeping the output constant between conversions, so called zero order hold. A
periodic control loop is implemented by the pseudo code in Listing1. The reading of inputs and
writing of output signals correspond to direct calls to external A/D and D/A conversion interfaces. It
is also possible to have the sampling and actuation being performed by dedicated tasks, when
buffers are used to communicate the values between the tasks. In the case of a networked control
system the reading and writing of signals also involve communication with other nodes in the
network.
In order to minimize the input output delay, the control algorithm is divided into two parts,
where the first part computes the control signal based on current measurements and previous states,
and the second part then updates the internal states of the controller for the next sample.
Listing 1
t = currentTime();
LOOP
Read Inputs;
Control Calculation;
Write Outputs;
Update Internal States;
t = t + h;
waitUntil(t)
END
II. Real-time scheduling
Real time scheduling theory is concerned with the problem of, given a set of tasks, finding an
execution order that guarantees that all tasks meet their timing constraints. Real time scheduling
algorithms fall in two basic categories: static and dynamic scheduling.
C
U = i n(2 n 1)
T
i =1 i
(1)
In the more general case where Di < Ti, deadline monotonic priority assignment is optimal
[Liu and Layland, 1973]. Here the priorities are assigned according to the relative deadlines of the
tasks.
For any fixed priority scheduling assignment, an exact schedulability analysis may be
performed by computing the worst case response times, Ri, for each task, see [Joseph and Pandya,
1986]. Using fixed priority assignment the priorities of the tasks are static and not changed during
runtime.
An alternative approach is earliest dead line first (EDF) scheduling which exploits dynamic
priority assignment based on the absolute deadlines of the tasks. At any point in time, the task with
the shortest remaining time to its deadline will get access to the CPU. EDF is more resource
effective than rate monotonic scheduling and a necessary and sufficient condition for schedulability
(given Di = Ti) is that the utilization factor is below one:
n
C
U = i 1
T
i =1 i
(2)
A benefit of dead line based scheduling over priority based scheduling is that it is more
intuitive to assign deadlines to tasks than to assign priorities. Global information about the relative
importance of all tasks in the system is needed in order to assign priorities, which is not required to
assign deadlines. The main drawback with EDF is that it offers no guarantees at all during overload.
In that case all tasks will miss their deadline, which is known as the domino effect [Stankovic et al.,
1998]. For hard real time systems this may be fatal. However, the result during overload under EDF
is that the effective periods of the tasks will be scaled in such a way that the utilization of the
system is still 100 per cent [Cervin et al., 2002]. Under reasonable overload, this fair distribution of
resources will, for most control systems, still give reasonable performance for all loops.
III. True time simulation tool
There are numerous tools that support simulation of control systems or simulation of real time
scheduling, but very few tools support co-simulation of control systems and real time scheduling.
The True Time simulator is a complete co simulation tool based on MATLAB/Simulink and in its
current version it supports task scheduling by arbitrary scheduling policies, network simulation by
standard MAC layer protocols, and a variety of real time primitives used for experimentation with
flexible scheduling and compensation schemes.
The case under study takes three PID tasks running concurrently on the same CPU,
controlling three different systems. The TrueTime blocks are connected with ordinary Simulink
blocks to form a real time control system, see Figure no. 2.
The three systems are controlled by controller tasks implemented in a TrueTime kernel block.
Before a simulation can be run, it is necessary to initialize kernel blocks and to create tasks for the
simulation. The execution of tasks is defined by code functions. A code function is further divided
into code segments according to the execution model. All execution of user code is done in the
beginning of each code segment. The execution time of each segment should be returned by the
code function.
The kernel is initialized by the initialization script, providing the number of inputs and
outputs, the scheduling policy and creating periodic tasks that uses defined code functions. In the
initialization script the rate-monotonic scheduling is specified by the function ttinitkerenel and the
task are created with ttCreatePeriodicTask function who specifies the name of the associated code
function. The code function is given in Listing 2.
Listing 2
function [exectime, data] = code_f(seg, data)
switch seg,
case 1, r = ttAnalogIn(data.rChan); % read reference
y=ttAnalogIn(data.yChan); % read process output
data = calc(data, r, y); % calculate PID action
exectime = 0.002;
case 2, ttAnalogOut(data.uChan, data.u); % output control signal
exectime = -1;
end
Running the simulation of the control system, seven graphics are obtained: three graphics for
the control signals, three graphics for the reference and outputs signals and the schedule graphic of
the tasks during the simulation. Studying the computer schedule and the control performance it is
noticed that task1 will miss all its deadlines (see Figure no. 3) and the corresponding control loop is
unstable (see Figure no. 4).
Fig. no. 3 Computer schedule (RM case): task1 (blue), task2 (green), task3 (red)
IV. Conclusions
A priority based approach will favor high priority tasks over low priority tasks, with the
possible consequence that low priority tasks may not execute at all, being starved. Using dead line
based scheduling, the available CPU time will be distributed among the tasks in a more fair way and
better results concerning the stability of the control loops will be obtained. Depending on the
application this may or may not be a desired feature. The major drawback with dead line based
scheduling is the lack of commercial products supporting it.
BIBLIOGRAPHY
1. strm, B. Wittenmark, Computer Controlled Systems, Prentice Hall, Upper Saddle River, N.J., 1997
2. rzn, K.-E., Real-Time Control Systems, Department of Automatic Control, Lund, Sweden, Lund
Institute of Technology, 2001