On PID control

ErNaErNa Posts: 1,294
edited 2016-03-25 - 18:21:05 in Learn with BlocklyProp
While control loops are in the focus of engineers, physicists under normal conditions don't touch this issue. So what follows may look a little strange.

To start with, I wish to look for the most simple case: have a P control.

What is a controller good for? If something goes wrong, the idea is, to make it better. As this is very general, I want to be more destinct and introduce a simple example.
Imagine somethings (an object) exists, then, if not a ghost, it is in a place. This place now might be the place, I want the object to be. But, as there are many places, the probability that the object is located else is huge. We introduce the distance between the wanted place (set-value) and the actual place (is-value) as the "error" we want to minimize.

To correct the error we need an action. Like: apply to the object a directed force. But: how will the force change the place? Changing a place we call movement and movement is characterized by velocity. So how is the application of force related to that velocity? Our gut feeling says: the more force, the more speed we will gain, the faster the object reaches the set value of place. But from experience we know, an object has a property of mass. So acceleration and speed is not only related to force, but also to mass. An object without mass can not be controlled, as the minimum force will result in infinite speed.

For this reason, an object that has to be controlled MUST have a mass and so inertia.
Now the term "the faster the object reaches the set value of place" shows ambiguity. Two meanings: reach set position in short time AND at high velocity. So we do not reach the set value, but pass that value and introduce a new error.

A p-controller by definition creates a force, that is proportional to the error. If the initial condition is: no error, no force is created and nothing happens. But it there is an initial error (in a positive direction), there is a negative force, the object starts to move and gains kinetic energy. As long as the positive error exists, there is force and kinetic energy increases. That means: the moment the set position is reached, the speed is at maximum and the next moment we will have a negative error and generate a positive force which now decelerates the object. The moment the object is at stand still, the error will be the initial error but in negative direction. Now the game starts from the beginning.

What we see here is: a P controller in the case of a mass with inertia is nothing but a harmonic oscillator and without damping will oscillate forever if once excited.

That is, where the "D" steps in.
If there is no error at start-up, the system is at rest in peace. Now we establish an error by creating a displacement. That means, the error changes so the derivative is large. To correct the error we apply a force propertional to the error (the "P"component) and a second force proportional to the change rate of the error ( the "D" component). That means: with a D, the back driving force is higher and the error gets smaller. But now the derivative becomes negative and the backdriving force is reduced. When the compents P and D are properly adjusted, the D part over compensates the P part, that means, when returning to the set position, the object is decelerated and comes to stand still at the set position.

But what, if the D compensates oscillation, but the error doesn't come to zero? In this case P creates a back driving force, but there is no movement. That only can be the case, if there is another force of value -P, that has an unknown (external) origine. So, if a PD controller comes to stand still at an error position it actually is a weigh that measures an external force. To compensate this force we have to apply a third current, we call the "I" component.

Now we have a PID controller completed: The D components dampends the movement by controlled extraction of kinetic energy from the object. The P component brings back the object to the set position, but if there is still an error, this means the existance of an external force and this force is proportional to the error and compensated by the I component.


no reason to reason if you feel feelings: in love with the propeller

How-2-TACHYON
«1

Comments

  • I'll point out there can be many variations to the basic servo loop. Integral function in particular can have issues with what's called wind-up. More terms can be added, double derivative being one, splitting terms into feedback and feedforward components is another practise, but doubling/tripling up the whole servo loop by using multiple transducers is probably more common.

    Possible trivia: I've come to the conclusion that the three P, I and D terms are effectively a 3rd order filter.
    We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
  • By introducing terms of energy to understand PID-control (as a well known and well non understood method of controlling) I wanted to come around some of the problems normally seen. Not educated in filter theory I don't care how many orders a filter has ;-) If you follow what I wrote: "I" term is nothing but a constant force, so if "I" term winds up, I don't care because it just means: the force to correct the error exceeds the force, the system can generate. And I always try not to solve problems that are overwhelming.
    And using multiple transducers often seems to me a method of over-engineering: a lot helps a lot. Mostly not true.
    What I wrote up, is just a theoretical approach. Some experiments will follow (hopefully soon)
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • evanhevanh Posts: 8,248
    edited 2016-03-26 - 12:47:13
    Nothing wrong with what you've written. I was just adding some of the usual considerations that crop up when building or even just tuning such servo loops, and maybe highlighting conceptual ideas that are involved. I wouldn't say I know a great deal about filters either, the simple single term low-pass is about all I ever explicitly implement.

    Over-engineering is a hallmark of industrial automation.
    We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
  • That's ok and that's why I try to explain PID without using these terms in considering energy and inertia. If it turns out that observing the behavior of the control loop, state variables can be determined, then self adjusting of the control loop will be reality. And the propeller allows to observe what is going on in doing it in parallel.
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • ErNa wrote: »
    And using multiple transducers often seems to me a method of over-engineering

    Not at all. In an application where some form of backlash is inevitable, the motor mounted encoder cannot be relied upon for accurate positioning of the load. Mounting the single feedback device on the load instead, now creates the problem of loop instability, thanks to the mechanical lost motion.
    Failure is not an option...it's bundled with the software.
  • ErNaErNa Posts: 1,294
    edited 2016-03-26 - 15:54:03
    Right, but such systems should be an exception. And, seen from a different point of view: In such a case we have two independent control loops: one is to position and one is to control rotational speed of the motor. If there is backslash, it is a good idea to work in only one direction (that was the case in old times, when every milling and turning machine had a trapezoidal spindel. Today with the preloaded high precision spindels that should not be an issue.
    But with this discussion I want to focus on: how to understand PID control in terms of real world.
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • Multiple feedback devices ARE a very important aspect of PID control because the P term is often fed by one feedback device and the I term by another. And it's not just a backlash issue. A broken ballscrew or motor coupling will result in the load not even moving and the motor feedback device will give the impression that the load is where it's supposed to be. Try telling the owner of a self destructed piece of equipment that dual loop feedback is only "over-engineering". Dual loop feedback is more common than you seem to realise.
    Failure is not an option...it's bundled with the software.
  • When it comes to "real world" systems, multiple systems can create more safety. But I'm not looking from this side here. PID is a very old technique. But every newby has to fight with the same problems. Mostly recommendation is: increase P value until the system starts to oscillate, then increase D to dampen the oscillation. If there is a constant deviation, introduce I.
    I showed (not in depth) why a P control is nothing but an oscillator. And only side effects like friction dampen oscillation. But if there is oscillation we can determine the frequency and so there is a chance to exactly damp this frequency. And if e.g. load changes, frequency will change and still oscillation can be damped and as a side effect, load is determined.
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • Yeah, I realize that I am detracting from the point of the thread. My apologies. I welcome any thread that discusses PID/Prop with respect to motion control and I would like to see a heck of a lot more.

    As you are no doubt aware, REAL robots and REAL machining centers don't rely on open-loop stepper motors. As far as I am concerned, no feedback = no (verifiable) control.

    Cheers
    Failure is not an option...it's bundled with the software.
  • My intention is to go step by step forward. I plan to make a pendulum that is connected to a motor and have this pendulum when lifted, falling down and dampen the movement as far as possible (not by shorting the motor winding, that would be to simple). As real systems are more complicated than the models we create, it might be a good idea to apply a known loop structure and determine the systems reaction, so this opens a way to characterize the system more precisely. In a next step the control loop can be modified to reflect the knowlegde gained etc at infinitum...
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • Erna,
    Sorry, you have lost me on your pendulum-connected-to-a-motor.
    I cannot understand what you mean.
    Please add a sketch or a diagram.
    Many thanks.
  • I'm not sure what this thread is about anymore.

    Physicists do indeed look at such problems. For example they can build you a mathematical model of a triple inverted pendulum and then derive a control algorithm to keep it upright.

    Any way, yes, a physicist like to boil things down to the simplest case, like ignore friction, ignore latency in the control loop, ignore backlash and dead zones, ignore noise, etc etc.

    In that way you can probably derive perfect control strategies for many simple cases.

    In the real world, we have friction, backlash, latency, noise etc all of which is hard to measure and hard to build a mathematical model for.

    The end result is we often throw a PID control loop in and then tune the thing manually as best we can.

    Or we might use fuzzy logic, handy when the system to be controlled is hard to analyse rigorously.

    Oddly I was thinking about all this today. I just ripped an old hard drive apart. So now I have the head actuator to play with, nice arm with a coil at one end sitting between two super strong magnets. Turning on a nice smooth bearing. I was wondering how I would build a control system to position it.

  • The path is to create a simple, ideal system and solve this. Next a disturbance, like friction is introduced. And again a solution is searched. If a problem is solved with linear tools, it is a good idea to assume, the problem is linear. In this case, stepwise solution should work. We will see, how this discussion continues, there have to be practical examples. It' part of our current stepper driver development
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • I get the idea.

    Problem is that many systems are not simple to model. And hence not simple to derive control strategies for.

    For example, as far as I'm told by people that study these things, it's not possible to balance a two wheel bot using a PID.

    Turns out that people do that, perhaps with some hack or other, anyway. Without getting deeply into the maths of the thing.

    I'm not sure where the stepper motors fit in here.

  • I work with PID loops a bit, and with both mechanical and thermal systems I find that the D term is the least effective, and the most likely to cause oscillation. Quite often it is disabled altogether.
  • Paul, there is a reason, if I understand correctly: in motion control systems there is a inner loop, controlling current (torque), a next loop, controlling speed, and a third, controlling position. The inner loop can be a bang bang control, that is, whenever current is to low, apply positive voltage, and negative voltage, when current is to high. No P, I or D needed, because the more voltage you have (DC-link) the faster the current changes (in the inductance). So current control loop is simple ( in a second order approach, adjustable voltage is advantageous). Now the next loop controls speed, here things are differently: now torque can not be switched on and off due to the inductance, that means, the speed changes as a integral function of torque. The same story is true for position control were distance is integral value of speed. Now a D-term in position is equivalent to a P term in speed. Instead of tuning the D it's better to tune P. An error prevented must not be corrected.
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • There's something different about temperature control loops. They don't use the same algorithm as a servo - which is three independent terms. If someone comes across a good block diagram of a temperature controller that explains why the terms seem to be so intertwined, I'm all ears.
    We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
  • in motion control systems there is a inner loop, controlling current (torque), a next loop, controlling speed, and a third, controlling position.

    The motion trajectory generator simply increments the command position in a time-sliced fashion which inherently takes care of both velocity and position control. The PID settings are responsible for the motor following the motion trajectory in a tight and stable fashion.

    Digital Motion Control has been this way since Dr. Jacob Tal (Galil Motion Control, Rocklin, CA) developed the first DMC chip in the 1980's.
    Failure is not an option...it's bundled with the software.
  • evanh wrote: »
    There's something different about temperature control loops. They don't use the same algorithm as a servo - which is three independent terms. If someone comes across a good block diagram of a temperature controller that explains why the terms seem to be so intertwined, I'm all ears.

    Most, or at least the majority of the temperature control loops I have come across were using a PID loop or at least something that looked very much like the same algorithm of a servo control loop. The major difference I could see was was due to the increasing difference in temperature between ambient temperature and the heated sample or area. Can you post an example of both that shows the difference?
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • I have never tried controlling temperature but from reading around it does seem to be done with PID quite a lot. But there are a couple of difficulties:

    1) Huge latency in the control loop due to thermal inertia. If nothing else that makes it time consuming and tedious to tune the parameters.

    2) Control is asymmetrical. If you are controlling servo position, say, then you get a position error that can be both negative and positive, then you can drive the actuator negatively and positively. But when controlling temperature often you can only pump heat in if the temp is low but if the temp is too high you can't suck heat out, you just have to let it cool down in it's own good time. The rate at which it cools of course depends on the current ambient temperature. Basically the system is very non linear.

  • Nope, I don't. The difference was in the action when hand adjusting the gains. They seem to be somewhat interdependent. Luckily, for the most part, when using standalone temperature controllers, I can rely on auto-tune.

    The temperature control routines I wrote myself I just used the same algorithm as I've always used for motor control and those were easy to tune, but that doesn't seem to be the norm for temperature control.
    We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
  • Eg: When reading up on setting of Integral and Derivative terms I frequently bump into descriptions of duration instead of gain. Setting one appears to affect both. And when set, seems to even substantially overpower the Proportional term.
    We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
  • This is where I've picked up the impression of it being a multi-order filter.
    We have the vastness of the internet and yet billions of people decided to spend most of their time within a horribly designed, fake-news emporium of a website that sucks every possible piece of personal information out of you so it can sell it to others. And they see nothing wrong with that.
  • I hope it will show out, that introducing energy to the problem leads a path to intuitive understanding.
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
  • Heater. wrote: »
    I have never tried controlling temperature but from reading around it does seem to be done with PID quite a lot. But there are a couple of difficulties:

    1) Huge latency in the control loop due to thermal inertia. If nothing else that makes it time consuming and tedious to tune the parameters.

    2) Control is asymmetrical. If you are controlling servo position, say, then you get a position error that can be both negative and positive, then you can drive the actuator negatively and positively. But when controlling temperature often you can only pump heat in if the temp is low but if the temp is too high you can't suck heat out, you just have to let it cool down in it's own good time. The rate at which it cools of course depends on the current ambient temperature. Basically the system is very non linear.

    Controlling temperature is a more complicated proposition than controlling servo position because of those two factors. Add to that the variety of physical systems (furnace, oven, building, etc.) as well as the number of methods to add energy and it can be quite a task. Adding the ability to drive temperature negatively adds to the problem since energy costs need to be taken into account.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • evanh wrote: »
    Eg: When reading up on setting of Integral and Derivative terms I frequently bump into descriptions of duration instead of gain. Setting one appears to affect both. And when set, seems to even substantially overpower the Proportional term.

    Since all those terms use the difference between the set point and the desired position/temperature they do affect the output of the loop.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • ErNa wrote: »
    I hope it will show out, that introducing energy to the problem leads a path to intuitive understanding.

    I suppose it could be done that way but it would involve more complicated calculations than a pid loop, particularly for the most common task of heating a building.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • Every situation is different. For example:

    1) You want to control the position of an object from left to right horizontally. OK, wrap a PID loop around it and see what you can do.

    2) But now we turn everything through 90 degrees so the position is up/down rather than left/right. Now you have a constant force of gravity acting on it. That means that in the stable, zero error, situation you have to be applying an upward force that exactly counters the force of gravity. Well, perhaps the PID can sort that out but it might be an obvious idea to just apply that upward force constantly thus giving the object "neutral buoyancy" as it were. Then let the PID work on that.

    3) But what if this system is sometimes horizontal and some times vertical and whatever in between? Perhaps it's an idea to measure the inclination and adjust that force required to achieve neutral buoyancy.

    I really start to think I have to build some actuator system and play with this.

    I once had a good friend who was seriously into control systems engineering, he designed the active suspension control system for the Williams F1 cars when they were winning all the time. He was always on about "poles" and "zeros" whenever we got together for a beer. Sadly I never understood what he was talking about!



  • Heater. wrote: »
    2) But now we turn everything through 90 degrees so the position is up/down rather than left/right. Now you have a constant force of gravity acting on it. That means that in the stable, zero error, situation you have to be applying an upward force that exactly counters the force of gravity. Well, perhaps the PID can sort that out but it might be an obvious idea to just apply that upward force constantly thus giving the object "neutral buoyancy" as it were. Then let the PID work on that.

    3) But what if this system is sometimes horizontal and some times vertical and whatever in between? Perhaps it's an idea to measure the inclination and adjust that force required to achieve neutral buoyancy.
    The way I understand PID loops, in the stable, zero-error condition P & D are zero so the constant force compensating for gravity comes from the integral term. The analogous situation in temperature control of a heated volume is the loss of heat to the surroundings. That's what I is for. When the temperature is stable at the set point, P & D are zero leaving only the integral to apply the power that compensates for the lost heat. In principle, when the system is stable and the temperature is on the set point, I alone can maintain the desired temperature. In any real-world situation that isn't very likely and P & D will be constantly catching small deviations and nudging the temperature back to the set point. The integral should only change to compensate for things like room temperature changes, mains voltage variations that affect heater power, etc. In the system you describe I think you're right that you would want to sense inclination and change the integral term to get the compensating force close, then let the loop make any small tweaks to achieve stability.

    To compensate for integrator windup, my simplistic approach has been to disable changes to the integral term when the temperature is far from the set point. There are probably better ways to do it, however.
  • In my opinion, PID is not useful in the case of temperature control. To control temperature the only information you need is specific heat. If you need 3 joule to increase temperatur by 1 degree, and the temperature is 3 degrees to low, 9 joules are needed to get the right value. How to know specific heat? Apply a certain amount of energy and watch how temperature chances. Under normal conditions temperature will reach a maximum and the decay. Decay will show, how much energy is lost to the invironment and so add this energy per time to keep temperature constant. Whenever the system shows a different behavior, something unforeseen must have happend, so start over to determine new specific heat and energy loss. If for example it turns out that temperature falls quickly and spending energy shows no influence, likely the window is open. That means: any practical temperature control should not be done without knowing the system. Indeed, there is a science: calorometry. You characterize materials by placing them in a dewar and measuring the temperature change over time at constant energy spending. In doing so, phase transitions can be detected, most simple case: melting of ice.

    As far as I know, most house heatings are controlled manually and roi of automatic heating control is very poor ;-)
    no reason to reason if you feel feelings: in love with the propeller

    How-2-TACHYON
Sign In or Register to comment.