![]() |
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()If either of the "m_pPID->GetError();" or "bOnTarget = m_pPID->OnTarget();" lines are uncommented, the code no longer functions. |
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
See if the following bug report seems like it could cause your issue: http://firstforge.wpi.edu/sf/go/artf1595
|
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
I ran into this tonight as well. Last year the implementation of PIDController:GetError() just set error = m_error inside the critical section. Anyone know the reason for now trying to set error = GetSetpoint() - m_pidInput->PIDGet()? Seemed like just returning m_error was good enough..
|
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
Quote:
Code:
myPID->SetSetpoint(); |
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
Replace your GetError function with this. It should work.
/** * Retruns the current difference of the input from the setpoint * @return the current error */ float PIDController::GetError() { float error; PIDSource *pidInput; CRITICAL_REGION(m_semaphore) { pidInput = m_pidInput; error = GetSetpoint() - pidInput->PIDGet(); }END_REGION; return error; } |
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
Scratch that last post. I thought this fixed the issues I was having during the Beta season, but it's blowing up for me now. If anybody has a work-around, I'd love to try it out.
|
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
And ^ that's what I get for not checking who is logged in to CD on the programming computer!
Sorry John. I'm going to bed now. |
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
I don't have the code in front of me right now but i think i ended up using this:
Code:
float PIDController::GetError() Even with this updated implementation of GetError() I also learned last night not to call GetError() within PIDWrite(). |
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
Sorry about the bug. There will be a fix posted shortly as soon as we finish fixing another issue with SmartDashboard.
Basically the problem is that the critical region uses a binary semaphore which blocks on multiple takes from the same thread. The code has a bunch of CRITICAL_REGIONS nested so it's hanging. The fix was to replace the semaphore with a Mutual Exclusion semaphore which will block on multiple tasks trying to access the code, but not when the same task tries. Brad |
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
Quote:
|
Re: Call to PIDController::GetError() and ::OnTarget() locks program.
Quote:
|
| All times are GMT -5. The time now is 12:55. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi