Sie sind auf Seite 1von 7

Using Grafcet To Structure Control Algorithms

Anders Wallén
Department of Automatic Control
Lund Institute of Technology
Box 118, S-221 00 Lund
Sweden
andersw@control.lth.se

Keywords: Real-time systems, sequential control, in- 2 Grafcet


telligent control, automatic tuning
Grafcet, or sequential function charts (SFC), is becom-
ing a standard tool in industry for programming PLC
systems. It can be viewed as a specialization of Petri
Abstract
Nets [David and Alla, 1992]. Thus, the existing formal
methods for analyzing Petri Nets may be applied to
A method is proposed for structuring real-time control Grafcet.
algorithms. Grafcet is used for representing the con- An example containing the basic Grafcet building
trol logic, and traditional programming languages are blocks is shown in Figure 1. The Grafcet consists
used for describing the pure algorithms. A detailed of interconnected steps and transitions. The steps
example with a relay auto-tuner is given. represent the states of the Grafcet. A filled marker
indicates that a step is currently active. Steps drawn
with double squares are called initial steps, implying
1 Introduction that they are initially active. Associated with each
step is a number of actions to be performed while the
Industrial control systems contain a mixture of con- step is active.
trol algorithms, sequences and logic. The pure control The steps are connected via transitions, each having
algorithms consist of algebraic, differential and dif- a boolean condition. This condition is tested while
ference equations coded in some traditional program- the transition is enabled, i.e., when the preceding
ming language. Most of the research in control system step is active. If the condition is true, the succeeding
design has been devoted to development and imple- step becomes active, and the preceding step becomes
mentation of such algorithms. Robust and adaptive inactive.
control are two areas where numerous design meth-
ods exist, leading to different control algorithms. Initial step
The logic surrounding the control algorithms is tra- Alternative paths
ditionally done by introducing boolean variables to-
gether with if and case statements in the algorithms. Parallel activities

As the complexity of the controller grows, the logic


tends to hide the actual control algorithm. Even if the
pure algorithm may be written in just a few lines, the Transition
final computer code might be very messy.
There is thus need for good tools to describe the Step
mixture of continuous algorithms with logic. In this
paper we will explain how an extension of Grafcet can
be used for this purpose. The approach combines the
clarity of the graphical representation of the logic with
Marker
the ability to perform high-level operations using or-
dinary programming languages. The obtained struc-
ture will simplify both development, debugging and
maintaining of the system. To illustrate the ideas, an
example with a relay auto-tuner for a PID controller
is discussed in more detail. Figure 1. Basic Grafcet building blocks.
control algorithms. It is convenient to interpret the
limit tests as non-linear modifications of the (mostly)
linear control algorithms, instead of emphasizing the
discrete-time property.
At the control loop level, there might be a lot of logic
governing the execution of the control algorithm. This
is especially true when implementing a controller with
more autonomy. For example, in order to successfully
install a controller, it is necessary to first make some
Figure 2. A macro step with exception transition. loop assessment, i.e. find the basic characteristics of
the process [Åström, 1993]. This includes a number
Grafcet supports alternative and parallel paths. The of more or less complex off-line and on-line tests, as
syntax for these is shown in Figure 1. In order to well as reasoning about the results from these tests.
structure the Grafcet hierarchically, it is possible to Further, there may be several different phases and
use macro steps, see Figure 2. A macro step is a modes of operation. Which mode to use may be decided
way of condensing an arbitrary number of steps and by various conditions such as operator commands,
transitions into just one step. It has one enter step working regions, scheduled control goals etc. During
and one exit step, and general Grafcet structures in on-line control, it may be desirable to do performance
between. The enter step is activated as soon as the assessment to see whether the control loop behaves
macro step becomes active. The transitions following as intended. Based on this, a decision may be taken
the macro step may not be fired until the exit step is to retune the controller parameters. Finally, it may
active. be possible to perform on-line diagnosis and fault
The power of Grafcet can be increased substantially handling on the local loop level. In Section 4 it is
by some minor modifications, see e.g. [Årzén, 1994]. shown how Grafcet can be used to address these
In this paper, the most important extension is that problems.
we allow general statements and expressions in the On the global control system level, the discrete-time
actions and transition conditions. Another useful ex- activities appear in control system (re)configuration,
tension is the exception transition, found to the left plant start-up and shut-down, planning and man-
in Figure 2. It is connected to a macro step, and it is ufacturing, global fault handling and diagnosis etc.
enabled all the time while the macro step is active. [Årzén, 1994] shows how Grafcet can be used in this
This makes the exception transition suitable for han- case.
dling failures, abortion and other types of exception
handling.
4 Using Extended Grafcet to describe
mixed systems
3 Mixing discrete-time and
continuous-time systems Many of the problems concerning the logic on the
control loop level are conveniently modeled using a
A typical realistic control system contains a mixture of Grafcet approach. This is especially true when the
algorithms running in continuous and discrete time. logic and decisions have a sequential nature.
Here, ’continuous-time systems’ refers to traditional In traditional Grafcet, the actions are normally ba-
control algorithms, which are sampled with a fixed, sic operations on simple data structures. There are ba-
fairly high, sampling rate. The discrete-time events sically two different types of actions: those performed
are assumed to happen less frequently, either ran- only once when the step becomes active, and those ex-
domly or regularly. Sequential controllers is an im- ecuted continuously while the step is active. Similarly,
portant class of discrete-time systems that are often the transition conditions are just simple tests. The be-
run together with continuous-time controllers, e.g. in havior of the Grafcet during execution is standardized
batch control. and quite straightforward.
The logic in a control system can be viewed as a By allowing more general expressions in actions and
discrete-time system interacting with the continuous- transition conditions, Grafcet becomes a powerful tool
time control algorithms. The logic appears at different for structuring more complex algorithms. However,
levels of the control system. On the signal level, the the simple rules for executing actions in a standard
logic may consist of range checks for measured sig- Grafcet must be altered in order to specify the be-
nals, control signal saturation, and other tests. In this havior of the extended Grafcet. The approach used in
context, these checks are randomly occurring discrete this paper allows every step to execute two different
events which interfere with the continuous algorithm. pieces of code, one initial action upon entry and one
They are primarily done with simple logic inside the continuous action while the step is active. In this case,
some properties of the process that can be used in
decisions later on.
C:{u = u+udot/h;}

