Go to Post And the only thing that can really measure that is when you look a kid in the eye, say "We've got a problem..." and you see them smiling, "Bring it on." - dtengineering [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-03-2010, 12:30
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Update Rate of PID Loops

Is putting PID loops in the area of the code that runs faster really that beneficial? If I recall, the 'main' portion of the loop updates at 20 hz, or every 50 milliseconds.

I took a single signals class in college and while we touched on oversampling, antialiasing, etc we didn't really dig in. In this case, I look at our 150 pound robot and think to myself that 1/20 of a second response time should be more than good enough.

Is there something I'm missing? I'd love a whitepaper on this, since it seems to be one of the 'black arts' that we don't really talk about here, even though almost every team utilizes PID loops at one point or another.
  #2   Spotlight this post!  
Unread 01-03-2010, 13:03
Sovietmagician's Avatar
Sovietmagician Sovietmagician is offline
Registered User
AKA: Ariel Eisenstadt
FRC #0694 (Stuypulse)
Team Role: Programmer
 
Join Date: Apr 2008
Rookie Year: 2007
Location: New York City
Posts: 12
Sovietmagician is an unknown quantity at this point
Re: Update Rate of PID Loops

What language are you using. If you are Using Java then WPILibJ's built in PIDController class has a constructor that you can set the update interval in, I assume with C++ there is a similar feature.
__________________
Shhhhhhhh... the code is compiling
  #3   Spotlight this post!  
Unread 01-03-2010, 13:26
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Update Rate of PID Loops

You are correct that a faster update rate (especially with our sloppy mechanical systems) won't make too much of a difference. (At least in the present time, or 'P' portion of the calcs)

The real issue is the PID loop needs to be run at a constant interval, as you are taking the integral and differential of a signal. You'd like to shrink delta T to a very small value for the D, and really want that value to be constant. You could calculate your real differential by measuring dT, but why bother when you have the horsepower to do it in constant time in another thread?

All WPILib is doing for PID is making it easy for an end user to fork off a thread and repeatedly call a function at a constant rate. (They also throw in the math for free)
  #4   Spotlight this post!  
Unread 01-03-2010, 13:55
Bongle's Avatar
Bongle Bongle is offline
Registered User
FRC #2702 (REBotics)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Waterloo
Posts: 1,069
Bongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond reputeBongle has a reputation beyond repute
Send a message via MSN to Bongle
Re: Update Rate of PID Loops

I'm not certain, but I think the actual sensors and motor outputs on the robot can be queried and updated much faster than 50hz. The 50hz timing is how often packets get sent to and from the classmate. It does you no good to query your joysticks or buttonboxes faster than 50hz, but the analog inputs can change much faster.
  #5   Spotlight this post!  
Unread 01-03-2010, 14:13
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Update Rate of PID Loops

Tom, thanks for the explanation, and that does make sense. However, the integral and the derivative (at least in my experience) are not needed on our robots 90% of the time. Since my team has never really needed to use them, then it sounds like we've never really hurt ourselves keeping the P portion of the PID in the normal loop.

However, if we ever work into the I and D section (and we might a bit this year), I'll start putting them in the "go fast" portion of the code.

Thanks!

Edit: On a side note, one of the really nice parts of the IFI system was that you had to program your own PID and understand how they worked. I made my team go through this year and use whitepapers to write their own PID code. It's always good to know what's under the hood of your robot!

Second note: This would be an Excellent EXCELLENT discussion to have at nationals and put a whitepaper here on chiefdelphi. Update rates of sensors, loops, and processing rate of code all tied together is something that simply doesn't get addressed very often.

Last edited by Tom Line : 01-03-2010 at 14:16.
  #6   Spotlight this post!  
Unread 01-03-2010, 14:14
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Update Rate of PID Loops

Quote:
Originally Posted by Tom Line View Post
However, if we ever work into the I and D section (and we might a bit this year), I'll start putting them in the "go fast" portion of the code.
Doesn't need to "go fast", just needs to "go the same".
  #7   Spotlight this post!  
Unread 01-03-2010, 15:03
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: Update Rate of PID Loops

Hey Tom, here are my thoughts on this:

1) The rate that you run the PID loops depend on what you're trying to control, how fast it is moving, and if you have any other logic that interacts with the PID loop. For example, if your robot is traveling at 10 ft/s you can travel 6 inches in one 50 ms time step. If you need to control to more accuracy than 6 inches (or you have some logic that looks for you to be in a 6 inch window) and you need to do it at a high robot speed, then you might want to move to the faster loop. If you are controlling motion that is slower or you don't need that kind of accuracy while traveling that fast, then the faster sample rate won't help you too much.

