<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Complexity- and Performance Analysis of Different Controller Implementations on a Soft PLC</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Robert Feldmann</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
          <xref ref-type="aff" rid="aff4">4</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Textual</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
          <xref ref-type="aff" rid="aff4">4</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Graphical</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
          <xref ref-type="aff" rid="aff2">2</xref>
          <xref ref-type="aff" rid="aff4">4</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Implementation language IEC 61131-3 /Structured Text (ST) C</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Nature of language Textual</institution>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Real-Time-Workshop (RTW, Simulink) CFC Code Generator [3]</institution>
        </aff>
        <aff id="aff3">
          <label>3</label>
          <institution>TUM - Technical University Munich</institution>
        </aff>
        <aff id="aff4">
          <label>4</label>
          <institution>Technion - Israel Institute of Technology</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>Whenever code for a Programmable Logic Unit (PLC) is generated using a model based approach there are multifarious possibilities for possible code generators. In order that the generated code is changeable and maintainable the code should have a low complexity. A high complexity complicates by hand changes that become necessary when the code generator is not available as well as it is a reason for high maintainability costs in general [1]. My research is the first to present an approach to compare between PLC implementations generated by different generators in terms of complexity using the example of a paper machine controller. Additionally the performance of the implementations is investigated and a preliminary evaluation of the generators selected is given.</p>
      </abstract>
      <kwd-group>
        <kwd />
        <kwd>Model-driven Engineering</kwd>
        <kwd>IEC 61131-3</kwd>
        <kwd>PLC</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        Model-driven engineering is becoming increasingly popular, especially in the
