You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old December 22nd, 2021, 12:42 PM   #1
destination unknown
Member
Ireland

destination unknown is offline
 
Join Date: Jun 2010
Location: Ireland
Posts: 107
OT: Basic Python PID Simulator

A simple PID simulator for my first steps with Python, might come in handy for some demos

https://github.com/Destination2Unkno...nPID_Simulator

GUI.JPG

PID_Trends.JPG

Last edited by destination unknown; December 22nd, 2021 at 12:44 PM.
  Reply With Quote
Old December 22nd, 2021, 01:24 PM   #2
mylespetro
Supporting Member
Canada

mylespetro is offline
 
mylespetro's Avatar
 
Join Date: Dec 2015
Location: NS
Posts: 696
This is pretty neat! I expect to see Peter and drbitboy in here shortly to bicker about it, as is customary
  Reply With Quote
Old December 22nd, 2021, 02:12 PM   #3
saultgeorge
Lifetime Supporting Member
United States

saultgeorge is offline
 
saultgeorge's Avatar
 
Join Date: Jul 2015
Location: Detroit
Posts: 532
That's pretty cool! Basically 3 minutes until the process went stable.
__________________
"Instant success teaches one nothing. Failure provides the tools and instructions one needs to succeed."
  Reply With Quote
Old December 22nd, 2021, 02:23 PM   #4
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,710
Quote:
Originally Posted by mylespetro View Post
This is pretty neat! I expect to see Peter and drbitboy in here shortly to bicker about it, as is customary

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?).
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (∞).
vi) Hakuna matata.
vii) Bookkeeping.

Last edited by drbitboy; December 22nd, 2021 at 02:27 PM.
  Reply With Quote
Old December 22nd, 2021, 03:27 PM   #5
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: The land of the woke and the home of the broke
Posts: 8,202
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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old December 23rd, 2021, 07:33 AM   #6
destination unknown
Member
Ireland

destination unknown is offline
 
Join Date: Jun 2010
Location: Ireland
Posts: 107
Quote:
Originally Posted by drbitboy View Post
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...


Quote:
Originally Posted by Peter Nachtwey View Post
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
  Reply With Quote
Old December 23rd, 2021, 08:39 AM   #7
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,710
Suggstions for additional features in the PID class:
  • Input filtering
  • Output filtering (D-term only?)
  • Input deadband
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (∞).
vi) Hakuna matata.
vii) Bookkeeping.
  Reply With Quote
Old December 23rd, 2021, 03:45 PM   #8
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: The land of the woke and the home of the broke
Posts: 8,202
Quote:
Originally Posted by drbitboy View Post
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/Mathca...PDT%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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon

Last edited by Peter Nachtwey; December 23rd, 2021 at 03:47 PM.
  Reply With Quote
Old December 25th, 2021, 01:15 AM   #9
durallymax
Lifetime Supporting Member
United States

durallymax is offline
 
Join Date: Sep 2017
Location: Wi
Posts: 64
Does this site allow you to attach the mcdx file or is it available somewhere for download?
  Reply With Quote
Old December 25th, 2021, 03:28 AM   #10
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: The land of the woke and the home of the broke
Posts: 8,202
Quote:
Originally Posted by durallymax View Post
Does this site allow you to attach the mcdx file or is it available somewhere for download?
What version of Mathcad do you have? The mcdx files can be zipped. Very few people have Mathcad and I wouldn't recommend buying it now. I would stick to Python now.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old December 25th, 2021, 10:49 AM   #11
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,710
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.
__________________
_
Brian T. Carcich
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good
v) I probably have the highest ratio of forum posts to actual applications in the field (∞).
vi) Hakuna matata.
vii) Bookkeeping.
  Reply With Quote
Old December 25th, 2021, 11:29 AM   #12
PLCnovice61
Member
Australia

PLCnovice61 is offline
 
Join Date: Apr 2015
Location: home
Posts: 364
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.
  Reply With Quote
Old December 25th, 2021, 11:32 AM   #13
PLCnovice61
Member
Australia

PLCnovice61 is offline
 
Join Date: Apr 2015
Location: home
Posts: 364
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.
  Reply With Quote
Old December 26th, 2021, 12:41 AM   #14
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: The land of the woke and the home of the broke
Posts: 8,202
Quote:
Originally Posted by drbitboy View Post
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.


Quote:
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.


Quote:

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.



Quote:
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/Mathca...%20vs%20FC.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.



Quote:

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.



Quote:

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.



Quote:

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.



Quote:

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.



Quote:

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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old December 26th, 2021, 01:09 AM   #15
PLCnovice61
Member
Australia

PLCnovice61 is offline
 
Join Date: Apr 2015
Location: home
Posts: 364
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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
PID loop question Tom W LIVE PLC Questions And Answers 7 August 21st, 2012 09:28 AM
PID temperature excel simulator rlawson LIVE PLC Questions And Answers 36 February 14th, 2011 05:47 AM
Use a PID? MarBa LIVE PLC Questions And Answers 4 May 8th, 2003 09:31 PM
how often should I trigger the PID? Ron Beaufort LIVE PLC Questions And Answers 11 February 22nd, 2003 11:57 AM
Cascading Sparky LIVE PLC Questions And Answers 24 February 17th, 2003 12:33 PM


All times are GMT -4. The time now is 05:25 AM.


.