mardi 15 mai 2012

PID control: algorithm and implementation


Meet,



Mr Proportional
a fat guy that eat too much his one and only issue is his stomach :pp





Mr Integrator

 a punctual guy and obsessed with time he can never be satisfied with something unless he finished it all.






Mr Derivator
an athlete that loves to run, sometimes slow and sometimes fast and he can make his colleagues run faster.








Mr P Mr I and Mr D can make a great combination to make any system work at his best withe all the energy that given by Mr P all the punctuality that is given by Mr I and all the speed that it's given by Mr D.


So PID Controller is a command law that controls a system to respond to a specific order.
Our objective to make a specific system respond to our command with the minimum possible error as fast as possible and with maintaining it's stabilité

So let's look to this system:
It can be controlled by two different way.
The first method is an open loop command  it's a very simple command we just put the command manually and the system will react according to that command BUT that means we don't have any idea about what's going on in the end and even that we can observe our system working we don't have an exact idea about his performance.

The second method is a close loop command that means we give a desired goal for example a specific position the system then will calculate the error = desired goal - output and create the command accordingly so in this case the command is generated automatically. 
here we can notice that the desired goal and the output must be with the same unity that means the desired goal must much the unity of the system output.

Where's the PID?

well PID regulator is the first one which meets the error calculated each time.


As we already saw Mr P, I and D are the 3 gentlemen who constitute the PID regulator.

Mr P is simply the error that we already talked about.
Mr I is the sum of all the errors calculated
Mr D present the Dynamic of the errors whether the error value are changed suddenly or smoothly we should consider that in out regulator.

How can I much this gentlemen with my specific system?

well here we need a little magic. You should know the exact amount of food to give to Mr P Let's called Kp. The exact sense of punctuality to Mr I (Ki) and the perfect body to Mr D (Kd).

Implementation:

If you want to implement your PID controller into a microcontroller you need to follow this steps;

1° Create a Timer interrupt (which represent the sampling time)
2° predefine your PID parameters
3° in the Timer routine calculate the 3 Mrs:
   MrP = target-output
-------------------------------
  MrI=MrP+LastMrI
 LastMr+=MrI
------------------------------
MrD=MrP-LastMrD
LastMrD=MrP
------------------------------
4°calculate the correction
 correction = Kp*Mrp+Ki*MrI+ Kd*MrD
5°Saturation:
correction mustn't exceed the maximum value the actuator would take so we need to do a saturation routine

N°: Sometimes "correction" have negative values so if we are dealing with motors that means turning in the other sens if we are dealing with a temperature regulation that means we should stop or cooling our system.

Aucun commentaire:

Enregistrer un commentaire