Add PIDController Wrapping (#601)

This commit is contained in:
Caleb Smith
2017-11-26 00:15:33 -05:00
committed by Peter Johnson
parent c9d440f338
commit a338ee8be0
2 changed files with 16 additions and 10 deletions

View File

@@ -640,11 +640,14 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
* @return Error for continuous inputs.
*/
double PIDController::GetContinuousError(double error) const {
if (m_continuous && std::fabs(error) > m_inputRange / 2) {
if (error > 0) {
return error - m_inputRange;
} else {
return error + m_inputRange;
if (m_continuous) {
error = std::fmod(error, m_inputRange);
if (std::fabs(error) > m_inputRange / 2) {
if (error > 0) {
return error - m_inputRange;
} else {
return error + m_inputRange;
}
}
}