Happy HolidaySs Giveaway - Last Sponsor Giveaway of the Year!

Come Enter the BrewDeals/FastFerment Giveaway!


Home Brew Forums > Home Brewing Beer > Automated Brewing Forum > Manually tuning PID
Reply
 
LinkBack Thread Tools
Old 08-15-2012, 01:17 AM   #1
MalFet
/bɪər nərd/
HBT_LIFETIMESUPPORTER.png
Feedback Score: 1 reviews
 
MalFet's Avatar
Recipes 
 
Join Date: May 2010
Location: NYC / Kathmandu
Posts: 8,276
Liked 1267 Times on 844 Posts
Likes Given: 583

Default 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!

__________________

"Be excellent to each other." -Benjamin Franklin

MalFet is offline
 
Reply With Quote Quick reply to this message
Old 08-15-2012, 06:38 AM   #2
crane
Feedback Score: 0 reviews
Recipes 
 
Join Date: Sep 2011
Location: San Diego, CA
Posts: 309
Liked 33 Times on 26 Posts
Likes Given: 1

Default

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.

__________________
crane is offline
 
Reply With Quote Quick reply to this message
Old 08-16-2012, 12:49 AM   #3
MalFet
/bɪər nərd/
HBT_LIFETIMESUPPORTER.png
Feedback Score: 1 reviews
 
MalFet's Avatar
Recipes 
 
Join Date: May 2010
Location: NYC / Kathmandu
Posts: 8,276
Liked 1267 Times on 844 Posts
Likes Given: 583

Default

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

MalFet is offline
 
Reply With Quote Quick reply to this message
Old 08-16-2012, 04:44 PM   #4
FastTalker
Member
HBT_SUPPORTER.png
Feedback Score: 0 reviews
 
FastTalker's Avatar
Recipes 
 
Join Date: Sep 2011
Location: Nashville, TN
Posts: 130
Liked 4 Times on 4 Posts
Likes Given: 4

Default

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.
__________________
FastTalker is offline
 
Reply With Quote Quick reply to this message
Old 08-18-2012, 02:50 AM   #5
MalFet
/bɪər nərd/
HBT_LIFETIMESUPPORTER.png
Feedback Score: 1 reviews
 
MalFet's Avatar
Recipes 
 
Join Date: May 2010
Location: NYC / Kathmandu
Posts: 8,276
Liked 1267 Times on 844 Posts
Likes Given: 583

Default

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

MalFet is offline
 
Reply With Quote Quick reply to this message
Old 08-21-2012, 08:27 PM   #6
porcupine73
Feedback Score: 0 reviews
Recipes 
 
Join Date: Aug 2012
Location: Fort Meade
Posts: 811
Liked 47 Times on 43 Posts
Likes Given: 513

Default

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.

__________________
porcupine73 is offline
 
Reply With Quote Quick reply to this message
Old 08-22-2012, 03:03 AM   #7
FastTalker
Member
HBT_SUPPORTER.png
Feedback Score: 0 reviews
 
FastTalker's Avatar
Recipes 
 
Join Date: Sep 2011
Location: Nashville, TN
Posts: 130
Liked 4 Times on 4 Posts
Likes Given: 4

Default

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.
__________________
FastTalker is offline
 
Reply With Quote Quick reply to this message
Old 08-22-2012, 03:59 AM   #8
Poobah58
HBT_LIFETIMESUPPORTER.png
Feedback Score: 1 reviews
 
Poobah58's Avatar
Recipes 
 
Join Date: Jun 2007
Location: New Milford, CT
Posts: 2,246
Liked 57 Times on 50 Posts
Likes Given: 25

Default

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
Poobah58 is offline
 
Reply With Quote Quick reply to this message
Old 09-20-2012, 09:27 PM   #9
alien
Feedback Score: 1 reviews
Recipes 
 
Join Date: Apr 2012
Location: Philadelphia, PA
Posts: 1,235
Liked 65 Times on 58 Posts
Likes Given: 61

Default

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
__________________
alien is offline
 
Reply With Quote Quick reply to this message
Old 09-20-2012, 09:44 PM   #10
MalFet
/bɪər nərd/
HBT_LIFETIMESUPPORTER.png
Feedback Score: 1 reviews
 
MalFet's Avatar
Recipes 
 
Join Date: May 2010
Location: NYC / Kathmandu
Posts: 8,276
Liked 1267 Times on 844 Posts
Likes Given: 583

Default

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

MalFet is offline
 
Reply With Quote Quick reply to this message
Reply



Quick Reply
Message:
Options
Thread Tools




Newest Threads

LATEST SPONSOR DEALS