Twistturn is a development and execution environment for programs written in PLC-common programming languages. It makes use of RTAndroid’s predictable process behavior and provides PLC developers the possibility to write or modify an existing PLC program and immediately execute it on the same device. Furthermore, Twistturn introduces additional components for rapid prototyping and a comfortable workflow:
- Development and editing tools (Structured Text, IEC 61131)
- Simulation of declared inputs and outputs
- Execution of the PLC program in real-time mode
- Communication to external hardware components
Currently, Twistturn supports the Structured Text programming language, which is one of the languages specified in the wide-spread automation standard IEC 61131-3. The architecture was designed in a flexible way to be easily extendable with other languages common in automation industries such as Instruction List, but also Function Block Diagram and Ladder Diagram. These languages are structurally different and would require another interpreter or compiler to deal with the input code. This issue is solved by designing an intermediate representation of the program, before the corresponding C++ code is generated. The code created with the Twistturn editor is automatically executed with real-time priority on RTAndroid. The details of this process, which are depicted below, include the automatic generation of equivalent C-code, which is then compiled on the device. Finally, the binary file is executed in a dedicated process in real-time mode.
- Import and creation of new source files and POUs
- Organization of multiple source files using projects
- Editor for ST with syntax highlighting
- Creation and configuration of peripheral hardware
Twistturn is able to visualize all input and output variables during runtime. If declared accordingly, the values of variables used in the PLC program can be edited on the user interface while being executed in real-time.
For monitoring and controlling applications, Twistturn requires an interface to interact with external hardware. Unfortunately, modern mobile devices typically do not provide any digital or analog I/O connectors. The available interfaces are limited to default audio and video outputs in combination with an USB port. To overcome this disadvantage we developed a microcontroller-based adapter for connected field devices. It provides a rich set of general purpose digital and analog I/O pins, which can be addressed by the tablets through a full speed USB 2.0 connection, for reading the current state of the sensors or for influencing actuators. The main task of this adapter is receiving commands from the running application and executing them accordingly. The adapter itself can be flexibly configured at any time from the Twistturn application without the need of re-flashing the firmware. It does not contain any program-related logic.
Following types of field devices are currently supported: input or output at one of the 54 digital pins, analog input using one of 16 10-bit ADCs and analog output using one of 15 8-bit PWM generators. The configuration is project-specific and is performed via a graphical user interface.
The following figure shows a configuration fragment with one input and one output using different digital pints. The left column shows the properties of configured devices like the variable name and the associated hardware pin.
Twistturn automatically generates shared memory addresses, where the data from external hardware is mapped to. These addresses may be used in ST to declare located variables with symbolic representation. The following listing contains a simple example based on the example configuration showed above.
VAR button AT %I0.1.0 : BOOL; output AT %Q0.2.0 : BOOL; END_VAR output := NOT( button );
Using located variables pointing to the given memory addresses, this program snippet activates the digital output at pin D20 if the corresponding button at pin A05 is not pressed. The project configuration is automatically loaded to the connected device adapters upon the start of the background service, before execution of the original program. During the execution, a periodic trigger refreshes the input values from the external hardware and writes output values accordingly.
A small-scale Fischertechnik industrial automation plant can easily be controlled by Twistturn and RTAndroid. This setup can serve as an low-cost educational platform for writing PLC code for realistic real-world automation scenarios.
We build the Kugelmaschine to demonstrate RTAndroids suitability for real-time demanding applications. The machine is able to sort balls into six different categories based on their colors. The machine sorts the balls while free falling with the help of compressed air. Due to the fact that the pressure valve has to be activated and deactivated with sub-millisecond precision in order to achieve correct sorting, the correct functioning of the system depends on strict and reliable real-time capabilities of the control system.