PID Conceptual Question - Page 1
Forum section: electronics / beginners

author: gigavolt
author_rank: Contributor
timestamp: April 05, 2023, 06:49:24 am
content: I am having some trouble understanding a system I want to control with a PID loop. The system is like this: I have an object I can move over a surface in x, y, and z (z being the direction normal to the surface). As I move in x and y, I would like to keep the object a fixed height above the surface which can vary in z position.My process variable is the distance from the object to the surface and the control variable is the z height of the object which I can directly change. My confusion is that in every PID tutorial I see on the internet, the control variable is some sort of rate. For instance the current to a servo motor. However, in my system, I can sort of directly manipulate the control variable.This seems weird to me because if I imagine just using proportional control for my system, the error will never go to zero. My question is if the problem is formulated incorrectly. I can imagine making my problem look like the other problems by having the PID output go to an integrator before controlling the z position. That way it outputs a rate. But, is this necessary?It would also be great if anyone can point me to the name for this type of system (if there is one). I've been trying to find reading online about it, but it's tough when you don't know the keywords to search.

author: Kleinstein
author_rank: Super Contributor
timestamp: April 05, 2023, 07:11:16 am
content: One usually can not directly contol the variable to regulate - one may think so, but the real system usually has delays and imperfections. A typical such example is an voltage regulator with a transistor as emiter follower. To a first approximation one gets the direct control, but still has to correct for errors.The mechanical system would be similar: one has the actuator to move the target, but there is a delay. If the actuator would be perfect one would not need the regulator at all.There are different systems to control, some are more integrating (e.g. many thermal systems) and other are more proportional. Depending on the system one may need different parameters for the PID regulator and some simpler versions like PI, P of a pure I regualtor may or may not work well. Some of the rule of thumb type adjustment rules may also not work for all systems.

author: ebastler
author_rank: Super Contributor
timestamp: April 05, 2023, 07:25:21 am
content: Quote from: gigavolt on April 05, 2023, 06:49:24 amMaybe you could describe your actual system a bit further. Is this just a simulation, so you indeed have perfect and direct control of the object's Z position? If so, I would indeed not see the need for a PID controller: Just set the Z height to the desired "landscape height (X, Y) + delta_Z". This amounts to a P-only control loop with infinite gain.If, on the other hand, this is a physical system, I would doubt your claim that you can control the object's Z position directly. Depending on the type of drive and sensors, there will be phase lag, slew rate limitations, noise on the measured Z positions etc. These will require proper PI or PID control to obtain a stable control loop.

author: Whales
author_rank: Super Contributor
timestamp: April 05, 2023, 07:47:06 am
content: > My process variable is the distance from the object to the surface and the control variable is the z height of the object which I can directly changeThose two variables are the exact same thing, worded differently.If you are fighting gravity: I assume you can control Z force (motor power/current) and measure Z position (distance). Z force will not be zero once your system is stable.If your system has so much friction you don't have to worry about gravity: Z force could end up being zero at the end, or some other number nearby (the sticky static friction will give you a wide berth).In both cases a well calibrated PID controller will help you avoid overshooting your goal Z position (underdamped), oscillating around that position (unstable), not quite reaching the position (offset) and too slowly reaching the position (overdamped). Alternatively you might want one of those features for some reason (eg overshooting might be OK), it's up to you.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 05, 2023, 07:53:51 am
content: What, your process variable is the distance, and also your control variable is distance? So you can already directly control the result? Sounds like you don't need a feedback loop at all, just... distance_out = measured_distance - surface_heightPID loop would come handy if you had distance measurement, and had to output a speed setting for a motor.In a complete system, you could have many PID loops working in cascade:PID1: measured distance -> motor speedPID2: motor speed -> motor currentPID3: motor current -> power stage transistor duty cycle

author: armandine2
author_rank: Frequent Contributor
timestamp: April 05, 2023, 08:15:29 am
content: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7038364/not behind a paywall - might be a useful read.I seem to remember that lesson 101 here is closing the loop on a voice coil actuator (loudspeaker)

