## Modified PID Algorithm Implementation

So here are the contents:

**Contents**

- Necessary things for making line following Robot
- Introduction PID algorithm
- How to implement PID algorithm
- PID Algorithm Parameters
- Modify PID for line following Robot

## 1-Necessary things for making line following Robot

## MOTOR DRIVERS AND DUAL H-BRIDGE L298 ARDUINO MODULES INTERFACING

### 2-Introduction to PID algorithm

**The Proportional Response**:

The proportional component in PID algorithm is the difference between the set point of the system and the process variable. Now, this difference is called Error. The proportional gain (Kp) is the ratio between output response and the error signal.

**The Integral Response**

Integral in PID is the sum of the error term over the time. If the result is a small error the integral component will increase slowly. Now the integral term will continually increase over the time unless and until the error is going to be zero, so the ultimate effect is driving the Steady-State error towards zero. The difference between the process variable and the set point is the Steady state error.

**The Derivative Response:**

The function of the derivative component is to decrease the output of the process variable is going to increase. The derivative is the rate of change of the process variable. The Increase in the derivative time (Td) will make the system to react strongly and to make changes in the error term.This will increase the overall speed. The very small (Td) the derivative time is used in most practical systems.Derivative Response is sensitive and highly sensitive to the noise and in the process variable. If the feedback is noisy or the control loop rate is very much slower, The control system will be unstable due to derivative response.

### 3-PID Control Algorithm for Line Following Robot

- In a case when robot is deviated to left it then pushes to move towards right
- In a case of deviation towards right, it is forced to move towards left

The accomplishment of this task gives a robot to follow the zigzag path.By this method, the speed we were giving was much less as error getting by using PID. And this technique was also not reliable for the turns. And To apply this algorithm it was better to use the error calculation method after calculating error giving motor it’s proportional value and then it changes speed and in turn, it gets back to the line.

e.g.-the deviation ranges between -3 to +3.

- It affects the accuracy of the robot when the robot is not much effective it gets back to mean position very slowly.
- To solve this problem we have to increase its proportionality contact but it will then overshoot when the robot comes to mean position due to inertia-cross to another side then again overshoot results in deviating result.

### 4-PID Algorithm Parameters

**: error****: time of deviation****: overshoots**

The efficiency of the PID algorithm is totally based on these three parameters these helps to reach at a mean position much faster.

**Kp****Ki****Kd**

**Kp:**Using only kp parameter the robot will be applied and give the results as the classical Line following algorithm.

**Kd:**kd does not allow the robot to perform any deviation.

### 5-Modify PID for Line Following Robot

**Define your sensors in an array:**

const int irPins[5] = {A1, A2, A3, A4 ,A5};

2.

**Further, define your sensors as a binary function:**

int irSensors = B00000;

3. **Define**

int errorLast = 0;

errorLast = error;

This is the point where an array stored the last error value and when ever the robot leaves the line it then comes back to the line by last stored value.

The last point is that use the error calculating equation to control motor speeds;

if (correction >= 0) {

motorRSpeed = maxSpeed – correction;

motorLSpeed = maxSpeed;

else if (correction < 0) {

motorRSpeed = maxSpeed;

motorLSpeed = maxSpeed + correction;

I know I just give some code snippets that will be really difficult to understand the whole concept.**See the Equation:**

Use this equation to control the speed of motors.Well here is just the PID understanding.

Read this complete post about PID that I have written for PIC controller.See the post the code will help you to understand more about the concept.

## PID ALGORITHM IMPLEMENTATION (PID CONTROLLED LINE FOLLOWING ROBOT)

## Conclusion:

**YouTube Channel**for video tutorials.