Re: WPILib PID controller object
Quote:
Originally Posted by SlimBoJones
(Post 821927)
We've done pretty much exactly the same thing as you did here. I think we're running into a small concurrency problem though, and would like to hear from you as well.
As once in a blue moon your camera "spaz" while it is tracking?
Very rarely, but often enough to make it a pain, our camera tracker will move out of position quickly then recover for no apparent reason.
I think it's because of a classic concurrency issue where source is being read and written at the same time.
The PID controller runs in a separate task, and so potentially both SetSource and PIDGet could be called at the same time.
Would any more experienced programmers out there recommend locks? And if so, how would you implement them in the quoted code?
|
If your code in SetSource consists of just an assignment statement, it's probably not a concurrency issue. Although it's poor style to not protect it with a semaphore, a simple assignment of an int or float is usually what's called an 'atomic' operation, which means that it would not be interrupted in the middle by a task switch. (It happens in one machine language operation) I would look elsewhere for the cause.
If you have more than one line in SetSource (or if you want to get used to how to do multithreaded programming) you need to protect the function with a semaphore. The 'C programming guide for FRC.pdf' page 78 discusses how to do this. It's not hard, just a matter of adding a line at the beginning and end of your function.
Steve C
|