(u>umax || abs(y)>ymax) 5 An example: Automatic PID tuning


C:{u = u-udot/h;} A scheme for automatic tuning of PID controllers will
now be modeled using the ideas from the previous
(u-u0<eps) section. The tuning procedure consists of a relay feed-
back experiment, followed by a small closed-loop step-
I:{u = u0;} response. The relay experiment will give the ultimate
period and gain, and the step response will give the
(stationarity(y)) static gain. This information is used to tune the con-
troller parameters according to the empirical rules
I:{prop = analyze(u,y);} based on dominant pole design presented in [Åström
and Hägglund, 1995].
The relay experiment consists of the following steps:
Figure 3. The Grafcet for a simple loop assessment 0. The operator has to make sure that the system is
experiment in steady state before starting the tuning experi-
ment.
“continuous” of course means that the action is exe- 1. Check the process output and the reference value.
cuted with a fixed sampling rate. Each sample, the If they differ too much, abort the tuning experi-
Grafcet behaves as follows: ment.
1. Fire all fireable transitions. 2. Freeze the control signal and estimate the mea-
2. For all steps becoming active in 1, execute their surement noise.
initial actions. 3. Set the relay hysteresis and the desired oscilla-
3. Repeat 1-2 until no more transitions may fire. tion amplitude.

4. Execute the continuous actions of all active steps. 4. Increase the relay amplitude until the output
reaches either of the crossing levels.
This behavior has a number of features that the
5. Set the sign of the process gain accordingly, if this
designer of the Grafcet must be aware of. At every
has not been given a priori.
sample, the algorithm above searches for stability,
i.e. a situation where no transitions can be fired. 6. Switch the relay, and wait for the process output
This is a potential danger, since it is possible to to change direction.
create, but often difficult to detect, situations where 7. Wait for the other crossing level to be reached.
all transitions in a loop are always fireable. Another
8. If there is a satisfactory oscillation, stop the tun-
feature of the execution algorithm is that the initial ing experiment, otherwise go to step 6.
actions may influence variables in the system, and
thus change the values of the transition conditions 9. Compute new controller parameters.
in the same sample. Continuous actions, on the other 10. If a refined tuning is desired, start the step re-
hand, may not cause these changes until the following sponse experiment, otherwise switch to automatic
sample. mode.
The behavior described above has been chosen since The optional step response experiment should do the
it is rather simple and straightforward, and yet pow- following:
erful enough for the applications that have been stud-
1. Close the loop with a preliminary PI controller
ied. It is not obvious, though, that this behavior is
obtained from the relay experiment.
desired in all possible applications.
A very simple example using C syntax in the ac- 2. Await stationarity.
tions and conditions is shown in Figure 3. The actions 3. Make a small step change in the reference value.
labeled I: and C: are initial and continuous actions, 4. Await stationarity
respectively. This part of the Grafcet models a possible
part of a loop assessment experiment. The process in- 5. Compute refined PID parameters and switch to
put u is increased until either u or the measured value automatic mode.
y reaches its maximum value. Then, u is decreased to The scheme above should probably be modified in
its initial value. When the process has reached sta- order to work for a larger class of plants, but it can be
tionarity, the function analyze is called. This returns used as an illustration of the modeling using Grafcet.
Manual

