Mini Project #2: PLC Programming with
Ladder Logic
CS 6263/ECE 8813: Cyber Physical System Security (Summer 2020)
Assigned: June 3rd, 2020 Due: June 17th, 2020, 11:59pm EST
Ladder Diagram (LD)
In the second mini project, we will write PLC programs to control different real-world
systems. The programs will be written in the Ladder Diagram (LD) format which is the
most popular language for writing PLC programs. Other formats for PLC programming
are: Structured Text (ST), Function Block Diagram (FBD), Instruction List (IL), and
Sequential Function Chart (SFC). Many early PLCs did not have accompanying program-
ming terminals that were capable of graphical representation of the logic, and so the logic
was instead represented as a series of logic expressions in some version of Boolean format,
similar to Boolean alge
a. As programming terminals evolved, it became more common
for ladder logic to be used, for the aforementioned reasons and because it was a familia
format used for electro-mechanical control panels. Newer formats such as state logic and
Function Block (which is similar to the way logic is depicted when using digital integrated
logic circuits) exist, but they are still not as popular as ladder logic. A primary reason fo
this is that PLCs solve the logic in a predictable and repeating sequence, and ladder logic
allows the programmer (the person writing the logic) to see any issues with the timing of
the logic sequence more easily than would be possible in other formats.
OpenPLC
Instead of using a real PLC, we will use an open source PLC emulator called OpenPLC
to do the programming. The performance of the programs will be evaluated in simulated
environments representing the behavior of real-world processes. The OpenPLC is the first
fully functional standardized open source PLC, both in software and in hardware. In fact,
OpenPLC is an alternative program which simulates the behaviours and capabilities of
eal PLCs with the help of simple and low-cost hardware such as Arduino or Raspbe
y
Pi. The focus of this software is to provide a low cost industrial solution for automation
and research. OpenPLC has also been used in many research papers as a framework fo
industrial cybersecurity research, given that it is the only controller to provide the entire
source code. Once you learn how to work with OpenPLC, you can easily pick up how to
program real PLCs of different vendors.
1
Mini Project #2 PLC Programming with Ladder Logic
Ladder Logic, though is different from mainstream coding languages, is very easy to pick
up. Here are a few tutorials on ladder logic to get you started: Tutorial 1, Tutorial 2. You
can also find a lot of tutorials in YouTube and Google. Note that there is no limitation on
the methods you can use in the following sections unless it is explicitly mentioned in the
write-up. For example, you can use any number of ladders and rungs you need in you
program. It should be also noted that since we will use an autograder for this project,
you must use the predetermined names of the inputs and outputs in your program (please
see Appendix for more detailed information). This is highly important because even if
your logic is 100% co
ect and you don’t use the predetermined memory addresses for the
inputs and outputs, the autograder will return full/partial points deduction. Failure to
follow this instruction will lead to significant points loss (ZERO) in your final grade. We
will NOT accept any excuses for naming mistakes. You MUST triple check the names
efore submission!
OpenPLC Setup – Writing and Testing Programs
In this section, we will explain how you can set up the project environment, write the
equired programs, and test them in the provided simulators. As the first step, please
follow the below instructions to download and set up the environment containing all of
the tools required to complete this project:
1. We have provided a Virtual Machine (Ubuntu) completely tailored for this mini
project. All of the required li
aries have already been installed on it and every tool
has been tested to perform as best as possible. You can use VirtualBox, VMware
Workstation (for Windows users) or Parallels Desktop (for MAC users) to use this
VM. First download the VM files located here (.ova format) and move them to you
desired location on your personal machine. Use VirtualBox (version 6.0 or later) o
Parallels Desktop (version 15 preferably) to open the downloaded VM. You can open
the VM in by clicking on the .vbox file or importing the .ova file directly in you
hypervisor. Do not forget that these files are your actual virtual machine
and deleting them from your personal computer will result in losing all
of your work. We strongly recommend saving your written programs in
cloud environments such as Google Drive so that in the case of failure in
the VM, you can resume your work with minimum issues on a fresh VM.
2. A user (username: cs6263 and password: Project2) has been created for you.
Please refer to this credential in case you need it or if you need to use the “sudo”
command. Open a terminal and navigate into the “OpenPLC v3” folder. Run the
OpenPLC server by typing the following command
sudo ./start_openplc.sh
The OpenPLC server should be running now and you can open Firefox and visit
http:
localhost:8080 to access it. This platform provides you with a PLC simulated
environment in which you can upload and run your PLC program like a real PLC.
Georgia Institute of Technology 2 Introduction to CPS Security (CS 6263)
https:
www.youtube.com/watch?v=Y1yD7aoUmOo
https:
www.youtube.com/watch?v=xpTBpFHyluw&list=PL9eN6-TpvPMVA7h3QK6LNct2xND-ZcnHp
https:
gatech.box.com/s/ok03lt8s7l8uohf7th54t4av9n0dtieg
http:
localhost:8080
Mini Project #2 PLC Programming with Ladder Logic
In fact, the server will act as the hardware for the PLC program that will run
your written program and communicate with a physical process (simulator in this
project). Once you verified that the OpenPLC works fine on the VM, you can kill
the process and start writing the PLC program as explained in the following steps.
Note that you will later use this OpenPLC server for testing the written programs
in parts 2, 3, 4, and 5.
3. Now it is the time to write your PLC programs. You can navigate to the Linux
application directory or “/Desktop/OpenPLC Editor v1.0-Linux” directory and run
sudo ./OpenPLC_Edito
openplc_editor.sh
to write logic for the OpenPLC program. To start, you should create an empty
folder for each part separately and choose that directory for that part. This link
can help you to learn how to start programing in the IDE. Please do not touch the
.Config settings (i.e., task0, Cyclic, T#20ms, Priority 0, instance0). For a list of
input/output pin definition, see the Appendix. Note: If the OpenPLC Edito
uns slowly in the VM, you can install it on your host machine and then
move the written programs to the VM for evaluation purposes. Please
see here for more information.
4. You can easily test the performance of the written program using the run button
within the IDE. You can choose the items to be shown in the Debugger tab by
selecting them with the glasses icon in the left side of the screen. By right clicking
and enforcing the values of inputs, you can see the effect of different inputs on
outputs in the Debugger tab.
5. After running and testing your program, the XML and .ST versions of the program
can be found in the relevant directory (XML is named plc.xml in the main directory
and .st is in the build directory with the name of generated plc.st). Note that you
need to create separate folders for each part and subpart. For testing parts 2, 3, 4,
and 5, you should upload the relevant .ST file into the server as described in here.
Verify that the page says “compiled without e
ors”. Please remember that you need
to follow the naming instructions in Deliverables and Submission Instructions
section. A schematic diagram of the relationship between .st file and the server has
een shown in Fig. 1.
6. For Part 1 of this Mini Project, you need to test the logic of your program using the
editor, but for the Parts 2-5, very useful HMIs have been developed and are provided
in the VM. item (for part 2 & 3) You can use the directories /Desktop/Process-
Simulato
RoboPath and /Desktop/ProcessSimulato
TrafficLight directories and
un
python ProcessSimulator.py
to start the HMIs associated with these parts of the project. Please note that the
HMI needs to be launched after the OpenPLC server is running using the .st file you
Georgia Institute of Technology 3 Introduction to CPS Security (CS 6263)
https:
www.openplcproject.com
eference-your-first-project
https:
openplcproject.com/plcopen-edito
https:
www.openplcproject.com
eference-uploading-your-project
Mini Project #2 PLC Programming with Ladder Logic
Figure 1: The overall overview of the program design and test in the OpenPLC platform.
generate from the OpenPLC GUI. If you need to restart the server by uploading a
new PLC program, please close the HMI before uploading, and relaunch it after the
server is running again.
7. (for Part 4 & 5) You can do the same as what you did for parts 2 and 3 by going
through each process’ directory (i.e., /Desktop/ProcessSimulato
TankSystem o
Desktop/ProcessSimulato
Sti
ingSystem) and run the process simulator with
.
un.sh
and the HMI file with
python hmi.py
You can also use the UaExpert software. In the /Desktop/UaExpert folder, double
click “UaExpert XXXXXXXXXXx86 64.AppImage” (in GUI) or by typing the following
command in Terminal
./UaExpert XXXXXXXXXXx86_64.AppImage
to start the software. Then, open the pre-configured “Sti
ingSystem.uap” or “TankSys-
temMonitor.uap” file to start monitoring the I/O values in real time. The values of
Georgia Institute of Technology 4 Introduction to CPS Security (CS 6263)
Mini Project #2 PLC Programming with Ladder Logic
interest have already been added to the “Data access view”. You may also leverage
this software to manually set the input and test your program. In this case, the
simulator does not need to be running.
Georgia Institute of Technology 5 Introduction to CPS Security (CS 6263)
Mini Project #2 PLC Programming with Ladder Logic
1 Part 1 (25 Points)
Construct three different Ladder Logic programs, each building on the previous one:
1.1 Part 1A (5 Points)
Construct a program that will simulate a push button activated LED. The program should
satisfy the following requirements:
1. When Input0 is activated, Output1 should activate;
2. When Input0 is deactivated, Output1 should deactivate;
3. Inversely, when Input1 is activated, Output0 should deactivate;
4. When Input1 is deactivated, Output0 should activate.
Note: Input0 and Input1 are not push buttons. For example, Output1 should
e active as long as the Input0 is active. To be more clear, Input0 and Input1
are like light switches, i.e., you should use simple contacts for them.
1.2 Part 1B (10 Points)
Construct a program that simulates an LED powered by an On-Off loop. Program re-
quirements:
1. When Input0 is activated