PID block algorithm in Simatic ?

I have checked and I get same matrices as you do. A and B are identical (there is small difference because I used -0.255 as pump's gain). There is overshoot. I think this is because I used classical PID controller, and you used state feedback controller. Also it seems to me that you use different model, that has integrator in direct path. It is hard for me to visualise your model, so if you can draw how your model look, it will be a great help in order to determin why exactly difference exist.

Yes, I'm pretty much sure difference is because we use different models. Matlab has function tf2ss that convert model given with transfer function to state space model using controller canonical form.

State space representation of transfer function (pump and tank are used together):

A = 0 1;

0 -12

B = 0

-0.0854

C = 1 0
D = 0

Discrete time representation (after calling c2dm function with sample time 1/120):

Am = 0.9048 0

0.0079 1.0000

Bm = 0.0079

0.0000

Cm = 0 -0.0854

Dm = 0



PID is continuous: Gpid = -605.4-907.2/s



Model picture with responses is given in uploaded figure.

Tank_level_continuous_and_discrete_simulation.jpg





 
Last edited:
You need to get the 'feel' for the system

Look at your graph. Notice that the PV goes from 0 to 2 meters in about .6 minutes. You know that isn't right since SIGreg's information said it took 68 second for the level to change just .8 meters. Don't expect the level to increase any faster than the maximum flow rate. During this time the integrator can wind up. Notice I put a limit on my output.

It helps if you graph all three values, SP,PV and CO.

Your discrete A matrix or transition matrix has the same numbers but they are not in the right places. Why?

Your continuous B or input coupling matrix is different from mine. Why. Obviously then the discrete matrix will be different.

Notice, I did not use a C or D array since my state variable were in the form I wanted which is level and rate of change in level.

Also, in my graphs the level is changing only about 0.06 meters at most and it takes two minutes to correct that because my closed loop time constants are that long by design.

I did find a bug in my .pdf. My graph should say time in minutes.

Notice that my Mathcad has few if any built in functions. I had to learn to make my own. It was hard but I think the understanding I gain while learning the hard way ( school of hard knocks ) was worth it.

You need to work the formulas out step by step and not rely on the Matlab high level functions. Compare your numbers with mine and find out why there are any differences. You need to work out how to change the flows rates like I do.

This takes time just like home work. Welecome to the school of hard knocks.
 
Hello Peter (and others)!
in attachment you can find .pdf file with my answers and explanations.
Cheers!
 
The B array is different.

Yes, I use pole placement. The math is there to see how I do it.

I use a state space controller, not a regulator. Regulators control to 0. A controller must have an integrator gain to control at different set points. I can modify my worksheet to use a PID. There wouldn't be much difference if any.

The only difference between the PID and state space controller is that the state space controller's proportional and derivative gains only work on the PV and PV'. Since the SP is not changing after the initial step to 2 meters there is no effective difference between the PID and state space controller. The state space controller avoids a spike in the control output when the set point is changed.

How can the PV rise to 2 meters in .4 to .6 seconds. If the pump is turn on the rate will be slower yet because it reduces the level. OOPS!

The C and D arrays should not be necessary.

Now I will be blunt. Stop using the fancy tools until you understand what is really happening. Have you noticed that I have a lower limit of 0 on the output of my PID. Does yours? When you make the step in the SP to 2 meters there is an error of 2 meters. Mulitply this error by a negative Ki gain and you can see the integrator will wind down below 0. The pump can not increase the level. It can only reduce the level. The pump can not reduce the error from 2 meters to 0 in .6 seconds.

Plot the SP,PV and CO. Plot the integrator contributiion to the CO. That way you can see the interaction.

I understand there is a format difference. My Scilab displays the arrays in a similar format as my Mathcad.
 
My simulation using a PID starting at a level of 0

This is my simulation using your conditions. I used a PID and started all the initial conditions at 0. Notice that there is no overshoot. The rate at which the level increases is propotional to the flow. The rate of change in the level has nothing to do with the PID until the level gets close to the set point. Notice that it takes a few minutes for the level to increase to two meters. I am still using the same gains but in this case it doesn't make much difference until the PV gets close to the SP. If I reduce the flow to 10 cubic meters per minute the rate would be half.

Do you still think I am wrong?
 
Peter, I didn't look at CO and think if that is realistic. i admit i was wrong. I'm trying to understend and correct situation.
Please read and help me understand.
 
Last edited:
Pandiani said:
Peter, I didn't look at CO and think if that is realistic. i admit i was wrong. I'm trying to understend and correct situation.
Please read and help me understand.
You need to limit the controller output to 0 to 100%. Not the pump.

u = max(min(i-Kx),0,100)

I say again. Stop using the high level blocks and stare at the equations until you understand them. I showed all the calculations. I don't use any high level fancy blocks. I think they obscure what is really happening. Copy what I do at a low level and duplicate my results. There is no easy way to understand all of this. It took me years because I learned on my own. I am self taught.
 
I know peter, but block gives me opportunity to fast manipulate with them, connect here and there. I understand that the best way to learn and to remember is hard way with equations.
I tried to limit controller output with saturation block. saturation block in Matlab is easy, if input is lower than the low limit, outpu is equal to low limit. if input is higher than upper limit, output from the block is equal to upper limit. If input value is between upper and lower limit, output from the block is equal to input value.
There is a problem. Since PID gains are large and negative and PID form is:
Gpid = -605.4-807.2/s, If I limit controller output between 0 and 100% I'll have following problem. In the begining PV = 0, SP =2, error is 2, when multiplying this with PID's gain, this value becomes negative and large and thus, controller output is 0. I used disturbance block in my model to simulate inlet flow. So, when controller output is zero, Flow (25.3) is entering tank blok and level is going up. At one point when Pv become grater than Sp, error becomes negative, after multiplying with larg negative gain constant, output from saturation block that is used to limit controller output jumps istanteniously to 100% and finally in effect I don't have nearly PV values I want.
I simply don't know how to compare this state space simulation and clasical PID simulation with transfer functions...?!!
I'm becoming frustrated because I want to make this simulation with transfer function blocks working first.
This is simulink model, really don't know what to change...
http://www.plctalk.net/qanda/uploads/Tank_simulation_answ.jpg

I'll start working on your simulation step by step until i understand it, but this Simulink simulation with transfer function really starts to worry me...
 
Last edited:
That looks better

The simulation looks more like I would expect from a system with a poorly implmented PID. Limiting the output to 0 to 100% may not limit the integrator wind up. Limiting the output may not really limit the PID output at all, just limit how much is passed on to the next block. Can you make another PID block that implements the PID like mine? I would include limits in the PID.

I think the problem is in how the Simulink implements a PID. I have this problem all the time when I simulate hydraulic cylinder motion. Hydraulic cylinders will reach the ends and stop. Pressure can't go below 0 etc. There are all sorts of limits with which real systems must contend must contend. I find I must write these simulations the old fashioned way , using systems of differential equations and Runge Kutta, because the ready made tools don't handle the discontinuities correctly.
 
Peter Nachtwey said:
The simulation looks more like I would expect from a system with a poorly implmented PID. Limiting the output to 0 to 100% may not limit the integrator wind up. Limiting the output may not really limit the PID output at all, just limit how much is passed on to the next block. Can you make another PID block that implements the PID like mine?
I'll try that Peter and let you know.
In the meantime I tried to understand your model and calculation but...
 
My state vector represents the level x(0) and the rate of change in level x(1). Normally the higher derivatives ae on the bottom.

I probably didn't use a pole placement procedure you would recognize because I use symbollic methods. My procedure accomplishes the same thing. At least I understand what is happening and can see how the variables affect the gains because I solve for the PID gains symbollically.
However, after you substitute numbers for my symbols the results are the same as Ackermann's formula. I can write more when I have more time.

Ackermann's formula does not provide symbollic results. You just plug in numbers without really understanding the method to the madness and get a number. It provides no feel for how the plant parameters affect the gains.

I define the inital output to be zero because the initial flow is 0.

One must keep the error history on a PID so one can compute the derivative term (Kc*Td)(error(n)-error(n-1)/T. I need to keep track of the last error. The incremental for requires keeping track of the last two errors.

Yes, I use discrete simulation. At some point the Simulink does too.

Mathcad does not have a PID routine or any simulation routines. One must write them.

u or the control output is in the right place.

What gains did you calculate? Could you cut and paste your matlab .m file in a post.

Do you understand where T(s) comes from? It is the closed loop transfer function CLTF. The trick is to get the characteristic equations in powers of s and normalized so the least significant term is 1. Now each coefficient for a power of s in the CLTF must be set equal to the coefficient for the same power of s in the desired characteristic equation function (Tc*s+1)^3= Tc^3*s^3+3*Tc^2*s^2+3*tc*s+1. Therefor Tc^3 = (Ti*Tp)/(Kc*Kt*Kp). What values of Ti and Kc will make this so? One can also see that the s*Ti term of the CLTF must be equal to 3*Tc*s of the desired characteristic equation so Ti must be equal to 3*Tc.
 
Peter, I really appreciate your effort to help me. I learned a lot from you, but it seems that I just waste your time and posts on this forum...
Thank you for everything but I think I'll not be able to get it...
 
You're right Peter, I was ignoring your suggestions because I had a couple of excercises in Simulink in school. We didn't have any feel for the process, simply teacher give us transfer function of process and we used built in functions, or bult in blocks to simulate. Now when I have something more realistic I find that I don't have any feel about what is going on and that frustrates me. I feel so powerless with such strong tool such as Matlab. But you're right, in order to gain full understanding of something it must be done from the scratch by myself.
I'll take few days to analyze what is going on, and how to implement something by myself.
Can you paste Scilab code for state space simulation. It will be more helpful to me?
Thanks again.
 

Similar Topics

HI.I REVIEWED A PROJECT DONE. THIS FB41 PID BLOCK WAS USED FOR THE PASTEURIZATION PROCESS. THE PROCESS I CAN'T UNDERSTAND IS THE ACTION. WHILE THE...
Replies
2
Views
1,124
Hello, I have a PID block in my program controlling pump speed in order to get a correct Differential pressure. The way I have it set up is the...
Replies
3
Views
1,284
Is there a way to create proportional logic for a control valve without using a PID function? I want to create a simple P controller without...
Replies
8
Views
2,637
So I have a PID block on CCW set up to control a motor. I have my variables input and the absolute error is changing but the CV is always 0. There...
Replies
1
Views
1,630
I want to change the setpoint of PID block in Codesys for every 1 hour. like that i have to give 48 setpoints for 48 hours. So how can I give 48...
Replies
2
Views
1,537
Back
Top Bottom