View Single Post
  #23   Spotlight this post!  
Unread 23-02-2012, 15:06
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Help me understand PIDController::OnTarget()

Quote:
Originally Posted by jwakeman View Post
Code:
bool PIDController::OnTarget()
{
	bool temp;
	CRITICAL_REGION(m_semaphore)
	{
		temp = fabs(m_error) < (m_tolerance / 100 * 
			(m_maximumInput - m_minimumInput));
	}
	END_REGION;
	return temp;
}
On a side note:

It looks like m_tolerance, m_maximumInput, and m_minimumInput are all constants.

Take them, and the calculation, out of the critical region

Code:
bool PIDController::OnTarget()
{
	double temp;
	CRITICAL_REGION(m_semaphore)
	{
         temp=m_error;
	}
	END_REGION;
	return (fabs(temp) < (m_tolerance / 100 * (m_maximumInput - m_minimumInput)));
}

Reply With Quote