View Single Post
  #5   Spotlight this post!  
Unread 12-04-2012, 10:53
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Encoder for Rpm help!

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.

Last edited by rbmj : 12-04-2012 at 10:55.
Reply With Quote