View Single Post
  #3   Spotlight this post!  
Unread 01-20-2010, 08:33 AM
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: Velocity-based PID with the WPILib PIDController Class

Warnings
Disclaimer: All I know about PID loops I learned through the Wikipedia page and tweaking the several that we had on our robot last year.

Safety note: Always test PIDs on a stand first. Sometimes you can have very unpredictable results, and you don't want a 60-150lb robot flying off at full speed into equipment or people.

Content
You'll probably need an I term to help you accumulate more power.

Think of the definition of a PID loop:

Output = P + I + D
P = error * kP
I = sum(past errors) + kI*error
D = not too important in this case.

In this case, your error is 5000 (10000 - 5000) and your kP is 0.00014. Since your kI and kD is zero, your output is 5000 * 0.00014 = 0.7. If a motor power of 0.7 ends up equaling the amount of drag in your drive system, then your robot will not accelerate any further. If you set a (very small) kI, then your I term will grow as long as you're not hitting your setpoint, which means your motors will speed up until the setpoint is hit.

Of course, if your setpoint isn't hittable (physical max speed is 8000 ticks/sec, maybe) then you'll probably have problems slowing them back down, but that's a tweakable thing.

An I term will also help you with low-speed stuff. Right now, if you set a setpoint of 1000 ticks/sec, that'll translate to a motor power of 0.14. If a motor power of 0.14 translates to 2000 ticks/sec on the robot, then you'll have a new output of -0.14, which might translate to -2000 ticks/sec, which will then give a motor power of 0.42 on your next cycle, and you see in this simple example you've got oscillation. An I term will allow you to reduce your P term and will at least smoothen the oscillations.

Another tweak might be to increase the frequency of the PID loop, which I believe you can do in its constructor. Faster updates might reduce oscillations, depending on the update rate of the encoders and cRio.

Last edited by Bongle : 01-20-2010 at 08:43 AM.
Reply With Quote