Manually tuning PID - Home Brew Forums

Register Now!
Home Brew Forums > Home Brewing Beer > Automated Brewing Forum > Manually tuning PID

Reply
 
Thread Tools
Old 08-15-2012, 12:17 AM   #1
MalFet
/bɪər nɜrd/
HBT_LIFETIMESUPPORTER.png
 
MalFet's Avatar
Recipes 
 
May 2010
NYC / Kathmandu
Posts: 8,632
Liked 1473 Times on 975 Posts



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!
__________________
"Be excellent to each other." -Benjamin Franklin

 
Reply With Quote
Old 08-15-2012, 05:38 AM   #2
crane
Recipes 
 
Sep 2011
San Diego, CA
Posts: 612
Liked 77 Times on 64 Posts


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.

 
Reply With Quote
Old 08-15-2012, 11:49 PM   #3
MalFet
/bɪər nɜrd/
HBT_LIFETIMESUPPORTER.png
 
MalFet's Avatar
Recipes 
 
May 2010
NYC / Kathmandu
Posts: 8,632
Liked 1473 Times on 975 Posts


Quote:
Originally Posted by crane View Post
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.
__________________
"Be excellent to each other." -Benjamin Franklin

 
Reply With Quote
Old 08-16-2012, 03:44 PM   #4
FastTalker
Member
HBT_SUPPORTER.png
 
FastTalker's Avatar
Recipes 
 
Sep 2011
Nashville, TN
Posts: 164
Liked 9 Times on 8 Posts


Quote:
Originally Posted by crane View Post
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.

 
Reply With Quote
Old 08-18-2012, 01:50 AM   #5
MalFet
/bɪər nɜrd/
HBT_LIFETIMESUPPORTER.png
 
MalFet's Avatar
Recipes 
 
May 2010
NYC / Kathmandu
Posts: 8,632
Liked 1473 Times on 975 Posts


Quote:
Originally Posted by FastTalker View Post
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.
__________________
"Be excellent to each other." -Benjamin Franklin

 
Reply With Quote
Old 08-21-2012, 07:27 PM   #6
porcupine73
Recipes 
 
Aug 2012
Fort Meade
Posts: 813
Liked 47 Times on 43 Posts


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.

 
Reply With Quote
Old 08-22-2012, 02:03 AM   #7
FastTalker
Member
HBT_SUPPORTER.png
 
FastTalker's Avatar
Recipes 
 
Sep 2011
Nashville, TN
Posts: 164
Liked 9 Times on 8 Posts


Quote:
Originally Posted by porcupine73 View Post
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.

 
Reply With Quote
Old 08-22-2012, 02:59 AM   #8

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.
__________________
Mead Lane Brewing
The liver is evil and must be punished

 
Reply With Quote
Old 09-20-2012, 08:27 PM   #9
alien
Recipes 
 
Apr 2012
Philadelphia, PA
Posts: 1,235
Liked 68 Times on 59 Posts


Quote:
Originally Posted by poobah58 View Post
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

 
Reply With Quote
Old 09-20-2012, 08:44 PM   #10
MalFet
/bɪər nɜrd/
HBT_LIFETIMESUPPORTER.png
 
MalFet's Avatar
Recipes 
 
May 2010
NYC / Kathmandu
Posts: 8,632
Liked 1473 Times on 975 Posts


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 View Post
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 View Post
+1
Well, what do you guys mean by "slow changing"? I gain or lose 5 psi in less than 15 seconds.
__________________
"Be excellent to each other." -Benjamin Franklin

 
Reply With Quote


Reply
Thread Tools



Forum Jump