View Single Post
  #20   Spotlight this post!  
Unread 24-02-2012, 11:32
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by vamfun View Post
What is maximumInput and minimumInput?
It is simply the minimum and maximum setpoint that the controller will accept. In the case of my shooter speed controller they are set to 0 and 100 respectively (units are feet per second in this case). For my turret position controller I am using -45 to 45 (degrees) and my turret speed controller accepts -250 to 250 (degrees/sec)...i think you get the idea.

Quote:
Originally Posted by vamfun View Post
Now that you brought this code up, would someone mind explaining why it is there?
The code I posted actually falls within one more if-statement, if(m_continuous). I've also always wondered what this code is meant to represent. What is meant by continuous in this case? Also running some values though the code doesn't help me understand at all.

Using my example of a shooter speed controller with minimum input of 0 and maximum input of 100 fps. Say I step my setpoint from 0 to 100. My error would be equal to 100 on the first iteration. So 100 is greater than (100 - 0) / 2 and 100 is greater than zero so m_error ends up being set equal to 100 - 100 + 0. So if I step my speed controller from zero to maximum the output will be computed as zero?!

Another scenario, I step the setpoint from 0 to 60. The error of 60 is greater than 50 and greater than zero so the m_error becomes 60 - 100 + 0 = -40. Now my positive error became negative error..I'm confused.

Code:
if (m_continuous)
{
    if (fabs(m_error) > (m_maximumInput - m_minimumInput) / 2)
    {
        if (m_error > 0)
        {
            m_error = m_error - m_maximumInput + m_minimumInput;
        }
        else
        {
            m_error = m_error + m_maximumInput - m_minimumInput;
        }
    }
}
Reply With Quote