Go to Post [You know you've overdoes on FIRST when...] You're willing to take an 8 AM for the team. - ttldomination [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 25-03-2012, 16:23
Clint Clint is offline
Registered User
FRC #0308 (Monsters)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Michigan
Posts: 2
Clint is an unknown quantity at this point
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
Reply With Quote
 


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


All times are GMT -5. The time now is 14:47.

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