# How To Interpret PID Output in a Slow Response System

@Update: A few days have passed since I asked this question and I've had a chance to do some research based on the answers I've received from @R Drast and @Spehro. I'm not sure this update is the correct thing to do, but my new questions are still related to the original topic and the title is still relevant.

I hadn't realized that "Position" and "Velocity" are two types of algorithm that determine how the PID output is treated (probably obvious from my original responses below). Oddly enough, I figured the incremental and relative (velocity) method was, intuitively, the most appropriate for my situation and yet it was roundly rejected in the previous answers. So, I have some questions about the position method relating to my specific setup (measuring temperature, large dead-time, etc).

Firstly, I want to make sure I have a correct understanding of how the position method actually works. I understand it to mean that you assign a PID output to each (valid) position on the actuator. For example, a PID output of -3V would be one extent of the actuator, say fully retracted (i.e., window closed/least ventilation) whilst 3V would be the other end (fully extended or maximum ventilation). This would put zero somewhere in between. Do I have this right?

If the above understanding is correct then that would mean you pre-determine the point on the actuator when the error is zero. Is that right?

So, how do you deal with the following scenario: it's mid-morning and 25 degrees in the gh. The SP is 25 degrees and the actuator is fully retracted, the error is 0 (so this puts the zero position as: actuator fully retracted - fair enough). As midday advances, the temperature goes up, the actuator pushes the window open and the temp in the gh falls again. Now we have a new 0 point actuator position. You can't ask the actuator to go back to the original zero position, that would close the window!

I obviously have gone wrong somewhere and I don't quite follow what @R Drast and @Spehro have said below. Can you guys (or anyone else) put me straight on this??

==================================================================== Original Question:

I'm relatively new to electronics and I've been working on a temperature controller for my greenhouse for some time now. The system comprises a PID controller and linear actuator all orchestrated by a microcontroller, ATTiny 2313 most likely (see images). The block diagram doesn't capture it, but the actuator is end stop controlled and the LDR is there to close everything up at night. My original intention was to do this without a microcontroller and so pieces like the DAC seem a little redundant now (although I expect I'll save some pins on my uC). That's the background, with most of the individual components built and tested at this stage.

My question is this, how should I interpret the PID output in a system whose feedback is slow? I understand the PID output to be a control "command", so when the PID output is +2V it's saying "adjust the system output by +2V to reach the set point target". I can understand this for say motor speed control where the feedback is rapid. There's little chance the system will be over-stretched owing to a slow system response since the motor will respond immediately to the PID command and in the next instant the command will have changed appropriately.

Just to be clear and in response to a comment by a responder, I understand that the command is "positional" which makes sense since a PID output of 0 means don't move from your present position, the setpoint has been obtained.

However, I can see (using my prototype setup, see image) that the command from the PID can be output for quite some time owing to the slow system response driving the actuator to the end stop. One idea I had was to slow down the command delivery by sampling the PID output (using the uC) every so often and then acting accordingly. This is an attempt to match the command to the system response but I'm not sure if this is the right thing to do. What's the best thing to do here? (Apologies for the quality of the PID Controller circuit diagram. It was difficult to fit it all on the one image).

• By 'end-stop controlled' do you mean that the actuator can only be fully open or fully closed?
– Chu
Commented Apr 9, 2015 at 9:20
• I mean the actuator is fitted with micro-switches (barely visible in the image) that limit its travel in either direction. Commented Apr 9, 2015 at 9:30

You shouldn't be using the PID output as a velocity command in your system, as it will simply become unstable and eventually oscillate between one end limit and the other, or have no response.

Using a linear actuator as you are, you should use the output of the PID as a position command, and have the actuator follow the output that way. By setting the PID min and max limits, the end of travel switches are only safeties if something goes horribly wrong.

Also, if you detect that your PID is at either limit (which it might have to be if the response is very slow), you want to inhibit the integral term for as long as it is at a limit so that you don't suffer from integrator wind-up.

PID's work fine on motor controls, true, but I use them industrially to control temperatures easily on systems with several minutes of lag. Tuning is everything... Remember the basics, Proportional gain will only get you (approximately) half to three quarters way to the setpoint, Integral gain will take you the rest of the way. Derivative tempers the change.

For temperature control loops with a long lag, I find it much easier to ramp the setpoint up slowly to the final setpoint rather than jump it immediately, it allows a tighter tuning of the PID without having it go into oscillation.

• I've edited the question to point out that I understand the command to be "positional" in case there is any confusion. The problem I have is interpreting this positional command. Does a max PID limit mean position the actuator at the very end of its travel? Does this happen at every instant? Or should the response of the actuator be scaled in some way. I like your idea of ramping up the setpoint, but I'm not sure how that would work with my system. Commented Apr 9, 2015 at 10:58
• One other point, given that the gain of each stage is POT controlled I'm struggling to figure out a way to shut-off the integral when the limit is reached. Commented Apr 9, 2015 at 11:02
• First: Above all, do NOT try to fake out the PID by twiddling with it's output, that will make the loop untunable and unstable. The PID Limits I spoke of are electronic or software clamps on the PID CV (output/Control Variable). Once the CV hits a limit, the integrator is suspended so that it doesn't continue to wind up. If you are actually controlling position, it might be that your integral term is too fast. Commented Apr 9, 2015 at 12:06
• Try the very basic of PID tuning: Set I and D terms to zero, then increase P until you can observe oscillation around your target. Then reduce P until the oscillation stops, and a "little bit more". Then start increasing the I gain (slowly) until you actually reach your target. Commented Apr 9, 2015 at 12:08
• @Buck8pe If the output winds up with the I Term set at zero, then there is an error in the PID equation. P is just Pout=(SP-FB)*Pgain There is no room for windup there. Jerky outputs can be caused by the D term, which is (generally) Dout=dErr/dTime * DGain. Again, no windup should be possible. The I term is the integral of the Error (SP-FB) over time * IGain. The final three terms are summed together. (There are other forms of the equation, but this is the basic). If you have your I term 1M pot at ground, you should have no windup. It is not shown connected to ground though. Commented Apr 9, 2015 at 14:15

Your 'I' term tuning range is too low by a huge factor.

Normally you'd want a time constant adjustable in the minutes (perhaps adjustable from 1 to 30 minutes) -not seconds- range for a largish thermal control system. What you've shown there will just work to nicely destabilize the control loop. You often don't really need I control anyway- a proportional control with high gain can do a lot (and the gain can be higher if the I term isn't in there nibbling away at stability- even when it's properly tuned). If you insist on using it, you'll need a much bigger low-leakage capacitor, an op-amp that's better and a much higher value resistor or to do it digitally. There are also tricks that can be played with lower voltages and very low leakage op-amps.

You generally want to reset the integrator or at least stop integrating when the output is railed or you'll get integrator wind-up which will cause overshoot and maybe even instability as the process variable reaches the setpoint. The best method for that depends on the scheme you're using, but it could be an analog switch or a reed relay.

• Yes, it sounds like I should disable the I contribution and see how I get on. But, I'm still confused by how I should interpret the output. Integrator contribution aside, when a difference between SP and FB appears (at startup or the sun comes out - doesn't happen often where I am:-) should I just experiment with how output voltage relates to movement? So, 2V might mean open the window another 2cm (n encoder blips). Commented Apr 9, 2015 at 15:36
• Pick a proportional band that is sensible- say 3 degrees C. For the temperature -1.5°C (or beyond) from setpoint your actuator is at one extreme, and for the temperature +1.5°C (or greater) from the setpoint your actuator is driven to the opposite extreme. It's usually best to react as quickly as possible, but not all actuators will behave well with frequent changes, and/or your error signal may be too noisy. Filtering tends to destabilize the closed loop system but you may have to do it to some degree. Commented Apr 9, 2015 at 15:52
• The integrator simply looks at the difference between the setpoint and the feedback, and sums it over time to generate an output term. Imagine a 1 second clock pulse, an integral gain of .1, and an error of 20. Every second, you take 20 * .1 and add it to the integral term. At t=1, I=.2 At t=2, I=.4 at t=3, I=.6. Now, if your SP = FB at t=3, then you have 0*.1 every second, so I remains at .6 The proportional term is just (SP-FB)* Pgain, and is added to the integral term for your final output. Commented Apr 9, 2015 at 16:31
• Thanks guys I know this is going on a bit and @R Drast I understand PID theory pretty well but let me put it a different way (and I think Spehro is closest here). I assume (maybe I'm wrong) that the motor controller is "stateless", it has no memory of what went before. It just needs a command to position it forward or backwards and because this is a closed loop system this command (issued by the PID) is occurring as fast as possible. So, maybe it's a bit too obvious, but what I understand now is that I just say 1v = 50 turns of the motor and... Commented Apr 9, 2015 at 19:47
• if the system is slow to respond to ventilation the actuator goes to the extreme. Commented Apr 9, 2015 at 19:53