PID Tuning tool

If you are constantly updating the model and subsequently the gains, it's almost a sudo MPC.
No! MPC has no gains! It does require an accurate model. MPC estimates the MV or control outputs for each iteration N times in the future. The control outputs are determine by minimizing the SSE between a desired SP(n) and the PV(n) or response N iteration into the future. For temperature systems N most be enough iterations to see past the dead time. So if if the temperature does an iteration every second, the MPC must do 30 calculations or look 0.5 minutes in the future because the dead time is .354 minutes. This allows the MPC to see past the dead time. This will keep the MPC from over saturating the control output. This is quite CPU intensive at first but after a good fit is found the next iteration will go much faster since N-1 MVs can be shifted down and the last MV is still a pretty good start for the next iteration.


Now think about this. If there are 30 MVs to optimize, N-M requires N+1 initial guesses. That is a lot. This is where some other method of optimizing might be better like Levenberg_Marquardt.


As the dead time increases, so does the number of iterations one much look into the future or maybe you can cut that in half if each iteration is 2 seconds instead of 1. It would also save on processing time.


[/quote]

There are plenty of options for future features. Nelder-Mead, it has been the most consistent.[/QUOTE]
Have you tried Levenberg-Marquardt. The package is called lmfit.py lmfit is much different from the standard packages in scipy.optimize.
 
Assuming you want the SSE for the hotrod.txt data.

I want to see values your model generates.

This doesn't surprise me. You will almost always get a lower SSE if you add more derivatives. In this case you have added two so you have a forth order model.

I added two derivatives instead of dead time (to exclude dead time out of model)
I consider dead time as infinite order lag

For high order lag without dead time, at least THEORETICALLY, IT POSSIBLE to derive some “ideal loop” (Yes, you right – find high order derivatives especially with noised signal it is nightmare).
For model with dead time, even THEORETICALLY, IMPOSSIBLE to derive some “ideal loop”. At least I don't know how.

Honestly, I’ve never apply high order derivatives in real loops.
I did some computational experiments, and I think that under certain conditions it is possible to create a control system with high order derivatives

Actually I use high order lag modes to avoid dead time at characteristic equation. Finding roots of algebraic (even higher order) equation much easier than transcendental equation.

As I say earlier, I don’t believe in “exact” “ideal” models. I exam plant, make decision if it necessary to include dead time in model, then doing some preliminary research on the model such as: finding the most “stable” roots, finding stable roots with acceptable oscillation.
 
I want to see values your model generates.
Look at #73

I added two derivatives instead of dead time (to exclude dead time out of model)
I consider dead time as infinite order lag
That is NOT the way to do it. Dead time should be simulated like one simulates the transmission delay in a coax cable. It is an infinite number of poles with short time constants.

For high order lag without dead time, at least THEORETICALLY, IT POSSIBLE to derive some “ideal loop” (Yes, you right – find high order derivatives especially with noised signal it is nightmare).
For hydraulic and pneumatic systems I use a 3 order open loop model. There are two complex poles for the actuator/load and the oil. A third pole occurs because velocity needs to be integrated to position. When the closed loop gains are added the integrator adds yet another pole so there are 4 closed loop poles.

For model with dead time, even THEORETICALLY, IMPOSSIBLE to derive some “ideal loop”. At least I don't know how.
I have posted how to do it many times. I don't know why I bother if no one pays attention. I will post it again.
https://deltamotion.com/peter/Mathcad/SOPDT/Mathcad - SOPDT_HOTROD.pdf
I show how the PID gains are derived to compensate for the dead time.
This is showing the tuning for the hotrod.txt data I did in 2007.
Study this. I haven't seen anything like this detail in a text book.

Honestly, I’ve never apply high order derivatives in real loops.
I did some computational experiments, and I think that under certain conditions it is possible to create a control system with high order derivatives
You can't properly place the closed loop poles with the derivative gains.

Actually I use high order lag modes to avoid dead time at characteristic equation. Finding roots of algebraic (even higher order) equation much easier than transcendental equation.
What??

