We do something similar to jsmeldru...
Code:
#include <PIDSource.h>
#include <Counter.h>
class freq_pid : public PIDSource {
private:
Counter& count;
public:
freq_pid(Counter& c) : count(c) {}
double frequency() { return 1/count.GetPeriod(); }
double PIDGet() { return frequency(); }
};
The nice thing for this is that it lets you use PID with a jag and such.
We take everything by reference since we centralize all of our sensor port data in one file.
Note that that frequency is in hz. If you want rpm you can just change the 1 to a 60.