Sei sulla pagina 1di 30

University of Applied Sciences

Ravensburg Weingarten

Faculty of Electrical Engineering and Information Technology

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 2 Hardware/Software Setup………………………………………………………………….….5


2.1 Controller and Controlled System (Hardware) ……………………………………………….5
2.2 Software Integration ……………………………………………………………………………………..6
3 Chapter 3 Tuning the Controller.………….…………………………………………………………………..7
3.1 General PID Equation…………………………………………………………………………………….7
3.2 Software Scaling for 5V Set Point………………….……………………………………………….8
3.3 Ziegler Nichols PID Tuning Procedure…….………………………………………………………8
4 Chapter 4 Comparisons……………………….………………………………………………………………….12
4.1 P Controller ………………………………………………………………………………………………….12
4.2 PID Controller …………………………………..………………………………………………………….13
4.3 Setting Controller Output Limits………..………………………………………………………….14
4.4 Using the Arduino PID Library.…………..………………………………………………………….15

5 Chapter 5 Matlab Tuning……………………….……………………………………………………………….16


5.1 PID Tuner.…………………………………………………………………………………………………….16
5.2 P Controller .……………………….……………………………………………………………………….17
5.3 PI Controller.…………………………………………………………………………………………….….18
5.4 PID Controller.………………………………………………………………………………………….….19

6 Chapter 6 Conclusion/Further Improvements……………………….…………………………….….20


7 Chapter 7 Arduino Code ……………………………..……………………….…………………………….…...21
7.1 PID with Library.…………………………………………………………………………………………..21
7.2 PID without Library.………………………………………………………………………………….….23
7.2 PID with Time Constants.………………………………………………………………………….….26

8 Chapter 8 Matlab Code ……. ……………………………………………….……………………………..….29

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.

1.2 Hardware/Software Requirements


Hardware:
1. Controllino Maxi Automation (PLC)
2. Regelstrecke- Controlled System (PT3)
3. A PC
4. I/O wires and USB Cable
5. A switch/button
6. DC Power Supply for Controlled System
Software:
1. Arduino IDE
2. MegunoLink
3. Matlab

3
1.3 Controllino Maxi Automation

Controllino Maxi can be used as low cost PLC and it is fully integrated into Arduino platform.

Figure 1: Controllino Overview

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

Figure 3: Controlled System (PT3 Strecke)

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

1. Proportional Term produces an output value that is


proportional to the current error value.

2. Integral Term is the sum of the instantaneous error


over time and gives the accumulated offset that should have been corrected
previously. The accumulated error is then multiplied by the integral gain 𝑲𝒊 and
added to the controller output.

3. Derivative Term , the derivative of the process error is


calculated by determining the slope of the error over time and multiplying this rate
of change by the derivative gain 𝐾d.

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.

3.3 Ziegler Nichols PID tuning procedure


The Ziegler-Nichols’ closed loop method is based on experiments executed on an
established control loop . This method is best suited for higher order plant systems. Since
our controlled System (PT3) is the third order System with the transfer function

Ziegler Nichols method is a good approximation for tuning .


The tuning procedure is as follows:
1. Turn the PID controller into a P controller by setting set Ti = ∞ and Td = 0. Initially set
gain Kp = 0.
2. Increase Kp until there are sustained oscillations in output of control system. (The
sustained oscillations corresponds to the system being on the stability limit.) This Kp
value is denoted the ultimate (or critical) gain, Kpu . For our System Kpu was found
to be 4.3 This is shown in the following figure:

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.

The calculated parameters are Kp = 2.58, Ki= 1, Kd= 1.61

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.

Figure 9: P Controller with Kp= 0.18

Figure 10: P Controller 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.

Figure 11: PID Controller -Zeigler Nichols

Figure 12: PID Controller -Moeller SPS with TR1=TR2=T1

13
4.3 Setting Controller Output Limits
The following figures shows the impact of not setting output limits of the PID Controller.

Figure 13: PID without Output limits

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.

Figure 14: PID with library

Figure 15: PID without 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,

Figure 16: Matlab P Controller with Kp =2.224

Figure 17: Implementation on Controllino

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.

Figure 18: Matlab PI with Kp= 1.137, Ki= 0.4541

Figure 19: Implementation on Controllino

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

Figure 21: Implementation on Controllino

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

Potrebbero piacerti anche