2) You can easily take the actual sample period into account in the PID code. For the integral, multiply the error by the time step before adding. For the derivative, divide the error by the time step before the subtraction. Just be sure to take this into account for your control gains - they will change by a factor of the average time step.
__________________
-
An ounce of perception is worth a pound of obscure.
  #8   Spotlight this post!  
Unread 01-03-2010, 16:38
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Update Rate of PID Loops

There are many competing factors at play when selecting a sampling rate/update rate for a PID controller. On the one hand, higher sampling rates minimize delays in the control loop and bring your system's discrete-time controller "closest" to its ideal continuous-time form. On the other hand, higher sampling rates can also lead to increased noise susceptibility, especially when you are using the "derivative" term, and increasing the sample rate eventually reaches the point of diminishing returns anyhow.

Implementing control systems that trade off between these factors is somewhat of a black art - my college adviser passed down the wisdom that, in general, the sampling period that you should shoot for will be one or two orders of magnitude (10-100x) smaller than the system's settling time (time from saturation to reaching its final destination). The popular article "PID without a Ph.D" agrees.

For example, consider a robot whose drive is commanded by a position PID loop. The setpoint is 30 feet away. For arguments' sake, lets say that Kp = .1 (Percent of full throttle per foot of position error**). For most of its trip from x=0 to x=30, the PID controller will be telling the robot to floor it (since Kp*error >= 1.0 until error is less than 10 feet). The amount of time it takes between the last output of 1.0 and the time that the error enters a final X% bound around the setpoint (for example, the "1% settling time" in this case would be the time elapsed between the time at which error=10ft and error=1% of 30 ft, or 3.6 inches) is the settling time. Lets say it takes our robot 2 seconds to slow down, possibly oscillate one or more times, and come to a stop within 3.6 inches of the target - using the 10-100x rule of thumb, our sample period should be between 200 milliseconds and 20 milliseconds, or 5 to 50 Hz.

The idea is that at a, say, 3 Hz sampling rate we would have a really bad settling time (if the system is even stable at all). As we increase the sampling rate from this point, we expect the settling time/stability to improve until, at some point before 50Hz, we converge at around 2 seconds 1% settling time. Above that sampling rate, we are not likely to improve significantly (and in fact we might hurt our robustness to sensor noise if we have a D term).

The above is just a rule of thumb; given a good mathematical model of any process there are some analytical ways to figure out what the ideal sampling rate should be, but unless you are building a space shuttle, the math is sufficiently complicated that I would say just play with your system and see what works.

I will point out two other related factors to sampling rate frequency:

1. Sampling rate jitter - this can be a huge problem, especially once you start talking about 5% or more. Jitter is the variation between successive sample times. It can be insidious when dealing with integral and derivative terms, for fairly obvious reasons (differentiation in a discrete PID loop is usually approximately by finite differences, e.g. x(t) - x(t-sample_period) ). You can compensate for it somewhat if you measure the sampling period between updates, but if you can do this, why not just use a timer in the first place?

2. Remember that in our systems, the cRIO does not command the motors directly. Rather, it commands speed controllers, which have their own set of delays. Victors update at something like 100Hz (or is it 120?) - this means that a potential delay of on the order of 10ms gets added to every single output if you aren't lucky. Jaguars have about half of this delay. So doing updates faster than 100Hz/200Hz is going to be fruitless.

** Note: I find that if I force myself to put units onto my PID controller gains, it makes life much, much more intuitive when it comes time to put in "initial guesses" for my parameter gains.

Quote:
Originally Posted by Tom Line View Post
Second note: This would be an Excellent EXCELLENT discussion to have at nationals and put a whitepaper here on chiefdelphi. Update rates of sensors, loops, and processing rate of code all tied together is something that simply doesn't get addressed very often.
Tom,

This sounds like a great idea (my master's is in control systems ) In classes or in text books, it is easy to find the PID equations and to understand the concepts. However, implementing control systems (and signal processing, and image processing) in effective code is a skill that is sadly underrepresented in the majority of literature on controls.

Last edited by Jared Russell : 01-03-2010 at 16:40.
  #9   Spotlight this post!  
Unread 02-03-2010, 00:42
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Update Rate of PID Loops

Ha! I just emailed your reply to myself and I'm going to put it on the team server. That made a ton of sense and didn't overcomplicate things, and gives a great rule of thumb to figure this stuff out.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tunnels in loops krupinski NI LabVIEW 1 09-02-2009 12:08
PID vs Normal loops 3DWolf Programming 20 14-12-2007 13:41
Why 26ms update rate? bear24rw Control System 2 24-03-2007 20:39
PID control loops - closed loop feedback KenWittlief Technical Discussion 56 26-04-2004 21:27
PID Control Loops ttedrow Programming 7 05-12-2002 12:03


All times are GMT -5. The time now is 03:22.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi