Thread: Speed PID loop
View Single Post
  #8   Spotlight this post!  
Unread 07-02-2012, 19:36
TravSatEE's Avatar
TravSatEE TravSatEE is offline
Spacecraft Engineer and more
FRC #2035 (Robo Rockin' Bots)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2002
Location: Monterey, CA
Posts: 26
TravSatEE is infamous around these partsTravSatEE is infamous around these parts
Re: Speed PID loop

The previous post [2] reference has Equation (1):

output += Kp*e_vel + Ki*e_vel_sum + Kd*e_vel_delta;

PIDController.java line 159 has:

m_result = (m_P * m_error + m_I * m_totalError + m_D * (m_error - m_prevError));

You want this line 159 to look more like the Equation (1). I'm not talking about changing the variable names, just that defining m_result becomes a += assignment instead of merely the = assignment.

This is the difference to the PID velocity controller and PID position controller. Note that your constants Kp, Ki, and Kd will be different compared to a position PID controller. To experiment, Set Ki, Kd to zero and find a good Kp that gets you "close enough" to your desired speeds. Then add in a Ki to see the result converge. You may want to find a way to output the encoder speed to verify your results.

Remember to make this change in a copy of the PIDController.java and not the original file itself. You can change some of the javadoc comments to reflect your work and post it to the WPILIB developers to get it included in the official WPILIB.

I would suggest you look through the lines of code 141-156 to see how it implements a PID controller. Looking at an equation is one thing, implementing in code is another.

Everyone please read the references again and follow up with questions. Copy quotes that confuse you to ask for clarification. I am seeing a lot of teams struggling with PID controllers, so the more you ask the more it will also help others.

Thanks gpetilli for pointing out the need for an encoder for the PID controller.
Reply With Quote