|
|
@@ -581,6 +581,22 @@ public double GetAvgError() |
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
+ /// Returns whether or not any values have been collected.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// If no values have been collected, <see cref="GetAvgError"/> is 0, which
|
|
|
+ /// is invalid.
|
|
|
+ /// </remarks>
|
|
|
+ /// <returns>True if <see cref="GetAvgError"/> is currently valid.</returns>
|
|
|
+ public bool IsAvgErrorValid()
|
|
|
+ {
|
|
|
+ lock (m_lockObject)
|
|
|
+ {
|
|
|
+ return m_buf.Count != 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
/// Sets the percentage error which is considered tolerable for use
|
|
|
/// with <see cref="OnTarget"/>.
|
|
|
/// </summary>
|
|
|
@@ -629,10 +645,13 @@ public void SetAbsoluteTolerance(double absTolerance) |
|
|
/// <param name="bufLength">The number of previous cycles to average.</param>
|
|
|
public void SetToleranceBuffer(int bufLength)
|
|
|
{
|
|
|
- m_bufLength = bufLength;
|
|
|
- while (m_buf.Count > bufLength)
|
|
|
+ lock (m_lockObject)
|
|
|
{
|
|
|
- m_bufTotal -= m_buf.Dequeue();
|
|
|
+ m_bufLength = bufLength;
|
|
|
+ while (m_buf.Count > bufLength)
|
|
|
+ {
|
|
|
+ m_bufTotal -= m_buf.Dequeue();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -652,9 +671,9 @@ public bool OnTarget() |
|
|
switch (m_toleranceType)
|
|
|
{
|
|
|
case ToleranceType.PercentTolerance:
|
|
|
- return Math.Abs(GetAvgError()) < (m_tolerance / 100 * (m_maximumInput - m_minimumInput));
|
|
|
+ return IsAvgErrorValid() && Math.Abs(GetAvgError()) < (m_tolerance / 100 * (m_maximumInput - m_minimumInput));
|
|
|
case ToleranceType.AbsoluteTolerance:
|
|
|
- return Math.Abs(GetAvgError()) < m_tolerance;
|
|
|
+ return IsAvgErrorValid() && Math.Abs(GetAvgError()) < m_tolerance;
|
|
|
default:
|
|
|
throw new InvalidOperationException("Tolerance type must be set before calling OnTarget");
|
|
|
}
|
|
|
|