Home Brew Forums

Home Brew Forums (http://www.homebrewtalk.com/forum.php)
-   Automated Brewing Forum (http://www.homebrewtalk.com/f235/)
-   -   Manually tuning PID (http://www.homebrewtalk.com/f235/manually-tuning-pid-347697/)

MalFet 08-15-2012 12:17 AM

Manually tuning PID
 
Hello,

I've been gradually automating my fermentation chamber, particularly the mechanisms I use for pressurized fermentation. I use a mass flow controller to gently bleed pressure off of my fermentor in response to measurements from an in-line transducer. I use the PID library on an Arduino to keep my setpoint, and so far it has been working very well.

After a fair bit of trial and error, I've found PID coefficients that seem to keep me steady (Kp = 200, Ki = 1, Kd = 5). These keep me reasonably tight on my setpoint, and even during the height of fermentation I rarely drift more than a tenth of a PSI away.

But, in the course of keeping things steady, my control output (valve position) races around like a jackrabbit. At peak fermentation, I'll see something like 300 SCCM average, but at any given moment it will be anywhere from 200-400. I stay very close to my target pressure, but the flow rate oscillates on about a 90 second period.

Any suggestions for convincing my output to settle down? My instinct is that I should lower my Kp and increase my Ki, but I wasn't able to make this work immediately. Before futzing with it more extensively, I thought I'd put the question to the many here who understand this stuff far better than I ever will.

Thanks!

crane 08-15-2012 05:38 AM

Have you tried playing around with the PID update rate. I believe that the default for the arduino PID library is rather fast and if your oscillations are at a 90 second period then the integral may be winding up too much before the system responds to the change in output. You may actually want to decrease the integral because it may cause the output to change too much before the system can respond. Once the system does start to move towards the set point then it takes too long for the integral to unwind which causes it to swing past the set point in the other direction.

So I would try decreasing the integral gain and/or slowing down the update rate, but I may be completely wrong as its been about 4 years since I took feedback control theory in college.

MalFet 08-15-2012 11:49 PM

Quote:

Originally Posted by crane (Post 4332250)
Have you tried playing around with the PID update rate. I believe that the default for the arduino PID library is rather fast and if your oscillations are at a 90 second period then the integral may be winding up too much before the system responds to the change in output. You may actually want to decrease the integral because it may cause the output to change too much before the system can respond. Once the system does start to move towards the set point then it takes too long for the integral to unwind which causes it to swing past the set point in the other direction.

So I would try decreasing the integral gain and/or slowing down the update rate, but I may be completely wrong as its been about 4 years since I took feedback control theory in college.

Thanks for your suggestion. Unfortunately, it doesn't seem to be working. The slower sampling rate actually amplifies the swing on my control parameter, which is unfortunate because I was optimistic about your idea.

From what I understand about the algorithm, I feel like I should need to drop my Kp and raise my Ki, but as soon as I do that I start seeing my pressure swing.

Hmm...this is very perplexing.

FastTalker 08-16-2012 03:44 PM

Quote:

Originally Posted by crane (Post 4332250)
Have you tried playing around with the PID update rate. I believe that the default for the arduino PID library is rather fast and if your oscillations are at a 90 second period then the integral may be winding up too much before the system responds to the change in output. You may actually want to decrease the integral because it may cause the output to change too much before the system can respond. Once the system does start to move towards the set point then it takes too long for the integral to unwind which causes it to swing past the set point in the other direction.

So I would try decreasing the integral gain and/or slowing down the update rate, but I may be completely wrong as its been about 4 years since I took feedback control theory in college.

Slowing the update rate of the Arduino PID algorithm will adversely affect the integral term. The less often you update the integral accumulation the less accurate it will be. The sample time is taken into account in the integral calculation (as well as the derivative calculation). The only time you would need to increase the sample time would be due to the controllers inability to actually scan the code that quickly. So I would not recommend increasing the sample time.

kp=200 does seem quite high. High proportional gain can definitely cause oscillation.

Like you said backing off the kp will help. But without seeing a trend, it's hard to say which direction the ki needs to go.

You could back off your kp a lot, and let the integral do most of the work. The response will probably be slower but you will have less movement of your output.

MalFet 08-18-2012 01:50 AM

Quote:

Originally Posted by FastTalker (Post 4335817)
Slowing the update rate of the Arduino PID algorithm will adversely affect the integral term. The less often you update the integral accumulation the less accurate it will be. The sample time is taken into account in the integral calculation (as well as the derivative calculation). The only time you would need to increase the sample time would be due to the controllers inability to actually scan the code that quickly. So I would not recommend increasing the sample time.

kp=200 does seem quite high. High proportional gain can definitely cause oscillation.

Like you said backing off the kp will help. But without seeing a trend, it's hard to say which direction the ki needs to go.

You could back off your kp a lot, and let the integral do most of the work. The response will probably be slower but you will have less movement of your output.

Thanks for the analysis. This seems to have helped, though the fermentation ran out of steam before I could test it properly. I'm hoping these new settings will work well for my next batch, and I'll post more info then. :mug:

porcupine73 08-21-2012 07:27 PM

I haven't used this controller, but in general in control some aspects that might be used, especially if there is say a pressure range that is acceptable to maintain rather than an exact specific pressure, is to incorporate a deadband. That is extremely common in industrial control where you don't want your modulating valve making tons of tiny little movements all the time causing excessive wear and tear. Having the derivative gain set too high usually makes the system quite twitchy, the proportional can do that as well.

FastTalker 08-22-2012 02:03 AM

Quote:

Originally Posted by porcupine73 (Post 4349685)
I haven't used this controller, but in general in control some aspects that might be used, especially if there is say a pressure range that is acceptable to maintain rather than an exact specific pressure, is to incorporate a deadband. That is extremely common in industrial control where you don't want your modulating valve making tons of tiny little movements all the time causing excessive wear and tear.
...

Good point. However, the Arduino library doesn't include deadband functionality. That wouldn't be too difficult to add to the the PID library Compute() function if needed. Only update the output if the absolute value of the error is greater than your deadband value.

Poobah58 08-22-2012 02:59 AM

For starters, get rid of the derivative. It's not needed for slow changing process variables. P & I control is more than enough for your application. Might start to settle things out.

alien 09-20-2012 08:27 PM

Quote:

Originally Posted by poobah58 (Post 4350860)
for starters, get rid of the derivative. It's not needed for slow changing process variables. P & i control is more than enough for your application. Might start to settle things out.

+1

MalFet 09-20-2012 08:44 PM

Shifting the bulk of my coefficient magnification to the integral component seems to have done the trick. I still need to keep P relatively high, somewhere near 80 or so, to get the thing to settle in the first place. Thanks for all the help!


Quote:

Originally Posted by Poobah58 (Post 4350860)
For starters, get rid of the derivative. It's not needed for slow changing process variables. P & I control is more than enough for your application. Might start to settle things out.

Quote:

Originally Posted by alien (Post 4430064)
+1

Well, what do you guys mean by "slow changing"? I gain or lose 5 psi in less than 15 seconds.


All times are GMT. The time now is 02:50 PM.

Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.