author: gigavolt
author_rank: Contributor
timestamp: April 05, 2023, 04:21:22 pm
content: OK, so I guess I shouldn't say that I can "directly" control position. Yes, there will be delays and noise on the real signal.The actual system is a scanning probe microscope. A fine tip will be rastered across a surface and give some sort of signal related to the distance of the tip from the surface. The height will be controlled by a piezo actuator. So, the displacement is proportional to voltage, but yes there will be some response time for it to act. There might also be some nonlinearity in the response.So, people just use PID loops on systems like this without turning them into "integrating" systems?

author: Terry Bites
author_rank: Super Contributor
timestamp: April 05, 2023, 04:26:32 pm
content: Liberate Sci.Hub!

author: Siwastaja
author_rank: Super Contributor
timestamp: April 05, 2023, 04:31:50 pm
content: Quote from: gigavolt on April 05, 2023, 04:21:22 pmSounds like there already is PID (or something similar) that controls the piezo actuator. Meaning, all the hard work is done. If it accepts position input and you want to control position, I can't see how you would add any feedback loop in that mix.A PID loop won't help with noise. If delay is excessive, it needs to be taken into account somehow, for example delaying the other control signals the same amount or just reducing speed or something like that.If the thing is wildly nonlinear and inaccurate and your measurement is more accurate than the accuracy of control, then yes you can and should add a feedback loop like PID. Then the process variable is simply the measured distance, and plant output is the control "distance" setting. Addition of a feedforward term could be a good idea, it would do most of the job with perfect response time, and PID terms would then help correct with offset, gain, linearity errors.

author: gigavolt
author_rank: Contributor
timestamp: April 05, 2023, 04:41:39 pm
content: Quote from: Siwastaja on April 05, 2023, 04:31:50 pmWell, not quite. There is only a piezo actuator and I directly apply a voltage to it. The material expands / shrinks as you change the voltage. There isn't any extra circuitry.

author: gigavolt
author_rank: Contributor
timestamp: April 05, 2023, 04:45:00 pm
content: Ok, and doing some more reading today, I think the term is "self-regulating" process.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 06, 2023, 06:36:59 am
content: Quote from: gigavolt on April 05, 2023, 04:41:39 pmOK, I misunderstood originally then. It's clearly a job for a feedback loop. But it's not going to be difficult because your plant output is so close and similar to process variable; you are basically just removing some nonlinearities, unknown gain errors and offset errors.(In a perfect world, if the actuator behaved always the same, you could just measure the response and create a lookup table, no feedback loop necessary. But if the response isn't perfectly reproduceable, you will need a feedback.)I would start with a feedforward term, then add P and I terms:Output = ff_gain * position_setpointAdjust ff_gain and see how close you get. Then add feedback:err = (measured_position - position_setpoint)Output = ff_gain * position_setpoint + p_gain * errPlay around with p_gain to see what it does. Adjust p_gain until you have oscillation and then halve it.Now it should behave all good except a SMALL error that remains; it should go quickly tonearlydesired position, not overshoot, not oscillate. Then add I term to get rid of that small offset:err = (measured_position - position_setpoint)err_integral += errOutput = ff_gain * position_setpoint + p_gain * err + i_gain * err_integralStart from i_gain = 0 and bring it up carefully.

author: MrAl
author_rank: Super Contributor
timestamp: April 06, 2023, 07:01:40 am
content: Quote from: gigavolt on April 05, 2023, 06:49:24 amHello there,In a control system integration is used to force the steady state error to zero, or very nearly so. This means most systems will have some sort of integrator in there. Steady state simply means the time when the controlled variable gets to a steady level. Although that sounds like it should be forever, it can be for 1 second, 100 seconds, or even just 1 millisecond or less depending how fast the system is.The idea with these systems is to integrate the error. The error is the difference between what you set the system to and what the system actually gets to when it reaches steady state. For example, if you set the system to 1 millimeter and the actual height measurement is 0.9mm, then the error is 0.1mm, and it could be plus or minus depending on the actual polarity of everything else.The reason for the integration is because an integrator has a very high gain when given time. For example, during the first microsecond the output with an error of 0.1mm may be just 10 microvolts, but then after 10 microseconds the output may be 100 microvolts, and as more time passes it just gets higher and higher. In a feedback loop however it eventually levels off to the right value in order to get the error to be 0mm or nearly so.The integrator has a large internal gain and so no matter what the error is, no matter how small, it can always produce a signal that will force the control variable to go up (or down) such that it eventually senses an error of zero. It does this by ramping up until the feedback meets the controlled variable, so they are equal and thus no error. There is actually zero limit in theory, but in practice there is usually a small error caused by the fact that the integrator can not actually have infinite gain. It will usually have very high gain though so it works well.This is the beauty of these systems. By measuring the difference in height and height setting, the integrator can eventually force the height to be the same as the height setting. There is a time before this actually happens, and that is usually referred to as the settling time. The time between when you go from steady state (from the previous setting) to the response which can be from your change of setting or some disturbance that enters the system.A simple example is a voltage regulator. If a load is applied the output temporarily goes down, and the error amplifier detects this, integrates the error, and produces a signal that will bring the voltage back up. It would be normal for it to bring it too high, and thus sense an error too high, then bring it back down a little, and after several iterations of this kind of action it settles into the steady state. When it does that, it is called ringing. Some systems do not incorporate any ringing so they ramp up smoothly to the right level, but they are generally slower than systems that allow some small amount of ringing because they get up to steady state faster.If any of this is not clear, just let me know i'll clarify.Sounds like a scanning electron microscope. [Edit: Scanning tunneling microscope]https://hackaday.com/2015/01/13/cheap-diy-microscope-sees-individual-atoms/

author: ebastler
author_rank: Super Contributor
timestamp: April 06, 2023, 07:42:10 am
content: Quote from: MrAl on April 06, 2023, 07:01:40 amNo, I don't think so. SEMs scan the sample with a focused electron beam from a relatively large distance. Scanning tunneling or scanning force microscopes are the types which scan and "profile" the surface by tracking it very closely.

author: armandine2
author_rank: Frequent Contributor
timestamp: April 06, 2023, 07:55:35 am
content: https://iopscience.iop.org/article/10.1088/0022-3735/17/1/010/metabehind a paywall - but a classic

author: EPAIII
author_rank: Super Contributor
timestamp: April 06, 2023, 08:20:32 am
content: It is easy to get all tangled up in the fancy language used in these systems. Let me try to make it as simple as possible.First, a servo system is a system that attempts to make a MEASURED value equal to a DESIRED value. In the fancy language, the measured value is called the "process variable". And the desired value is the "control variable". These two values should be expressed in the SAME units. Those units can be distance, linear velocity, rotational velocity, time, or any other physical units. The important thing is they must be the same type of units: distance and distance, velocity and velocity, etc.The actual serve system can use different technologies: mechanical, hydraulic, pneumatic, electrical, or electronic. Most are electronic. But in any case the two values, measured and desired, must be translated/expressed in the same manner and in a manner that is understandable by the actual, servo technology. Since most servo systems are electronic, that manner is usually a Voltage.So in your case a distance must be measured with a sensor that translates it into a Voltage. And your desired value must also be expressed as a Voltage. That gives us two Voltages that become inputs to the servo system.For the time being I am skipping over the PID TYPE of servo. There are other types. But whatever type is used, the result of an electronic servo is usually another Voltage.That Voltage is then sent to some kind of amplifier or other circuit that converts it into the form needed to drive a device that physically corrects the measured value (the "process variable") to bring it the desired value (the "control variable"). That device is often a motor but can be any of many types of drivers. Depending on the type of that device, the amplifier or other circuit can convert that Voltage to a different Voltage range, a current, a series of pulses, a varying frequency or whatever is needed.The above process is called a closed loop servo. It is a closed loop because the two values are compared, an error is found, that error is amplified and/or processed, and that processed error is used to correct the process variable to make it match the control variable. The process begins again from the start and repeats on a continuous manner.Many of the other terms you will hear will be specific to one or more steps in the above process.Now PID: PID is the initials of Proportional, Integral, and Differential. The proportional is easy to understand. The error at the output of the servo circuit is proportional to the error between the two values. The greater the difference, the greater the P or proportional servo output. Of course, the proportional output must be in the proper direction to correct the error, not increase it.The integral component is a value that depends on the recent or not so recent history of the difference. If the error has been positive in the past, then it will add a correction in the negative direction. And vice-versa. This tends to provide a kind of smoothing component if the proportional output is jumping around.The differential component depends on the rate of change in the proportional error. If the proportional error is increasing rapidly, it can help bring it down. And vice-versa.These three components are added together (summed) to produce a single output Voltage. Most PID servo circuits will provide controls on each of them so a proper mix can be created.The instructions for the PID servo should provide, at least a good starting point for those settings. If not, start with the P at a moderate gain and the I and D fairly low. Then observe the system and adjust them accordingly. Of course, a good starting point can vary for different systems.Just to clarify, holding a given value (height above a surface) does not mean that the output of the servo will be zero at that point. It would be assumed that there is some force acting on the system, probably due to gravity and possibly other forces and some non-zero value of the servo's output would be required to counter those force(s).I hope this helps.

author: EPAIII
author_rank: Super Contributor
timestamp: April 06, 2023, 08:23:42 am
content: The "I" in PID is for Integrating.Quote from: gigavolt on April 05, 2023, 04:21:22 pm

author: gigavolt
author_rank: Contributor
timestamp: April 07, 2023, 06:29:45 am
content: Wow, that's super cool, thanks! It's funny, I had to look up phase sensitive detectors since I've only heard of them as lock-ins nowadays.

author: MrAl
author_rank: Super Contributor
timestamp: April 07, 2023, 10:22:23 am
content: Quote from: ebastler on April 06, 2023, 07:42:10 amHi,Yes wrong terminology...https://hackaday.com/2015/01/13/cheap-diy-microscope-sees-individual-atoms/

author: artag
author_rank: Super Contributor
timestamp: April 07, 2023, 11:14:29 am
content: Quote from: gigavolt on April 05, 2023, 06:49:24 amYou are correct. Although other posters in the thread have provided helpful and accurate information (I particularly liked MrAl's), they haven't, as far as I saw, addressed this. Yes, the control effort should work the same as the error. Only then will the PID integrator ramp until the error input is zero and the error is therefore also zero.Many systems are misused, as you, with the proportional gain acting on the error signal to cause a rate of change to the error. The reason we get away with this so often is because they're not pure effects. For instance, a heater integrates to make a temperature change. But there are also thermal losses which are much of the need for heat input, and they're proportional to a power of temperature (cube ? I forget). So they mask the misuse.If you do proper root stability calculations you will find it difficult to get a useful result unless your model of the system is correct, and likely will not be able to do it with pure PID - it will work better if it also has a feedforward term (a gain term on the target which compensates for losses).The result is that most people in industry don't use root stability equations to determine the PID terms. They use heuristics and experience to get a best effort.

author: Siwastaja
author_rank: Super Contributor
timestamp: April 08, 2023, 08:52:15 am
content: Really, P term alone cannot make the errorzero. Small enough? Possibly yes, P controllers are widely used, for example in room heating systems where it simply does not matter if the room temperature is 20.5 degC instead of the 21 degC setpoint; you just increase the setpoint manually to compensate - theuseris the I term!But there is nothing to be afraid about in the I term.Especiallyif the control does not run saturated at either end for prolonged time, adding I term is simple and harmless; bring the I coeff up carefully until you get rid of the remaining error.Now if the control might stay saturated to 0% or 100%, then you want to limit how far the I term will accumulate. I won't go into math because you will find examples of this.