[artf3709] Fixed PIDController loop timing.

For C++: The PIDController loop had been changed to run an infinite loop
with a Wait(period) rather than using the Notifier class to schedule
exact runs of the CallCalculate command. Essentially a revert to bb50f4b134,
accounting for more recent changes.

For Java: A similar problem had developed; essentially, a TimerTask used
to be used and at some point was changed to a Runnable. The Runnable had
an infinite loop with a Wait; TimerTask actually schedules things reasonably
(although it is not strictly real-time). Also, there were some
Thread-safety issues which I fixed.

Although Java and C++ had similar issues, they seem to have developed
these issues independently.

Changes have been tested on the GearsBot in both C++ and Java (and it
    works).

Change-Id: I478cb8bfd77cd2d031f8e343d0b8193b602dcc2a
This commit is contained in:
James Kuszmaul
2014-10-24 15:30:54 -04:00
parent 80194e9809
commit 687e2c6711
3 changed files with 289 additions and 284 deletions

View File

@@ -8,7 +8,7 @@
#include "Base.h"
#include "Controller.h"
#include "LiveWindow/LiveWindow.h"
#include <pthread.h>
#include "HAL/Semaphore.hpp"
class PIDOutput;
class PIDSource;
@@ -83,18 +83,13 @@ private:
float m_error;
float m_result;
float m_period;
MUTEX_ID m_semaphore;
PIDSource *m_pidInput;
PIDOutput *m_pidOutput;
#ifndef FRC_SIMULATOR
pthread_t m_controlLoop;
#else
Notifier* m_controlLoop;
#endif
pthread_mutex_t m_mutex;
void Initialize(float p, float i, float d, float f, PIDSource *source, PIDOutput *output,
float period = 0.05);