4.1. Programmable Logic Controllers
PLC is used in many industrial and infrastructure systems to monitor input sensors and control actuators [1]. PLCs are, essentially, digital computers mainly used for automation of electromechanical processes. They have the capability of continuously monitoring several sensors through their inputs and generate output signals based on software to control many devices.
Moreover, PLCs are known to be resistant to unfavourable conditions, such as mechanical vibrations, dust, moisture or high temperatures. These characteristics make them very suitable to be used in an industrial environment or even in extreme situations, for example, inside Wave Energy Converters or in the ELT in Chile’s Atacama Desert.
A PLC is a hard real-time system [2]. That means that there is a very short time window between reading the inputs and producing the corresponding outputs. All PLCs have a common standard architecture, which can be extended or upgraded to accomplish the project objectives. Figure 5 shows the PLC architecture. In this figure, we observe that the PLCs have both ROM and RAM memory. The ROM is used to store data related to the PLC operative system or configuration values that must be permanently saved. While the RAM memory is used to read the inputs and write the output values, also stores data variables from the CPU’s running software.
Figure 5. PLC standard architecture
Moreover, this system has a CPU element where the program to be executed is loaded.
This software is executed in a loop, which includes five main steps (see Figure 6). First, the inputs are detected and checked. Then, the CPU is checked to ensure that the configuration loaded is valid. Next, the input values are read. When the inputs have been collected, the program logic is executed. This program logic, taking into account the inputs, would decide how the outputs are updated.
This control loop is executed at a high frequency, typically between 1 kHz and 4 kHz. That means that all the code loaded in the CPU should be executed in less than 1ms. This feature makes developing software for a PLC slightly different than developing for a conventional computer. The execution of the PLC cycle cannot be paused by any means;
this must be considered with typical I/O operations such as opening an external file.
Methods to handle these situations would be further discussed in this document.
Figure 6. PLC cycle
4.2. Beckhoff PLCs
Beckhoff is a German company working in the automation technology products. They develop several PLC models, also many modules to be integrated with them. These PLCs stand out for including Windows 7/10 in addition to the classical CPU control cycle. The Window’s distribution is named IoT, and it is specially optimized for real time features.
Moreover, Beckhoff has also created TwinCAT, software for programming, configuring, diagnosing, simulating and debugging code for PLCs. It is a very powerful tool that covers all the needs along the PLC software developing process. It also includes extensions to monitor data, TwinCAT Scope View, and to create user interfaces, TwinCAT HMI.
These products have been used in multiple projects such as the IRAM 30m telescope1, the SLAC National Accelerator Laboratory2 or in the CorPower3 wave energy converter.
4.3. PLC Programming
The programming languages PLCs can be found in the IEE61131-3 standard [11]. There a total of five programming language standards defined:
• Ladder Diagram: Was the first standard for PLC programming, it is a graphical representation of relay contact logic [4].
1 IRAM 30m telescope project: https://www.iram-institute.org/EN/30-meter-telescope.php
2 SLAC National Accelerator laboratory: https://www6.slac.stanford.edu/
3 CorPower: https://www.corpowerocean.com/
1.- Start Scan
2.- Internal Checks
3.- Scan Inputs 4.- Execute
Program Logic 5.- Update
Outpues
• Function Block Diagram: It is also a graphic language that includes standard logical functions as well as timers, triggers or counters.
• Structured Text: It is a high-level programming language, including functions, conditionals, loops and several data types. It also has some OOP features like inheritance [3].
• Instruction list (currently deprecated): It is a low-level textual language, like assembly. Consists of sets of simple instructions.
• Sequential Function Chart: Graphic language that involves states, transitions and actions.
Despite being different programming languages for PLCs, all of them have common elements which are the pillars of PLCs software development. These elements are the following ones:
• Tasks: A task is assigned to one of the PLC’s cores. It runs cyclically executing a block of code. The software loaded into a PLC can contain multiple tasks, each one with its frequency of execution and its priority. They run as separate programs and do not communicate between them.
• Program Organisation Unit (POU): POUs are code containers that have two main parts: the declaration of the variables used (header) and the algorithmic behaviour (body). POUs can be written in any of the five languages mentioned before.
Moreover, POUs can be defined as Function Blocks or as Programs.
• Function Block: They are like Classes in other languages such as Java or C++.
They contain several variables, either native data types or instances of other Function Blocks, and they can have multiple methods, including a constructor method that would be triggered whenever an instance of the class is created.
Moreover, they support inheritance and encapsulation.
• Programs:. They are formed by the header and the body. The body is the main execution program. In the header, several function blocks can be declared, so their methods are used in the program’s body. Programs are usually referenced to a task, so they are executed cyclically inside it.