mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Merge "Fix onTarget() so that it returns false until there are any values retrieved"
This commit is contained in:
@@ -486,8 +486,10 @@ void PIDController::SetToleranceBuffer(unsigned bufLength) {
|
||||
* setpoint.
|
||||
* Ideally it should be based on being within the tolerance for some period of
|
||||
* time.
|
||||
* This will return false until at least one input value has been computed.
|
||||
*/
|
||||
bool PIDController::OnTarget() const {
|
||||
if (m_buf.size() == 0) return false;
|
||||
double error = GetAvgError();
|
||||
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class PIDController implements PIDInterface, LiveWindowSendable, Controll
|
||||
|
||||
@Override
|
||||
public boolean onTarget() {
|
||||
return (Math.abs(getAvgError()) < percentage / 100 * (m_maximumInput - m_minimumInput));
|
||||
return isAvgErrorValid() && (Math.abs(getAvgError()) < percentage / 100 * (m_maximumInput - m_minimumInput));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class PIDController implements PIDInterface, LiveWindowSendable, Controll
|
||||
|
||||
@Override
|
||||
public boolean onTarget() {
|
||||
return Math.abs(getAvgError()) < value;
|
||||
return isAvgErrorValid() && Math.abs(getAvgError()) < value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,6 +575,16 @@ public class PIDController implements PIDInterface, LiveWindowSendable, Controll
|
||||
return avgError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not any values have been collected. If no values
|
||||
* have been collected, getAvgError is 0, which is invalid.
|
||||
*
|
||||
* @return True if {@link #getAvgError()} is currently valid.
|
||||
*/
|
||||
private synchronized boolean isAvgErrorValid() {
|
||||
return m_buf.size() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the percentage error which is considered tolerable for use with
|
||||
* OnTarget. (Input of 15.0 = 15 percent)
|
||||
|
||||
Reference in New Issue
Block a user