Init

Auto

Relay experiment

Abortion
recovery Tuning
Timed out. Preliminary
No oscillation. design

Step response
experiment

Figure 4. The main operating modes.


Final
design

The PID controller used in this example is on po-


sition form. It uses set point weighting on the pro-
portional term. Anti-windup is obtained by a track-
ing scheme as described in [Fertik and Ross, 1967].
The idea is to make the computed PID control signal
equal to the actual control signal being sent to the
plant. This is done by altering the value of the inter- Figure 5. Expansion of the tuning step.
nal state of the controller, i.e. the integral part. To
obtain both anti-windup and bumpless mode changes, loop step response. These steps are bypassed for the
the PID control signal and the state updating must be simpler methods. The tuning session ends with a
computed each sample in all modes. Thus, this com- calculation of the new controller parameters.
putation can be done in a continuously running proce- The Init step, expanded in Figure 6, initializes the
dure, independent of the current mode. The grafcet de- variables and checks the set point and noise level. If
scribed below only selects what control signal should the measured variable y is too far from the set point,
be used. the tuning experiment will be aborted by activating
The main modes (manual, auto and tuning) of the the exception handling in Figure 4. The noise level
controller, and the logic for switching modes is mod- is checked by keeping u constant and measuring the
eled by the Grafcet in Figure 4. The step labeled deviations of y from its nominal value during a fixed
Manual has a continuous action {u = uman;} to deter- number of samples. If information about the noise is
mine the control signal. The user may set the value of available, e.g. from a previous experiment, this step is
uman. Likewise, the Auto step has an action consisting bypassed. Finally, the relay hysteresis is set to twice
only of the statement {u = upid;}. The Tuning step the maximum detected noise amplitude.
is a macro step and will be described later. The chart for the relay feedback experiment is
The exception transitions to the left of the tun- shown in Figure 7. The first step has a continuous ac-
ing step are enabled during the whole tuning exper- tion that each sample increases the relay amplitude,
iment. This is a convenient way of doing exception and thus the control signal, by a constant factor. The
handling when the tuning experiment for some rea- following transitions wait for y to become larger than
son is aborted. This may for example happen if the the hysteresis level. If the gain sign is not set a pri-
user desires to go to manual or automatic mode while ori, the first switching of either level is detected by
tuning. the right transition, and the gain sign is set accord-
The expansion of the tuning step in Figure 4 is ingly. When the plant has right half-plane zeros, this
shown in Figure 5. The basic actions of the chart may cause problems, since y might initially go in the
are explained by the texts next to the steps. All wrong direction. By setting the gain-sign a priori, the
tuning sessions start by initializing and running a left transition will wait for the correct switching level.
relay experiment. For the refined tuning method, a The main part of Figure 7 consists of a loop which
preliminary design is calculated and used in a closed will switch the relay until a stable oscillation is es-
Increase relay amplitude,
Initialize variables wait for relay crossing

Setpoint
check
Set gain sign
Setpoint OK

Check noise level Set the control signal


and wait for maximum

Set relay hysteresis Maximum reached

Update relay
amplitude

Wait for relay crossing

Figure 6. Tuner initialization.


Switching level reached,
check oscillation status
tablished. The first step in the loop has two actions.
Continue Abort
Initially, the relay switches the value of the control
Tuning
signal. Then, the maximum deviation of y during the succeeded
new half period is recorded each sample. The follow-
Timed out.
ing transition is fired when the deviation of y has de- Too many
creased enough from its maximum value. After the oscillations.
peak has been detected, the step labeled Maximum
reached stores the amplitude.
The step Update relay amplitude becomes active
only after the third relay switch, and is by-passed oth-
erwise. The purpose of this step is to adjust the relay
amplitude in order to make the output oscillate with
Figure 7. The relay experiment.
a desired amplitude. The next step has no actions, but
just waits for its output transition to fire. This hap-
pens when y reaches the next crossing level. The last The step response experiment is straightforward
step in the loop stores the current half period time and and is not further discussed here.
determines the current oscillation status. This decides Going from the verbal description of the algorithm
which path to choose in the alternative branching. If to the Grafcet involves a few intermediate steps. A
there is a stable oscillation, i.e. the last oscillation suitable data structure must be chosen, and the algo-
peaks have been almost equal, the relay experiment rithm has to be described in detail using this struc-
has succeeded, and execution returns from this macro ture. A detailed specification will make the construc-
step. tion of the Grafcet easy, though there is still some non-
Two situations will abort the relay experiment be- uniqueness in choosing the Grafcet structure. Macro
fore it has succeeded. Firstly, when the relay has steps can be used for grouping the steps hierarchi-
switched too many times without any stable oscilla- cally into different phases of the algorithm. This is
tion, the lower right step in Figure 7 becomes active. especially useful when the exception handling behav-
Secondly, if the time between two consecutive switches ior is similar for a set of steps, as is the case for the
becomes too large, the exception transition in Figure 5 auto-tuner.
will fire. In both cases, the exception handling in Fig- The auto-tuner has been implemented and simu-
ure 4 will be activated. lated in G2 using the Grafchart toolbox [Årzén, 1994].
The control panel may look as in Figure 8. The slid- y (solid) and u (dashed)
0.1

