View Single Post
  #1   Spotlight this post!  
Unread 24-01-2013, 20:15
KGU KGU is offline
Registered User
FRC #3284
 
Join Date: Jan 2013
Location: Missouri
Posts: 1
KGU is an unknown quantity at this point
Call to PIDController::GetError() and ::OnTarget() locks program.

We have been working with the PID controller and have a simple set up with a motor and potentiometer. The motor tries to control to set point as it should, but only if the we are not using the GetError or OnTarget methods. If either of these methods are called, the program locks up and does not continue on to the rest of the code. Here is a snippet of our code (we initialize everything in a separate header not shown):

Code:
CRobotMain::CRobotMain() : SimpleRobot()
{
	// Create our object pointers.
	m_pPot		= new AnalogChannel(1, 2);
	m_pMotor	= new Talon(1, 8);
	m_pPID		= new PIDController(0.1, 0.001, 0.0, m_pPot, m_pMotor);
}

void CRobotMain::OperatorControl()
{
	float	fError;
	bool	bOnTarget;
	
	m_pPID->SetOutputRange(-0.25, 0.25);
	m_pPID->SetInputRange(0, 1023);
	m_pPID->SetAbsoluteTolerance(50);
	m_pPID->SetContinuous(true);
	m_pPID->Enable();
	
	// Continuously run loop while in teleop mode.
	while (IsOperatorControl())
	{
		m_pPID->SetSetpoint(250);

///		fError = m_pPID->GetError();
///		bOnTarget = m_pPID->OnTarget();
		
		Wait(0.050);
	}
}

If either of the "m_pPID->GetError();" or "bOnTarget = m_pPID->OnTarget();" lines are uncommented, the code no longer functions.
Reply With Quote