Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ravensburg Weingarten
Project Documentation
Design and Evaluation of PID Controller on
Arduino Platform
SS 2019
Name Matriculation Number
Mohammad Faizan 27889
Muhammad Abdullah Tarar 27895
Danial Kaleem Ahmed 27897
Submitted to
Prof. Dr.-Ing. Lothar Berger
Under Supervison of
Manfred Kern
1
INDEX
1 Chapter 1 Introduction……………………………………………………………………………………….…..3
1.1 Objective ..……………………………………………………………………………………………………..3
1.2 Hardware/Software Requirements………………………………………………………………….3
1.3 Controllino Maxi Automation…...…………………………………………………………………….4
2
Chapter 1
Introduction
1.1 Objective
The primary goal of the project was to design and evaluate a PID controller on Arduino
software and Controllino as PLC Hardware. Then see how well the Controllino perform in
comparison to Moeller Compact SPS in Control engineering lab. Controllino is a low cost
solution to Moeller SPS which in fact was implemented successfully in our project. During
this phase , we in addition also added the behavior of P and PI Controller and their Matlab
Simulation for compare their results to see effectiveness of Matlab Automated Tuning in
real Control environment . Last but not the least, PID was programmed on Arduino using
three different ways, one with library, one without library , and one with integral and
derivative time constants.
3
1.3 Controllino Maxi Automation
Controllino Maxi can be used as low cost PLC and it is fully integrated into Arduino platform.
4
Chapter 2
Hardware/Software Setup
2.1 Controller and Controlled System (Hardware)
The Controller Output from Analog Out pin AO0 (0 -10V) is connected to Y input to PT3
System. The output X from the PT3 System is connected to Analog Input pin AI12 (0 -10V).
The button is connected to digital input pin DI0. The connections for button and power
Supply are not shown for simplicity. The set point was set virtually in the software to 5V.
The controller was connected to the PC using a USB cable.
Figure 2: Controller
5
2.2 Software Integration
The required library is CONTROLLINO which can be installed directly from library manager of
Arduino. After installation, go to File- Preferences and add the following link as shown to the
Additional Board Manager.
https://raw.githubusercontent.com/CONTROLLINO-PLC/CONTROLLINO_Library/
master/Boards/package_ControllinoHardware_index.json
Figure 4
Afterwards Controllino Board can be installed directly from Board Manager of Arduino IDE.
An interface between MegunoLink and Arduino was created. Meguno Link is graphical tool which
uses data from the Arduino to plot accurate graphs in real time.
6
Chapter 3
Tuning the Controller
3.1 General PID Equation
The following figure shows the PID equation in parallel form.
Figure 5
7
3.2 Software Scaling for 5V set point
The analog input AI12 (0- 10V) to the Controllino is converted by ADC and then read by the
microcontroller with the resolution of 10 bits (0- 1023). The analog input was converted
into 8 bits by dividing the Controller input by 4
Input = analogRead(CONTROLLINO_AI12);
Input =Input/4;
This was necessary because our Controllino has Output resolution of 8 bits 0- 255 which
means at 255 the analog Output provides the maximum value of 10V. Therefore, the set
point was calculated as 128.
8
Figure 6
3. Measure the ultimate (or critical) period Pu of the sustained oscillations. From the
above figure time period average was taken over several oscillations which was
found to be 5s.
4. Calculate the controller parameter values according to the following table , and use
these parameter values in the controller.
9
The following figure shows the result after implementing the parameters on the controller.
Figure 7
Note that although the controlled variable reaches set point but are some oscillations which
can be removed by using the No Overshoot parameters of Ziegler Nichols according to the
following table.
The new parameters are Kp= 0.86, Ki= 0.344 and Kd= 1.44
10
The following figure shows the results with no overshoot method.
Figure 8
11
Chapter 4
Comparisons
4.1 P Controller
The Kp= Kr = 0.18 was selected. The final value reached by the system is 19 which is 15% of
the set point same as that of Moellar SPS.
12
4.2 PID Controller
Although in our Controller the parameters according to Zeigler Nichols were used, by
comparing PID , it can be concluded that expected behavior for PID was realized with
Controllino.
13
4.3 Setting Controller Output Limits
The following figures shows the impact of not setting output limits of the PID Controller.
As seen from the figure the is a large overshoot before the controlled variable reaches the
set point 128. The settling time is also increased considerably which is not good. Therefore,
it has been realized that its important to set the output limits to 0 and 255.
14
4.4 Using the Arduino PID library
It was also realized PID Controller programmed without Arduino PID library <PID_v1.h>
performed much accurately as compared to the one programmed using library.
15
Chapter 5
Matlab Tuning
5.1 PID Tuner
The PID Tuner app automatically tunes the gains of a PID controller for a SISO plant to
achieve a balance between performance and robustness. You can specify the controller
type, such as PI, PID with derivative filter, or two-degree-of-freedom (2-DOF) PID
controllers. Analysis plots let you examine controller performance in time and frequency
domains. You can interactively refine the performance of the controller to adjust loop
bandwidth and phase margin, or to favor setpoint tracking or disturbance rejection.
In the following figures reference tracking step plot is used for comparisons. Reference
tracking is the response at y to signals at r.
16
5.2 P Controller
The Matlab P Controller simulation is compared with the real Controller. Kp = 2.224 is used.
By comparison it can be said that Matlab automated tuning is quite accurate for P
Controller,
17
5.3 PI Controller
The Maltab simulation for PI is quite different from when implemented on real Control
System. However, still set point was reached.
18
5.4 PID Controller
Again the result is quite different when implemented on Controllino. An Overshoot was
expected but there was no overshoot in the real control environment.
Figure 20: Matlab PID with Kp= 1.204, Ki= 0.575, Kd= 0.6296
19
Chapter 6
Conclusion/Further Improvements
It can be concluded that Controllino is a low cost solution to expensive PLC for certain tasks
because desired results were achieved successfully on Arduino Platform. Matlab Simulation
was an additional part. Matlab Tuning is important for plant and controller simulation.
Although with Matlab PID Tuner the desired result of reaching the set point with stability
was achieved, however, due to certain inaccuracies in real plant and the controller, the
comparison is not always exactly the same. In the future, MATLAB support package for
Arduino could be used that lets you write MATLAB programs that read and write data to
Arduino and connected devices. MATLAB is a high-level interpreted language, programming
with it is easier than with C/C++ and other compiled languages, and you can see results from
I/O instructions immediately—without recompiling. MATLAB includes thousands of built-in
math, engineering, and plotting functions that we can use to quickly analyze and visualize
data collected from Arduino.
20
Chapter 7
Arduino Code
7.1 PID with Library
21
22
7.2 PID without Library
23
24
25
7.3 PID with Time Constants
26
27
28
Chapter 8
Matlab Code
29
30