mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Miscellaneous cleanups for wpilibc PID controller (#175)
* Reorder wpilibc PIDController's SetAbsoluteTolerance() and SetPercentTolerance() implementations to be consistent with header and wpilibj * Added std:: prefix to fabs() calls in wpilibc PIDController
This commit is contained in:
committed by
Peter Johnson
parent
dffaa0abb9
commit
c93b5bedf9
@@ -6,8 +6,10 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "PIDController.h"
|
||||
#include <math.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/HAL.h"
|
||||
#include "Notifier.h"
|
||||
#include "PIDOutput.h"
|
||||
@@ -110,7 +112,7 @@ void PIDController::Calculate() {
|
||||
|
||||
m_error = m_setpoint - input;
|
||||
if (m_continuous) {
|
||||
if (fabs(m_error) > (m_maximumInput - m_minimumInput) / 2) {
|
||||
if (std::fabs(m_error) > (m_maximumInput - m_minimumInput) / 2) {
|
||||
if (m_error > 0) {
|
||||
m_error = m_error - m_maximumInput + m_minimumInput;
|
||||
} else {
|
||||
@@ -454,18 +456,6 @@ void PIDController::SetTolerance(float percent) {
|
||||
m_tolerance = percent;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the percentage error which is considered tolerable for use with
|
||||
* OnTarget.
|
||||
*
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetPercentTolerance(float percent) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the absolute error which is considered tolerable for use with
|
||||
* OnTarget.
|
||||
@@ -478,6 +468,18 @@ void PIDController::SetAbsoluteTolerance(float absTolerance) {
|
||||
m_tolerance = absTolerance;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the percentage error which is considered tolerable for use with
|
||||
* OnTarget.
|
||||
*
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetPercentTolerance(float percent) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the number of previous error samples to average for tolerancing. When
|
||||
* determining whether a mechanism is on target, the user may want to use a
|
||||
@@ -516,11 +518,11 @@ bool PIDController::OnTarget() const {
|
||||
double error = GetAvgError();
|
||||
switch (m_toleranceType) {
|
||||
case kPercentTolerance:
|
||||
return fabs(error) <
|
||||
return std::fabs(error) <
|
||||
m_tolerance / 100 * (m_maximumInput - m_minimumInput);
|
||||
break;
|
||||
case kAbsoluteTolerance:
|
||||
return fabs(error) < m_tolerance;
|
||||
return std::fabs(error) < m_tolerance;
|
||||
break;
|
||||
case kNoTolerance:
|
||||
// TODO: this case needs an error
|
||||
|
||||
Reference in New Issue
Block a user