mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Fix C++ PIDController SetToleranceBuffer and OnTarget locking.
Also implement OnTarget fix in simulation PIDController. Change-Id: Ic4b452759f80aa769a721f22cb6e732c2a9a213a
This commit is contained in:
@@ -500,6 +500,7 @@ void PIDController::SetAbsoluteTolerance(float absTolerance)
|
||||
* @param bufLength Number of previous cycles to average. Defaults to 1.
|
||||
*/
|
||||
void PIDController::SetToleranceBuffer(unsigned bufLength) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
m_bufLength = bufLength;
|
||||
|
||||
// Cut the buffer down to size if needed.
|
||||
@@ -518,9 +519,9 @@ void PIDController::SetToleranceBuffer(unsigned bufLength) {
|
||||
*/
|
||||
bool PIDController::OnTarget() const
|
||||
{
|
||||
double error = GetError();
|
||||
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
if (m_buf.size() == 0) return false;
|
||||
double error = GetError();
|
||||
switch (m_toleranceType) {
|
||||
case kPercentTolerance:
|
||||
return fabs(error) < m_tolerance / 100 * (m_maximumInput - m_minimumInput);
|
||||
|
||||
Reference in New Issue
Block a user