As I say earlier, I don’t believe in “exact” “ideal” models.
No one does but you shouldn't use it as an excuse. If the model is accurate within 5% that is pretty good if you use feed forwards/bias. The feed forwards will then get close and the closed loop control only needs to do the remaining 5% This would reduce the error by a factor of 20. I usually can get within 2%.

I exam plant, make decision if it necessary to include dead time in model, then doing some preliminary research on the model such as: finding the most “stable” roots, finding stable roots with acceptable oscillation.
You can use trial and error. I try to place the closed loop poles on the negative real axis so the error decays without overshoot. Overshoot is bad in motion control applications.
 
Last edited:
No! MPC has no gains! It does require an accurate model. MPC estimates the MV or control outputs for each iteration N times in the future. The control outputs are determine by minimizing the SSE between a desired SP(n) and the PV(n) or response N iteration into the future. For temperature systems N most be enough iterations to see past the dead time. So if if the temperature does an iteration every second, the MPC must do 30 calculations or look 0.5 minutes in the future because the dead time is .354 minutes. This allows the MPC to see past the dead time. This will keep the MPC from over saturating the control output. This is quite CPU intensive at first but after a good fit is found the next iteration will go much faster since N-1 MVs can be shifted down and the last MV is still a pretty good start for the next iteration.


Now think about this. If there are 30 MVs to optimize, N-M requires N+1 initial guesses. That is a lot. This is where some other method of optimizing might be better like Levenberg_Marquardt.


As the dead time increases, so does the number of iterations one much look into the future or maybe you can cut that in half if each iteration is 2 seconds instead of 1. It would also save on processing time.


I meant in terms of the next progression.
PID-> Adaptive PID (model based PID Gains) -> MPC (full model based control)

Have you tried Levenberg-Marquardt. The package is called lmfit.py lmfit is much different from the standard packages in scipy.optimize.

No.. what is the difference, performance wise?
 
No.. what is the difference, performance wise?
We use Levenberg-Marquardt for our auto tuner for motion control. It works very well but the code is written in C and is very fast. The python implementation is slow. I have an example where I am finding the model of a non-linear valve. There are 15 constants to determine so takes many minutes to find the best solution. I haven't had time to try dong the same using Nelder-Mead because it is too fancy. I will try to clarify that later. For now, Nelder-Mead is the best for working with real data. Both methods are trying to do the same thing which is to minimize the SSE between the model and actual data.
 
Look at #73

I didn’t find it there.
Did it myself. Please find it at attached xls file.

That is NOT the way to do it.

To do what? To use high order derivates instead dead time? Why? I have no reason to suppose that the real plant includes significant "dead times".

I have posted how to do it many times. I don't know why I bother if no one pays attention. I will post it again.
https://deltamotion.com/peter/Mathcad/SOPDT/Mathcad - SOPDT_HOTROD.pdf

Thanks.
1. You and I have a different meaning of the term "ideal loop". Please find curves of "ideal loop" step disturbance response below.
attachment.php


2. The document provides a good formula for calculating the PID controller arguments to get a "nice and smooth" change-setpoint-response curve, not so "nice and smooth" for disturbance response.