0.05

PID 1 0

u man -1.0 1.0 −0.05

0.2 −0.1
yr -1.0 1.0 0 50 100 150 200 250 300 350 400 450 500
0.2
PID1, a pid-controller Figure 9. A tuning experiment for
Manual K 1.0 G(s) = e−10s /(2s + 1)3 .
Auto Ti 120.0
Td 0.0
Tune
Refined PID tuning
B 1.0
0.4

Design Method: 0.3

0.2
Ziegler-Nichols Refined PI
PI Refined PID 0.1
PID 0
Dead time Tuner settings
−0.1
0 50 100 150 200 250 300 350

Ziegler−Nichols method
0.4
Figure 8. The control panel of the controller PID1.
0.3

0.2
ers are used to set the manual control signal and set
point, respectively. The traditional PID parameters 0.1

are displayed to the right, and they may be edited 0

manually. The lower part contains buttons for selec- −0.1


0 50 100 150 200 250 300 350
tion of design method. The ones to the left only require
a relay experiment, whereas the refined methods also Figure 10. Response to a set point change and an
require a step response experiment. input load disturbance.
The simulation results of a typical tuning experi-
ment with both relay feedback and a step response are implemented as unconditionally rules, which
is found in Figure 9. The plant in the simulation has are executed regularly while the step is active. The
the transfer function G (s) = e−10s/(2s + 1)3 . Based transition conditions are treated in a similar way. The
on the tuning experiment a refined PID tuning is cal- rules may call G2 procedures written in the built-in
culated. Figure 10 shows the response to a set point pascal-like programming language.
change and an input load disturbance, both with pa- Grafchart together with the real-time simulator is
rameters from the refined PID method and Ziegler- a good environment for developing systems mixing
Nichols method. For this particular plant, the new continuous and discrete time activities. A drawback is
method obviously performs much better than Ziegler- that G2 is not well suited for hard real-time demands.
Nichols method. To meet this, routines have been developed in G2 to
translate the Grafcet into C + + code, which may be
6 Implementational issues executed in a real-time control system. This way, it is
possible to test the algorithms on a real plant.
G2 [Gensym, 1992] is a good tool for rapid real-
time software prototyping. It was originally used for
developing expert systems, but it has become useful 7 Conclusions
for other types of applications as well. It is fairly
easy to design graphical user interfaces using built- The example in Section 5 shows that Grafcet is a pow-
in tools. G2 also has a built-in real-time simulator, erful and intuitive modeling tool for systems mixing
which makes it easy to test control algorithms against pure algorithms with sequencing and logic. A good
a simulation of the plant. structure is obtained by the graphical representation
In the Grafchart toolbox, steps and transitions are of the logic, and the ability to perform advanced ac-
G2 objects, linked together by arcs. The actions are tions using ordinary programming languages.
written as G2 rules, which are placed upon the sub- We will continue to study new auto-tuning methods
workspaces of the steps. Initial actions are imple- and explore how the information given by the exper-
mented using initially rules, which are executed iments can be used. Grafcet will be used as a conve-
once when a step becomes active. Continuous actions nient tool for structuring these methods.
8 References
ÅRZÉN, K.-E. (1994): “Grafcet for intelligent super-
visory control applications.” Automatica, 30:10,
pp. 1513–1525.
ÅSTRÖM, K. J. (1993): “Autonomous process control.”
In Proceedings of The Second IEEE Conference on
Control Applications, Vancouver, British Columbia.
ÅSTRÖM, K. J. and T. HÄGGLUND (1995): PID Control.
Instrument Society of America, Research Triangle
Park, North Carolina.
DAVID, R. and H. ALLA (1992): Petri Nets and
Grafcet: Tools for modelling discrete events sys-
tems. Prentice-Hall International (UK) Ltd.
FERTIK, H. A. and C. W. ROSS (1967): “Direct digital
control algorithms with anti-windup feature.” ISA
Trans., 6:4, pp. 317–328.
GENSYM (1992): G2 Reference Manual, Version 3.0.
Gensym Corporation, 125 CambridgePark Drive,
Cambridge, MA 02140, USA.

Das könnte Ihnen auch gefallen