OT: Basic Python PID Simulator

This is pretty neat! I expect to see Peter and drbitboy in here shortly to bicker about it, as is customary :ROFLMAO:
 
This is pretty neat! I expect to see Peter and drbitboy in here shortly to bicker about it, as is customary :ROFLMAO:


I think it's sweet. I wonder if OP would be interested in adding another control algorithm class cf. here.

Most Linux environments would run that out of the box, once the pre-requisites are installed.

I wonder how many Windows 10 folks know that can be run as well in their environment, with a half-hour or so of setup (WSL, PuTTY, X server, etc.; or maybe that can run native Windows?).
 
Last edited:
What are the units for the open loop gain? What are the units for the controller gains? Normally FOPDT systems have integrator and differentiator time constants.


IAE works but ITAE works better when the PV takes step jumps. The reason is the accumulated error is huge at the beginning and there is nothing that can be done about it. Later one the fine adjustments are small compared to the initial error. ITAE doesn't accumulate a lot of error at the beginning and amplifies the error as time goes on. It is a simple change.
 
I think it's sweet. I wonder if OP would be interested in adding another control algorithm class cf. here.

Most Linux environments would run that out of the box, once the pre-requisites are installed.

I wonder how many Windows 10 folks know that can be run as well in their environment, with a half-hour or so of setup (WSL, PuTTY, X server, etc.; or maybe that can run native Windows?).

Will have a look at that, or you can just fork it.

You can create a portable exe when Python is setup with pyinstaller...


What are the units for the open loop gain? What are the units for the controller gains? Normally FOPDT systems have integrator and differentiator time constants.

IAE works but ITAE works better when the PV takes step jumps. The reason is the accumulated error is huge at the beginning and there is nothing that can be done about it. Later one the fine adjustments are small compared to the initial error. ITAE doesn't accumulate a lot of error at the beginning and amplifies the error as time goes on. It is a simple change.

Open loop gain is in %EU/%Controller Output
Ki is in seconds and Kd is 1/seconds.
IAE was just for simplicity, changed it to ITAE and added noise.

Here's a quick compare of two tunes, noise is the same for both runs.
No1.JPG No2.JPG
 
Suggstions for additional features in the PID class:

  • Input filtering
  • Output filtering (D-term only?)
  • Input deadband
 
Suggstions for additional features in the PID class:

  • Input filtering
  • Output filtering (D-term only?)
  • Input deadband
