OT: Basic Python PID Simulator

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.
I really don't expect people on this forum to follow the math. I have a YouTube channel "Peter Ponders PID". Most people bail out after about 2 to 3 minutes because they don't understand the math. This is sad. If a judge by the names, most aren't even Americans, Canadians or UK citizens. This is very sad.


drbitboy isn't my main concern. The problem I really have is that no one at my company wants to dive into the control theory. The math makes their brain hurt. This is sad.


What people should take away from these threads is that mathemagic is possible and could be worth $$$$
 
Update: I am not saying a dead band is always better than a filter; I am only saying it is another tool in the toolbox, and its benefits or detriments in any situation will come from knowledge of the entire system (process + control).

TL;DR

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.
It's been awhile (decades), I am working on refreshing that. But I do roughly follow what you have done.
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.

Yah I could be wrong here, but I don't see how either one does not delay, or at least attenuate, the response.

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.

Sorry, I have to disagree, but a dead band that ignores the drift has been set incorrectly. If the dead band is set correctly i.e. based on common mode variation i.e. actual noise, not signal, then when the actual signal drifts in one direction, the noise will "break through" that side of the dead band and the PID will respond. Noise that is Gaussian makes both approaches work.

An interesting aspect of this is that there is a delay, random to be sure, but a delay nonetheless, in how long it takes for the (first) breakthrough, so in that sense it has the problem as the filter. But since we are saying things like "if the sample time is fast then the noise averages itself out." then it does not matter.
The filter will not increase the noise.

I didn't say the filter increases the noise. What I said was that, in a system with input noise, a PID that responds to that noise, i.e. "chases the noise," will increase (amplify) the noise. Since a filter attenuates but does not eliminate noise, the filter-attenuated noise that gets through will be amplified in the system (system = process + control) by the PID.

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.

That dead band was set incorrectly, which is why you got that result. But an incorrectly-designed experiment proves nothing. That is why I try to always remember to qualify that the dead band has to be set appropriately/correctly. It should be set to 2-σ (95%) or 3-σ (99.7%), not 1-σ (68%). Obviously there is a tradeoff here between how immune it will be to noise vs. how long it should take to respond to drift, as noted above.

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.

If we sample at a high rate, and take the extrema over some period, in order declare their midpoint as the actual signal, then that is roughly akin to empirically determining the dead band limits. Yes, that is not an actual dead band, because an actual dead band is fixed around the setpoint (only), but it is saying "ignore all variation between these two limits as noise," which is the same concept, roughly, as a dead band.
 
Last edited:
Yah I could be wrong here, but I don't see how either one does not delay, or at least attenuate, the response.
They both delay the response. The difference is that an input filter changes the characteristic equation.



Sorry, I have to disagree, but a dead band that ignores the drift has been set incorrectly.
I think we are saying the same thing. Read again.



I didn't say the filter increases the noise. What I said was that, in a system with input noise, a PID that responds to that noise, i.e. "chases the noise," will increase (amplify) the noise. Since a filter attenuates but does not eliminate noise, the filter-attenuated noise that gets through will be amplified in the system (system = process + control) by the PID.
You are assuming a input filter. Without an input filter the noise does get amplified but should be filtered on the output.



That dead band was set incorrectly, which is why you got that result.But an incorrectly-designed experiment proves nothing. That is why I try to always remember to qualify that the dead band has to be set appropriately/correctly. It should be set to 2-σ (95%) or 3-σ (99.7%), not 1-σ (68%). Obviously there is a tradeoff here between how immune it will be to noise vs. how long it should take to respond to drift, as noted above.
In my example the standard deviation for noise is 3 degrees. You are saying the dead band should be set to 9 degrees? OK.
https://deltamotion.com/peter/Mathcad/SOPDT/Mathcad - SOPDT SP vs FC 9deg db.pdf
I made a "noise" array so that both simulations will have exactly the same noise. The standard deviation is still 3 degrees. You can see that making the dead band wider at +/- 9 degrees makes things worse. Only 1% of the samples will correct the PV and nothing happens within the dead band.

I have also made the noise extremely small. The PV eventually just stops somewhere in the dead band.


If we sample at a high rate, and take the extrema over some period, in order declare their midpoint as the actual signal, then that is roughly akin to empirically determining the dead band limits.
Yes, that is not an actual dead band, because an actual dead band is fixed around the setpoint (only), but it is saying "ignore all variation between these two limits as noise," which is the same concept, roughly, as a dead band.

[/quote]
It is just a crude way of finding the average assuming the wave form is symmetrical. One could average all the points during one cycle too but it would need to be one cycle and that would vary depending on the pump speed. The results would be wrong if the averaging occurred over a wave length and a half.



