# Simple explanation of PID control [duplicate]

I tried reading and searching different books and links for understanding PID control but not much progress

Can some one please give me simple explanation of PID control?or atleast links where easy content is available which is simple to understand

The farther away the actuator is from the goal, the harder the actuator tries to reach the goal. That is the (P)roprtional part of PID.

The longer amount of time the actuator is blocked from the goal, usually by larger than expected friction rather than actual object blocking the path, the harder the actuator tries to reach the goal. That is the (I)ntegral part of PID.

The faster the actuator is moving towards the goal, the more likely it is that it will overshoot and go too far, so the faster it goes toward the goal, the more it resists and tries to slow down. That is the (D)erivative part of PID.

You can see how PID works for controlling the motion of a car in this video:

In simple words, PID control law computes the error function (e(t) = r(t) - y(t)) where r(t), y(t) are the reference signal and output signal of the system being controlled. At any given time, 3 terms are computed, namely the current, history and future value of error function.

Current: P term penalizes the current error value: Kp*e(t)

History: I term penalizes the integral of the error values: Ki*sum (e(t))

Future: D term penalizes the derivative of the current error value: Kd*d e(t)/dt

Control law is given as u(t) = Kpe(t) + Kisum[e(t)] + Kd* d e(t)/dt

You can find more details in Karl Astrom's book: https://www.cds.caltech.edu/~murray/courses/cds101/fa02/caltech/astrom-ch6.pdf

Before we can introduce PID control, a more easier to implement controller has to be mentioned first, which is bang-bang control. It contains of an if-then-statement.

Such a controller, is able to move the robot on a line. The disadvantage is, that the robot's actions are not smooth, but the device will steer a bit chaotic. The more elegant approach is pid control, which isn't only steers left vs. right, but measures the amount. The deviation of the angle is set into relationship to the steering command. For example, if the angle error is only -2 degree, then the steering is small. This results into a more affordable trajectory.

def bangbang(current,goal):
if current==goal: steer=0
elif current<goal: steer=1
elif current>goal: steer=-1
return steer
def pid(current,goal):
error=goal-current
steer=0.5*error
return steer

# main
goal=0
print("currentangle,goalangle,bangbang,pid")
for i in range(-5,6):
a=bangbang(i,goal)
b=pid(i,goal)
print(i,goal,a,b)

""" output:
currentangle,goalangle,bangbang,pid
-5 0  1  2.5
-4 0  1  2.0
-3 0  1  1.5
-2 0  1  1.0
-1 0  1  0.5
0 0  0  0.0
1 0 -1 -0.5
2 0 -1 -1.0
3 0 -1 -1.5
4 0 -1 -2.0
5 0 -1 -2.5
"""