automotive domain, as it can shorten the development time by as much as 50% [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. In
model-driven engineering a model is created based on requirements. These models
are created with the aid of mostly graphical, dataflow-oriented languages such as
Simulink. Other than in the classical software development process the code is
automatically generated from the model with the aid of code generators.
      </p>
      <p>The concept of model-driven engineering is presently also used in the PLC
domain. PLCs are appliances used for the automation of technical processes.
Programming PLCs is based on the IEC 61131-3 standard, which includes different languages.
Code generators for many PLC compatible languages have become available over the
last years; three of them can be found below:</p>
      <p>C and CFC are both not included in the original IEC 61131-3 standard, but are
suited as well and can be regarded as quasi standards.</p>
      <p>Programmers that have to implement a model-based PLC application and wish to
apply the concept of Model-driven engineering consequently have to choose between
3 distinct code generators that produce 3 implementations in different languages.</p>
      <p>The aim of this research is to provide recommendations for which code generator
is best. In a showcase, controller implementations in the three languages listed above
are generated from a model of a paper machine controller. The implementations are
then investigated and compared with regard to complexity and performance on a soft
PLC. The conceptual approach is depicted in Fig. 1:
This is the first work to compare among various PLC based implementations
generated from the same model.</p>
      <p>
        Prior work mainly deals with the quality assessment of standard computer
software, but does not explore characteristics of Model-driven engineering or the PLC
domain. [
        <xref ref-type="bibr" rid="ref4 ref5 ref6 ref7 ref8">4–8</xref>
        ] give an excellent overview about the fundamentals of software quality
assessment.
      </p>
      <p>
        [
        <xref ref-type="bibr" rid="ref10 ref11 ref9">9–11</xref>
        ] adapt the concepts presented in the literature above to the specific needs of
Model Based Engineering. [
        <xref ref-type="bibr" rid="ref12 ref13 ref14">12–14</xref>
        ] include methods to assess the quality of software
in the PLC domain.
      </p>
      <p>
        This research especially builds upon [
        <xref ref-type="bibr" rid="ref10 ref12 ref8">10, 12, 8</xref>
        ], since the findings of these
publications enable comparison of implementations in different programming languages.
3
      </p>
    </sec>
    <sec id="sec-2">
      <title>Approach and Uniqueness</title>
      <p>The implementations were generated using a Simulink model of a paper machine
controller. The model itself has no subsystems and uses 6 different kinds of blocks:
Discrete PID controller, discrete transfer function, transport delay, sum, step and
outport. There are two input signals and four output signals. Compressed in a subsystem
the model looks as follows:</p>
      <p>Delivering this subsystem as an input to the three code generators returns three
implementations: The C-Code, ST-Code and the CFC block diagram are now subject to
the following evaluation.</p>
      <sec id="sec-2-1">
        <title>Complexity analysis.</title>
        <p>
          Measuring software quality in general implies using software metrics [
          <xref ref-type="bibr" rid="ref15">15</xref>
          ]. Metrics
are algorithms that map an attribute of a program, such as ‘complexity’, on a
numerical scale. Several metrics to measure complexity have been published. The following
table shows 3 complexity metrics that are suited for the application on automatically
generated PLC-based implementations:
        </p>
        <sec id="sec-2-1-1">
          <title>Complexity metric</title>
        </sec>
        <sec id="sec-2-1-2">
          <title>Lines of Code McCabe Halstead</title>
        </sec>
        <sec id="sec-2-1-3">
          <title>Application in</title>
          <p>
            the style of
[
            <xref ref-type="bibr" rid="ref8">8</xref>
            ]
[
            <xref ref-type="bibr" rid="ref10">10</xref>
            ]
[
            <xref ref-type="bibr" rid="ref12">12</xref>
            ]
          </p>
        </sec>
        <sec id="sec-2-1-4">
          <title>Adaptability to tex</title>
          <p>tual languages


</p>
        </sec>
        <sec id="sec-2-1-5">
          <title>Adaptability to</title>
          <p>graphical languages


</p>
          <p>
            LOC measures the number of code lines. It can be applied on both the ST- and
CCode, but naturally cannot be applied on the CFC block diagram. Like many
complexity metrics, the LOC metric is not clearly enough defined. Therefore the version
described in [
            <xref ref-type="bibr" rid="ref8">8</xref>
            ] is going to be applied, which also allows intercompability between
different programming languages.
          </p>
          <p>
            The McCabe metric measures the cyclomatic complexity. It is based on the control
flow graph of a program and determines the linear independent paths through the
graph. In this research the cyclomatic complexity is calculated according to [
            <xref ref-type="bibr" rid="ref10">10</xref>
            ],
which builds upon the original definition of the McCabe metric [
            <xref ref-type="bibr" rid="ref16">16</xref>
            ], but extends it
such that it is applicable to graphical languages such as CFC.
          </p>
          <p>
            The original Halstead metric [
            <xref ref-type="bibr" rid="ref17">17</xref>
            ] is based on the lexical structure of a program.
Starting from the partitioning of the lexical elements into different operands and
operators, the program volume can be calculated as a measure for complexity. [
            <xref ref-type="bibr" rid="ref12">12</xref>
            ]
adapted this metric such that it can also be applied to graphical languages such as
CFC.
          </p>
        </sec>
      </sec>
      <sec id="sec-2-2">
        <title>Performance.</title>
        <p>To measure performance, the three controller implementations are integrated into
the programming environment TWINCAT 2.11, compiled into a Soft PLC and their
time response are simulated. It is desirable that the implementation time response is
close to the time response of the model, because the more alike the time responses
are, the better one can estimate the performance of software in advance. Therefore the
time response of the model is also measured and compared to the implementations.</p>
        <p>As an input a unit jump was impressed on the entries and received the step function
response at the exits. The duration of record was 2000 data points or 2000 seconds at
a step time of 1 second.
4</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Results and Contributions</title>
      <sec id="sec-3-1">
        <title>Complexity.</title>
        <p>Applying the presented metrics on the three implementations of the paper machine
model delivers the following results:</p>
        <p>Metric
ST-Code
C-Code</p>
        <p>CFC</p>
        <p>LOC
238</p>
        <p>According to the LOC metric the ST code performs better than the implementation
in C because it requires fewer lines of code. The CFC block diagram has the lowest
value for cyclomatic complexity (McCabe) and program volume (Halstead). The
implementation in CFC should therefore be clearly preferred with regard to complexity.</p>
      </sec>
      <sec id="sec-3-2">
        <title>Performance.</title>
        <p>While the implementations in C and ST do not show significant differences
between the model, the time response of the CFC block diagram clearly differs from that
of the model, which can be seen on the basis of the error depicted in Fig. 3:</p>
        <p>To quantify this discrepancy the error in least squares sense was calculated:
implementation</p>
        <p>CFC
0.03775</p>
        <p>ST
8.0666E-15</p>
        <p>C
0</p>
        <sec id="sec-3-2-1">
          <title>Model</title>
          <p>0
(as ref.)</p>
          <p>The implementations in C and ST clearly perform the best, as the error function
(nearly) equals zero. The performance of the CFC block diagram clearly is the worst
in this assessment. Different execution orders of the Simulink and the CFC blocks are
a likely reason for that.
5</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Conclusion &amp; Future Work</title>
      <p>This research presented an approach for the quality assessment of three different
automatically generated controller implementations on a PLC. By Assessing
complexity and performance of the implementations of the paper machine controller my
work shows that Continuous Function Chart performs best in terms of complexity,
whereby the implementations in C and ST have the best time response. What was
showed exemplarily on a medium sized model with 60 blocks should also be done
with other kinds and sizes of models to help validate my findings and extend it to a
broader range of models.</p>
      <p>Acknoledgements. I would like to thank Lindsay Bauer (Manhattan, New York City)
for her patience and gratitude to revise my paper and giving me excellent advice on
how to express my ideas.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Banker</surname>
            <given-names>RD</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Datar</surname>
            <given-names>S</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kemerer</surname>
            <given-names>C</given-names>
          </string-name>
          et al. (
          <year>1993</year>
          )
          <article-title>Software Complexity</article-title>
          and
          <string-name>
            <given-names>Maintenance</given-names>
            <surname>Cost</surname>
          </string-name>
          .
          <source>Communications of the ACM</source>
          <volume>36</volume>
          (
          <issue>11</issue>
          ):
          <fpage>81</fpage>
          -
          <lpage>94</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Pohlheim</surname>
            ,
            <given-names>H. Stürmer I. Salecker E.</given-names>
          </string-name>
          (
          <year>2012</year>
          )
          <article-title>Ein Ansatz zur Qualitätsbewertung von modellbasierten Entwicklungsprojekten eingebetteter Software. 8. DagstuhlWorkshop Model-Based Development of Embedded Systems (MBEES</article-title>
          <year>2012</year>
          ):
          <fpage>11</fpage>
          -
          <lpage>20</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Bayrak</surname>
            <given-names>G</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Renzhin</surname>
            <given-names>D</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vogel-Heuser</surname>
            <given-names>B</given-names>
          </string-name>
          (
          <year>2011</year>
          )
          <article-title>Integration of control loops in an UML based engineering environ-ment for PLC. Emerging Technologies and Factory Automation (ETFA)</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Fenton</surname>
            <given-names>NE</given-names>
          </string-name>
          (
          <year>1991</year>
          )
          <article-title>Software metrics: A rigorous approach</article-title>
          . Chapman &amp; Hall, London [etc.]
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Fenton</surname>
            <given-names>NE</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pfleeger</surname>
            <given-names>SL</given-names>
          </string-name>
          (
          <year>1997</year>
          )
          <article-title>Software metrics: A rigorous and practical approach, 2nd edn</article-title>
          .
          <source>PWS Pub</source>
          , Boston
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Hoffmann</surname>
            <given-names>DW</given-names>
          </string-name>
          (
          <year>2008</year>
          ) Software-Qualität. Springer, Berlin and and Heidelberg
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Oman</surname>
            <given-names>PW</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pfleeger</surname>
            <given-names>SL</given-names>
          </string-name>
          (
          <year>1997</year>
          )
          <article-title>Applying software metrics</article-title>
          . IEEE Computer Society Press, Los Alamitos and Calif
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Thaller</surname>
            <given-names>GE</given-names>
          </string-name>
          (
          <year>2000</year>
          )
          <article-title>Software-Metriken: Einsetzen, bewerten, messen, 2nd edn</article-title>
          .
          <source>Verl. Technik</source>
          , Berlin
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Thomsen</surname>
            <given-names>T</given-names>
          </string-name>
          (
          <year>2012</year>
          )
          <article-title>MISRA C und seine Anwendbarkeit auf Seriencodegeneratoren</article-title>
          . http://www.dspace.de/ftp/papers/dspace_El25_0312_d_f28.pdf
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Prabhu</surname>
            <given-names>J</given-names>
          </string-name>
          (
          <year>2010</year>
          )
          <article-title>Complexity Analysis of Simulink Models to improve the Quality of Outsourcing in an Automotive Company</article-title>
          . http://alexandria.tue.nl/extra1/afstversl/wsk-i/prabhu2010.pdf
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Kabra</surname>
            <given-names>A</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Karmakar</surname>
            <given-names>G</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Joseph</surname>
            <given-names>J</given-names>
          </string-name>
          (
          <year>2012</year>
          )
          <article-title>ST to MISRA-C Translator and Proposed Changes in IEC 61131-3 Standard</article-title>
          .
          <source>International Journal of Information and Electronics Engineering</source>
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <surname>Stürmer</surname>
            <given-names>I</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pohlheim</surname>
            <given-names>H</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rogier</surname>
            <given-names>T</given-names>
          </string-name>
          (
          <year>2010</year>
          )
          <article-title>Berechnung und Visualisierung der Modellkomplexität bei der modellbasierten Entwicklung sicherheits-relevanter Software</article-title>
          . Automotive - Safety &amp; Security: S.
          <fpage>69</fpage>
          -
          <lpage>82</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>Christian Staron</surname>
          </string-name>
          (
          <year>2004</year>
          )
          <article-title>Entwicklung eines Analysewerkzeugs zur Ermitt- lung von Metriken und Qualitätskriterien sicherheitsrelevanter Software im Maschinenschutz, Fachhochschule Bonn-Rhein-Sieg</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <surname>Krell</surname>
            <given-names>M</given-names>
          </string-name>
          (
          <year>2003</year>
          )
          <article-title>Bestimmung von Qualitätskriterien für sicherheitsrelevante Software im Maschinenschutz auf Basis von zertifizierten Industrieanwendungen, Fachhochschule Bonn-Rhein-Sieg</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>15. ISO 9126</mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16.
          <string-name>
            <surname>McCabe</surname>
            <given-names>T</given-names>
          </string-name>
          (
          <year>1976</year>
          )
          <article-title>A complexity measure</article-title>
          .
          <source>IEEE Transactions on Software Engineering SE-2</source>
          (
          <issue>4</issue>
          ):
          <fpage>308</fpage>
          -
          <lpage>320</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          17.
          <string-name>
            <surname>Halstead</surname>
            <given-names>MH</given-names>
          </string-name>
          (
          <year>1977</year>
          )
          <article-title>Elements of software science</article-title>
          .
          <source>Operating and programming systems series,</source>
          vol
          <volume>2</volume>
          .
          <string-name>
            <surname>Elsevier</surname>
          </string-name>
          , New York u.a
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>