BTW, we are helping Star Hydraulics with their servo valve testing. The test involves generating sine waves to the valve and measuring the response. The person doing helping out is using a FFT to estimate the the amplitude of the response but it would have been easier to just capture the high and low of the responses sine wave. The sampling is done at 8KHz. This is fixed. It is best if the sine wave frequencies are some factor of 8KHz. For instance. Sampling a 333 Hz sine wave means we don't always catch the peak. We have a technique where we use two samples before the peak and two samples after the peak to estimate the true peak. This works well. If one just samples a 333 Hz signal at 8 KHz and applies a FFT, it will not return the correct amplitude.
 
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.

I have access to 6.0.0.0, I like the speed of it for some things. Express does a lot of what I need but I have access to the full version when needed.

I will have to check out the channel, going through EE most of the YT I watched be it transfer functions, nodal, Laplace, mesh, etc was not native English speakers but I did appreciate that they tend to get to the point instead of ramble like some of the Americanos. I doubt I'll follow the math either, but keep some contacts that do enjoy that type of math and will pass it on.
 
Last edited:
I have access to 6.0.0.0, I like the speed of it for some things. Express does a lot of what I need but I have access to the full version when needed.
Is that a student version? Mathcad 6 was old back in the early 2000s. There is now a Mathcad Prime. I bet that is what you have. Mathcad is pretty good at symbolic math. wxMaxima and Mathematica are better. Python can do symbolic math but it is a kludge. Definitely learn python and wxMaxima because they are free. Here is an example using wxMaxima solving 17 equations for 17 unknowns to generate a 3rd order motion profile. Doing this by hand is tedious and error prone. The tools help you learn faster.
https://deltamotion.com/peter/wxMaxima/Seg1234567.html



I will have to check out the channel, going through EE most of the YT I watched be it transfer functions, nodal, Laplace, mesh, etc was not native English speakers but I did appreciate that they tend to get to the point instead of ramble like some of the Americanos.
I know what you mean about getting to the point.

I have my Mathcad examples done before I start videoing so I don't waste time typing and fixing mistakes during the video.



I doubt I'll follow the math either, but keep some contacts that do enjoy that type of math and will pass it on.
My channel is not for beginners. It is gear for grad students and people in the field. There are too many channels that explain PID control by saying this gain does this and that gain does that but they don't provide a good understanding of how the gains and plant work together.

I have over 800 Mathcad files on all sorts of topics. I started with the original Mathcad 3 back in the early 1990s.


BTW, there is a lot of stuff I learned in college that I NEVER used. However, Laplace transforms and differential equations are a must. Many things were taught back then. PID knowledge was crude. When I was going to college there was a class where a PID was made using op amps, resisters and capacitors.


You need to see my "Root Locus is Useless" video
https://youtu.be/uYhz3TuTkfM
I used the same example an Indian IIT professor used. He used 8 videos to show how to plot the root locus. However, at the end he didn't have a means of controlling the system the root locus was based on. I am no nonsense. If you want some entertainment there is my Fuzzy Logic vs PID where I blast a paper that was presented to some engineering meeting. It is obvious the committee that accepted that paper didn't know anything.
https://youtu.be/5389Mh6Xibo


Learn python, Laplace transforms, numerical analysis, differential equations and system identification. Be able to solve systems of differential equations.


A channel I like is "APMonitor".



If you want to be more specialized, learn FPGA programming. FPGA programming. An FPGA is like PLC that can execute all its rungs at once.


Above all, the the basics. I call this "forever knowledge" because it will never change. The tools, PLCs and motion controllers and languages are all fads and may be gone in 20 years.


Have fun, the futures belongs to the doers and designers.
If you have a question PM me. I have help students get their masters degree in the past. Forum member Pandiani is an example.
 
Is that a student version? Mathcad 6 was old back in the early 2000s. There is now a Mathcad Prime. I bet that is what you have. Mathcad is pretty good at symbolic math. wxMaxima and Mathematica are better. Python can do symbolic math but it is a kludge. Definitely learn python and wxMaxima because they are free. Here is an example using wxMaxima solving 17 equations for 17 unknowns to generate a 3rd order motion profile. Doing this by hand is tedious and error prone. The tools help you learn faster.

It is Prime 6.0.0.0. I've used it to solve multiple equations for multiple unknowns using solve blocks and have also used Mathematica quite often, but not much anymore. I'll look at wxMaxima.

My channel is not for beginners. It is gear for grad students and people in the field.

BTW, there is a lot of stuff I learned in college that I NEVER used. However, Laplace transforms and differential equations are a must.

If you want to be more specialized, learn FPGA programming. FPGA programming. An FPGA is like PLC that can execute all its rungs at once.

I have very little interest in grad school, but don't like to ignore things that can be solved with math. Hence the reason I kept the numbers of my much smarter peers that "see the math" and enjoy it. Laplace and DE were two things that were actually enjoyable, real world use for once.

We did FPGA's in VHDL and LabVIEW. I prefer VHDL but can see the appeal to LabVIEW for some.
 

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,905
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