Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Bug in WPILib PIDController? (http://www.chiefdelphi.com/forums/showthread.php?t=105032)

Clint 25-03-2012 16:23

Bug in WPILib PIDController?
 
The following code excerpt is found in PIDController.cpp of revision 3111 of WPILib, on lines 128 through 141.
Code:

double potentialIGain = (m_totalError + m_error) * m_I;
if (potentialIGain < m_maximumOutput)
{
        if (potentialIGain > m_minimumOutput)
                m_totalError += m_error;
        else
                m_totalError = m_minimumOutput / m_I;
}
else
{
        m_totalError = m_maximumOutput / m_I;
}

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

In the lines of code above, a subtle problem exists, under a certain few specific conditions:
  • Output is restricted with a minimum or maximum of 0
  • m_I is 0

Under these instances, the first if statement fails (or, it continues through to the second inner statement which also fails). In both cases, the total error is calculated by dividing by m_I. When m_I is zero--a perfectly logical use case--m_totalError becomes NaN.
As a result, m_result becomes NaN as well. Subsequently, when PIDController::Calculate writes this value to the output, errors rapidly accumulate in the console.


Clint

virtuald 26-03-2012 11:41

Re: Bug in WPILib PIDController?
 
You should file a bug at the WPILib tracker.

http://firstforge.wpi.edu/sf/tracker....wpilib_c_bugs

Clint 26-03-2012 19:32

Re: Bug in WPILib PIDController?
 
Thanks. If anyone else is interested in following this issue, the artifact can be found here.


All times are GMT -5. The time now is 13:06.

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