A Heuristic approach to PID Design and Implementation


Hey folks, Welcome and I hope all are doing well.

This Course was written as a guide to help people get started with PID controllers (Not Mathematical, but Intuitive and an Implementation approach)

I myself completely learned this online and I wanted to make this course a one-point solution for people seeking help on this. All the resources I used are attached at the end of this course. 

Course weightage:

  • 30% Basics

  • 40% MATLAB

  • 30% Arduino

Please read from the start till end as I have all the data’s and Information required to develop a project that runs on a PID controller.

Let’s get started…

YouTube Video series Link: Youtube Video series

MATLAB File exchange Link: MATLAB File exchange

An Overview

In this course, we will understand a practical way of designing and implementing a PID controller for a PID based Temperature controller. It also covers the electronics and computation required to completely build this project. Arduino and MATLAB Simulink are used as a tool for project construction and tuning of the controller.

I will write this course step wise, please follow each step. Patience is the key to Success. This course might take several hours to complete.



Step 1: Why Learn this??

Before getting deep into this course, Lets understand the need for a controller and why a temperature controller was chosen as a project of interest.

  1. What is the need of a controller?

Let’s start with an Example, assume you are riding a space shuttle (Why always a space shuttle?? It is the most complex machine ever flown) and you want to get into a specific trajectory. You need to adjust the thrust vectoring gimbal so that the pitch, roll and yaw of your rocket are altered.  This will get you into a specific trajectory. Here we don’t know how much degree should I move my thrust vectoring gimbal so that we get into the specified trajectory. This is done by a controller.

The controller gets you to a specified setpoint by controlling the output of the system. In this case, specified trajectory is your set point (Input), Thrust vectoring gimbal is your output (Thrust vectoring gimbal controls the pitch, roll and yaw of your rocket).

 (Link: https://www.youtube.com/watch?v=XeRic0Mu-bw&ab_channel=SpaceIsKindOfCool)

In order to make the necessary changes to attain a specific target, A controller is required.

  1. Why a PID based Temperature controller??

PID is a most widely used controller. PID based temperature controller is a go to project as it is very basic and easy to understand. You can use the same concept to develop different projects.

Step 2: Brushing up some basics

To learn any concepts, Basics are very important. So, we do a small brush up on basics and move on. Please use the link for better understanding (If you’re new to this)

2.1 What is control system?

A control system controls the input of the system to achieve a desired output. 

A control system consists of 

  1. Error Detector: Detects the error value between the feedback signal and setpoint.

  2. Controller: Controls the input to the plant by observing the error signal to get the desired output

  3. Plant: Is the actual system onto which the input is applied and output is observed.

  4. Feedback elements: The observed output is measured or processed into other desired variables through feedback elements. 

Let’s take the same example, A space shuttle.

Here the set point (black curve) is the trajectory to reach the lower earth orbit. Space shuttle’s thrust vectoring gimbal is the plant. The output of the plant (i.e. The present trajectory (red curve)) is observed. This is then sent to the Error detector were the setpoint and output of the plant is subtracted and an error signal is obtained. Based on the error signal the controller moves the thrust vectoring gimbal. The main aim of the controller is to reduce the error value to zero. Zero error means the setpoint and present trajectory is aligned perfectly. This can be observed in the graph after 2000 Km.

(This figure is just an illustration and not the actual data)

2.2 PID (Controller)

PID stands for Proportional, Integral and Derivative, is a conventional controller. A very simple yet an efficient controller. The controller helps you to achieve the set point in a most efficient and in a less tedious way. 

A generic closed-loop process-control system with PID controller. |  Download Scientific Diagram

DONT PANIC:

P – Proportional Keeps track of the present.

I – Integral Keeps track of the Past. By summing up the past error values.

D – Derivative Keeps track of the future. By knowing the rate of change of error values.

This together forms a PID controller which is a simple, most efficient controller.

Three constants namely Kp, Ki, Kd exists.

Kp – Proportional constant.

Ki – Integral constant.

Kd – Derivative constant.

These constant plays the most vital role in approaching the set point. Whatever the application may be these three constants are tuned to get the desired output.

Watch this video to get a very good intuitive understanding on PID controllers. A very good series by engineer Brian Douglas. 

(Link:https://www.youtube.com/watch?v=wkfEZmsQqiA&list=PLn8PRpmsu08pQBgjxYFXSsODEF3Jqmm-y&ab_channel=MATLAB)



Possible outputs of the system that uses PID controller:

Quadcopter PID Explained - Oscar Liang


Various output curves can be obtained by tuning the constants of PID (i.e. Kp, Ki, Kd)

  • The Orange curve is poorly tuned PID, i.e., Kp, Ki, Kd are inappropriate

  • The Green curve is the best possible output to reach the setpoint.

  • The Blue curve is better but not the best.

In our Project this is how our PID flowchart looks like:

The input, output and the feedback will be temperature signal.

2.3 Transfer Function

A transfer function is a Black box that forms a relationship between the Input and output in Frequency domain. A transfer function is applicable only to Linear time invariant system. A transfer function is used to convert the real time model into a mathematical model. This model is further used to tune the PID gains. The sole purpose of Transfer function in our project is to tune the PID gains (i.e. Kp, Ki, Kd). 


Is Synergy In Audio Cables Real or Snake Oil? | Audioholics


X(s) – Input to the system (Frequency domain) 

T(s) – Transfer function of the system

Y(s) – Output of the system (Frequency domain)

More on Linear time Invariant systems:

https://www.youtube.com/watch?v=Y8iFJVmSQIk&t=205s

https://www.youtube.com/watch?v=3eDDTFcSC_Y&t=128s&ab_channel=BrianDouglas

More on transfer functions by: https://www.youtube.com/watch?v=RJleGwXorUk&ab_channel=BrianDouglas

2.3.1 Poles and Zeros of Transfer function: 

Poles: Frequencies at which Denominator of the transfer function [X(s)] is zero.

Zeros: Frequencies at which Numerator of the transfer function [Y(s)] is zero.

More on Poles and Zeros of transfer function by:https://www.youtube.com/watch?v=AZ7_MvANy_Q&ab_channel=NesoAcademy


Step 3: Creating the Hardware Unit

3.1 About the temperature controller

A heater with variable power input and a temperature sensing probe. The heater is controlled with an Arduino Uno and the temperature is also measured using Arduino Uno as a feedback element for our controller.

3.2 Components Used

  • Arduino Uno

  • LM35 Temperature Sensor

  • MOSFET or BJT Transistor (I used CEP 83A3 N channel Mosfet)

  • Heating Element

  • Power supply

  • Some wires

I have soldered the circuit on a Prototype PCB. You can do it on a breadboard. Make sure you don’t melt the breadboard due to conduction of heat through the heating element leads. 

3.2.1 Temperature sensor

I had a LM35 temperature sensor in-hand and I used it. If you are buying a new temperature sensor, I would recommend to buy some other sensor as LM35 fails to show correct reading sometimes… 

A temperature sensor with a sensing range of 0 – 100 *C (for our application) and an Arduino support library is recommended. 

3.2.1.1 LM35

LM35 Temperature Sensor Pinout

More about LM35 temperature sensor:

https://components101.com/sensors/lm35-temperature-sensor

3.2.2 MOSFET/ BJT

Choosing between the MOSFET and BJT depends on the heater you’re going to control. I’m using a heater scavenged from an old iron box. The power supply is 12VDC 1A. So, a MOSFET or BJT that can handle your power supply is mandatory. I used a CEP 83A3 MOSFET. 

Above table representing CEP83A3 specs

To understand more about BJT and MOSFET: https://www.youtube.com/watch?v=VlMdSCI29A0&ab_channel=Electronoobs

3.2.3 Heating Element

I got my heating element from an old iron box. I cut a small piece (approx. 2.5 inches in length) of the heating element and used it in my project. It reaches 100*C with 6VDC 1A power source which is good for our application.

3.3 How to Build??



Step 4: Interfacing Hardware with MATLAB Simulink


Step 5: Tuning of PID

Tuning a PID means setting the Kp, Ki and Kd to an appropriate value in order to achieve the set point at a much faster time and in a better way. You can tune the PID manually but it’s a heuristic method. In order to properly tune a PID controller you need a

  • mathematical model

  • state space model

  • transfer function of the system.

This needs some groundbreaking math and analytics. Since the course is all about practical approach, I will take you through one of the easy methods to tune a PID controller. We have made the real model in step 3. Using this model, we will create a transfer function and tune the PID controller. 


5.1 Step response Model

Since we have the Hardware, we give a constant step input to the system and observe the response as output. Note that both the input and output are recorded. This is how the input and output look with respect to time.  Graphical Method: FOPDT to Step Test | Dynamics and Control

In our case, the input and output of step response model:

This is fed into the MATLAB system identification toolbox. Please watch the video below on how to extract the transfer function from the data. 

From the system identification toolbox, we get the transfer function. 



5.2 Tuning the PID

Once the transfer function is obtained, it is fed onto a loop containing the PID controller. Here a preset option (PID tuner app) in PID controller block helps us tune the PID gains.



You can also watch the video by brian douglas and AP monitor on tuning of PID’s: 

https://www.youtube.com/watch?v=Mbx5IMICS_Y&t=1353s&ab_channel=BrianDouglas

Step 6: Testing

We have successfully built a PID based temperature controller.

Hope you like this series. This is my first series and I would love to hear back from you on comments below.  



Fig: Result showing the correlation between the hardware and the transfer function


Comments

Popular posts from this blog

Electric Vehicle Powertrain - Calculations and Mathematical Modelling

Attitude Heading Reference System: An intuitive engineers perspective