Output filters are much better than input filters. Input filters have a severe affect on the closed loop transfer function.
Filtering the derivative is OK it it isn't necessary if you use the other filters.
I don't like the idea of a input dead band. It is a kludge.
I would add having a steady state PV. I all it PVss. When the control output goes to 0 the temperature doesn't go to 0.
I would add SOPDT.
I had all these done 5 years ago and no one seemed to care. Also, since then Python has made little changes so I must modify my old code to work with the new python. I don't like that. My odeint didn't work. I looked up the documentation to see what had changed only to find out that odeint is/has been superseded by another function :(
I haven't touched python since I became retarded, I mean retired.
This is 10 years old. I show how to derive the controller gains for a FOPDT system. Unfortunately it is written in Mathcad so Mathcad is necessary to play around with it.

https://deltamotion.com/peter/Mathcad/FOPDT/Mathcad%20-%20FOPDT%20I-PD.pdf
My example shows how to implement the PVss. It shows how to calculate the controller parameters given the plant parameter and a desired time constant.
Notice that my formulas will compensate for very long dead times, 10 min in my example, but there is a limit. If the dead times are too long then a Smith Predictor is required.

No one cared years back.
 
Last edited:
Does this site allow you to attach the mcdx file or is it available somewhere for download?
 
Though my memory is far less than perfect, I don't remember recommending an input filter for PID control, though I see no problem with it when applied appropriately. I did suggest adding an input filter as a feature to the Python PID class posted in this thread.

The primary reason for an input filter would be to smooth the display of a PV to shut up ignorant people (i.e. managers) who confuse the presence of noise (Common Cause Variation) with a failure to adequately control the process.

I find extraordinary the claim that the effect of adding an input filter on the closed loop system is significantly more severe than a filter on the PID output: both will slow down the system response to unfiltered PID output changes.

The primary precondition for filtering the input would be the presence normal (Gaussian) random noise in the PV i.e. variation in measurements that is present even if the CV is not changing the the process is otherwise in steady state. I.e. "Common Cause Variation."

A dead band on PV will do the roughly same thing as an input filter, or an output filter for that matter, when the process is at setpoint, Again, this assumes normality of the measurement noise. The purpose is to avoid "chasing noise" i.e. trying to control that which cannot be controlled; in fact, if the is noise in the PV measurement of a process to CV changes, then the PID will actually increase the noise in the PV relative to the uncontrolled system i.e. with the PID turned off. Filtering the output, or the input for that matter, will, I suspect, also increase the noise relative to the uncontrolled system, because some noise will always make it through the filter; that increase will be far less than in the unfiltered situation, of course.

A properly-set dead band will ignore the noise once the process is both at setpoint and at steady-state. The suggestion, in another thread, to oversample the PV, to pick up the highs and lows in order to estimate a mean or median value (PV) being controlled, is conceptually similar to using a dead band.
 
sir BRBB, please see Scadda post and have a stress relieving sherry or 3, although l am loving the challenge between someone that has made hopefully a lot of money out of his knowledge against someone that knows his stuff and helped put rockets in space, it really is fun. ah 2022 should be interesting.
 
The beauty of a non perfect memory (which l think you have) is that you don't need it, surprise e surprise you just look back at the previous post. snigger snigger you hadn't thought of that had you, snigger, snigger.
 
Though my memory is far less than perfect, I don't remember recommending an input filter for PID control, though I see no problem with it when applied appropriately. I did suggest adding an input filter as a feature to the Python PID class posted in this thread.
Do you know how to generate transfer functions using Laplace transforms? There is a significant difference between having an input filter and a output filter.


The primary reason for an input filter would be to smooth the display of a PV to shut up ignorant people (i.e. managers) who confuse the presence of noise (Common Cause Variation) with a failure to adequately control the process.
There should be ignorant manager filters. I have an example of this but I won't go into it here.


I find extraordinary the claim that the effect of adding an input filter on the closed loop system is significantly more severe than a filter on the PID output: both will slow down the system response to unfiltered PID output changes.
Yes, but an input low pass filter doesn't change the characteristic equation. An output filter just adds another pole and doesn't change the tuning.



The primary precondition for filtering the input would be the presence normal (Gaussian) random noise in the PV i.e. variation in measurements that is present even if the CV is not changing the the process is otherwise in steady state. I.e. "Common Cause Variation."
Look at my simulation here.
https://deltamotion.com/peter/Mathcad/SOPDT/Mathcad - SOPDT SP vs FC.pdf
I don't implement an input filter. I added noise, dead time, and feedback resolution so the temperature feedback has only 0.1 degree resolution. For the floating control I do implement a dead band the right way. The dead band is not wide enough to remove all the noise but since the integrator has such a long time constant, the noise really makes no difference.



A dead band on PV will do the roughly same thing as an input filter, or an output filter for that matter, when the process is at setpoint,
Close but no. The dead band will ignore drifting from the set point within the dead band. If the noise is Gaussian the noise will filter out to the true value.



Again, this assumes normality of the measurement noise. The purpose is to avoid "chasing noise" i.e. trying to control that which cannot be controlled; in fact, if the is noise in the PV measurement of a process to CV changes, then the PID will actually increase the noise in the PV relative to the uncontrolled system i.e. with the PID turned off.
If the sample time is slow relative to the response of the system then a bad reading may cause the system to respond. However, if the sample time is fast then the noise averages itself out.



Filtering the output, or the input for that matter, will, I suspect, also increase the noise relative to the uncontrolled system, because some noise will always make it through the filter; that increase will be far less than in the unfiltered situation, of course.
The filter will not increase the noise. Some noise may make it through the system but if the sample time is fast relative to the system response it will average out.



A properly-set dead band will ignore the noise once the process is both at setpoint and at steady-state.
Yes, but the system will not be a steady state. It will drift within the dead band. What if the noise is greater than the dead band? I made my simulation difficult on purpose. The dead band is 3 degrees but that is also the standard deviation of the noise so about 35% of the readings are outside the dead band.



The suggestion, in another thread, to oversample the PV, to pick up the highs and lows in order to estimate a mean or median value (PV) being controlled, is conceptually similar to using a dead band.
No! How can you say that? Where is the dead band? There is no dead band. The goal is sample fast enough to get a true reading of the average pressure. Do you remember Nyquist? Actually one needs to sample faster than that.



I, my company, does a lot of hydraulic servo control. Some applications require doing force control. The ripples from the pumps are evident in small systems as in the thread above. This is one reason why I insist on using accumulators. Accumulators are like a low pass filter in a way but actually the integrate, store, energy in the form of compress nitrogen. This allows one pump to store energy for many actuators whereas servo motor systems must size each drive for the peak power required for each axis.
 
Sorry for my indulgency, this is how some people learn (of course l include me in that statement)
P watch out he is pretty(understatement) smart, poke the computer at your possible peareal
You do know D an't going to lay down.
 

Similar Topics

I like to understand and know how to write a basic python code to connect and interact with Siemens PLC S7-300 and S7-1200 using Snap7. Please...
Replies
13
Views
11,114
Hi all, I have a noob question regarding data handling from sensors. I understand configurations and I/O mapping sensor input/output variables...
Replies
2
Views
195
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
0
Views
391
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
10
Views
1,906
I’m a bit stuck on HMI (KTP-1200) programming… See the picture attached. The PASS or FAIL box should only appear when the toggle switch is...
Replies
7
Views
1,003
Back
Top Bottom