Let’s look at the CO curve on the last page (I've attached the image below)
attachment.php


At 5-th minute setpoint changes from 117,6 to 380.
Before 5-th min CO =10 i.e. Ui = 10. Kc = 0.23675.
At first iteration (PLC scan) after setpoint changes
Error value E = setpoint – actual PV = (380 – 117,6) = 262,4
CO = Kc*E + 1/Ti *E*dt + Ui(-1) + Td* (E – E(-1))/dt = 0,23675*262,4 + 1/3,6 * 262,4 * 1/60 +10 + 0,557*(262,4-0)*60 = 8842,75
At second iteration (PLC scan) after setpoint changes
CO ≈ 0,23675*262,4 + 1/3,6 * 262,4 * 1/60 +10 + 0,557*(262,4-262,4)*60 = 73,34

What I see in the picture is somewhat different from the above calculations. Won't you explain?

You can't properly place the closed loop poles with the derivative gains.

Let's play “captain obvious”!
If real plant includes dead time you right!
If the real plant doesn't include dead time, you're still right! - it is impossible to completely describe a real plant using LDE, so the roots of the equation will never fully respond real plant.


Peter, I'm not native speaker. My English quite poor. And of course I don't feel language overtones.

“What??” – I don't get what it actually means.

No one does but you shouldn't use it as an excuse. If the model is accurate within 5% that is pretty good if you use feed forwards/bias. The feed forwards will then get close and the closed loop control only needs to do the remaining 5% This would reduce the error by a factor of 20. I usually can get within 2%.

I do not evaluate the accuracy of models because I do not know how.

You can use trial and error. I try to place the closed loop poles on the negative real axis so the error decays without overshoot. Overshoot is bad in motion control applications.

As I noted earlier, I take into account the ratio of the imaginary and real parts of the roots of the characteristic equation.

D4_IL.png PN_model.png
 

Attachments

  • HR_SOPDT_PN.xls
    217.5 KB · Views: 2
Last edited:
The reason your calculations are not the same as mine is that you are apply the proportional and derivative gains to the error. I am not. I am applying the proportional and derivative gains only to the change in the PV.

You can check to see how good your model is by plotting the model's response vs the actual response. That is a visual way. I also calculate the SSE ( sum of squared errors ) between the model's estimated response and the actual response. I have shown this many times. Sometimes the SSE is not as meaningful as calculating the RMS error between the estimated and actual response. The advantage of calculating the RMC error is that it takes into account the number of iterations. This is good for comparing data from different "runs" or tests where the number of samples between tests is not the same. The square root function of the RMS calculation tends to compress the results towards zero.
 
The reason your calculations are not the same as mine is that you are apply the proportional and derivative gains to the error.

I was thinking PI-controller works this way.

I am applying the proportional and derivative gains only to the change in the PV.

In your article, you show a method for tuning a PID controller (without any qualifications). BUT you demonstrate the result of the method on a modified PID controller?

I am applying the proportional and derivative gains only to the change in the PV.” – I don't understand how should it works. Can you please explain, show formulas, and so on?


You can check to see how good your model is by plotting the model's response vs the actual response.

No you can NOT. The only thing you check this way – how close your models response to plant response “here and now” i.e. at this exact conditions and this exact way.

"Model accuracy" is a very complex concept.
 
I was thinking PI-controller works this way.
You can make a I-P controller where the P term acts only on the change in the PV

In your article, you show a method for tuning a PID controller (without any qualifications). BUT you demonstrate the result of the method on a modified PID controller?
Yes, the gains for a PID and I-PD or PI-D are the same. The gains place the closed loop poles, not the zeros. A PID will add two zeros, a PI-D will add one zero. An I-PD adds none.

Zeros can extend the bandwidth of the system but they can also have negative effects. The can cause a system with real negative poles to still have over shoot problems. If you place the zeros wrong, they can also cause a loss of gain at some frequencies. This usually is not desirable but if you know how, you can place the zeros so they create a notch filter.

I am applying the proportional and derivative gains only to the change in the PV.” – I don't understand how should it works. Can you please explain, show formulas, and so on?
I will need to make some Bode plots. Actually, I have them made. I will need to make another video.

No you can NOT.
Yes I can!

The only thing you check this way – how close your models response to plant response “here and now” i.e. at this exact conditions and this exact way.

"Model accuracy" is a very complex concept.
No it isn't. The response. Everything a can be represented using exponentials, sines and cosines. Non-linear systems may have constants that aren't really constant. In this case you make them a function that can be approximated closely using a Taylor series or Pade approximant. Dead times are modeled using these techniques. I once wrote a magazine articles about time constants that aren't really constant. School teachers and books don't telly you this. If you can accept that time constants may not be constant then your ability to model the system will improve because you will take this into account.

Here an an example of how I model a non-linear valve.
https://www.youtube.com/watch?v=Zu3MC4LJpu8

About closed loop zeros
https://www.youtube.com/watch?v=eYNB-yReTY4

An example where time constants are not constant.
Tank level control.
https://www.youtube.com/watch?v=d_twlM8VDuM

I have a lot of good information on my Peter Ponders PID YouTube channel.
You need to think beyond the text books and your no-experience instructors.
 
Yes, the gains for a PID and I-PD or PI-D are the same. The gains place the closed loop poles, not the zeros. A PID will add two zeros, a PI-D will add one zero. An I-PD adds none.

Oh, I figured out what I was wrong about. Please forgive my carelessness.
Your article is titled "I-PD Control of a SOPDT Temperature System" so you show the results curves with I-PD.

But I trusted the math:
Сhange set-point Closed loop transfer function (in your article):
G(s) = Gc(s)*Gp(s)/(1+ Gc(s)*Gp(s))
corresponds to a system with a PID controller

Сhange set-point CLTF with I-PD is:
G(s) = GI(s)*Gp(s)/(1+ Gc(s)*Gp(s))
GI(s) – is integral term of PID

No it isn't. The response. Everything a can be represented using exponentials, sines and cosines. Non-linear systems may have constants that aren't really constant. In this case you make them a function that can be approximated closely using a Taylor series or Pade approximant. Dead times are modeled using these techniques. I once wrote a magazine articles about time constants that aren't really constant. School teachers and books don't telly you this. If you can accept that time constants may not be constant then your ability to model the system will improve because you will take this into account.

Ok, let's look at your example "Tank level control".
What is the accuracy of the model if we don't have any information about pipeline parameters, pump performance characteristics, etc.?
What will happen to the accuracy of the model when the temperature changes if glycerin or (even funnier) a solution with exactly unknown parameters acts as a liquid?

And most importantly: what do you think, how many more parameters can remain unaccounted for?
 
Last edited:
Ok, let's look at your example "Tank level control".
What is the accuracy of the model if we don't have any information about pipeline parameters, pump performance characteristics, etc.?
This was a problem presented by a student in the Netherlands. The problem was presented back in 2010 back when LinkedIn had engineering forums.
The student wasn't able to give much information. He was a clueless student. He did have a mockup in the lab at school, but he did not have a model. He finally got the system to work using trial and error. I said I wouldn't have given a passing grade because he couldn't write those first two differential equations.

What will happen to the accuracy of the model when the temperature changes if glycerin or (even funnier) a solution with exactly unknown parameters acts as a liquid?
The motor is assumed to respond very fast, almost instantly, relative to everything else so modeling the pump was not a priority. The fluid is water at room temperature. This was at a school/university.

And most importantly: what do you think, how many more parameters can remain unaccounted for?
I didn't account for the Coriolis effect, oh my.

I wasn't trying to model the system. I didn't have access to the system. Nor was I given data for the system. I was trying to show that if you have a model, the controller gains can be calculated and adapt to changing plant parameters. Notice that I made the shape of the tanks a function so that the effective gain of the tank will change as a function of the water level.
 

Similar Topics

http://www.pas.com/tunewizard I've been using this a lot lately, used to cost $10k but now it is free (hoping you will pay for support or buy...
Replies
15
Views
10,746
Hello, I am attempting to tune a PID loop on a process. The process involves a valve with electronic actuator that has quite a high deadband...
Replies
10
Views
1,907
so i have 4 25gpm wells feeding a 1000gal tank (T-1), with an additional 15gpm from a decant tank for 3hrs every 12hrs. P1 and P2 both controlled...
Replies
154
Views
34,540
Hi everyone, yet another PID problem. I'm hoping I understand enough of the process I'm controlling that my request for help is reasonable. If a...
Replies
113
Views
26,616
I haven't had to tune a PID loop in a very long time. It's actually a PI loop for a pulse width modulation s.v. What was the name of that tuning...
Replies
16
Views
3,926
Back
Top Bottom