![](/media/cache/profiles/2012_sf_avc_095.jpg.50x50_q85.jpg)
Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
Diff: Sensors/IncrementalEncoder/IncrementalEncoder.h
- Revision:
- 0:826c6171fc1b
diff -r 000000000000 -r 826c6171fc1b Sensors/IncrementalEncoder/IncrementalEncoder.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sensors/IncrementalEncoder/IncrementalEncoder.h Wed Jun 20 14:57:48 2012 +0000 @@ -0,0 +1,67 @@ +#ifndef __INCREMENTALENCODER_H +#define __INCREMENTALENCODER_H + +#include "mbed.h" + +/** An interface for a simple, 1-track, incremental encoder. If using a simple reflectance sensor, then a voltage comparator + * circuit will be required to generate the pulsetrain. See: http://www.bot-thoughts.com/2011/03/avc-bot-wheel-encoders.html + * + */ +class IncrementalEncoder +{ + public: + /** Create an incremental encoder interface. Increments counter at every rise and fall signal + * + * @param pin -- the pin to which a digital pulsetrain is sent + */ + IncrementalEncoder(PinName pin); + + /** Get ticks since last call + * + * @returns the number of ticks since the last call to this method + */ + unsigned int read(); + + /** Get total tick count since last reset + * + * @returns total ticks since the last reset or instantiation + */ + unsigned int readTotal(); + + /** Get total rise tick count + * + * @returns total rise ticks + */ + unsigned int readRise(); + + /** Get total fall tick count + * + * @returns total fall ticks + */ + unsigned int readFall(); + + /** Read time interval between ticks + * + * @returns filtered time between encoder pulses + */ + unsigned int readTime(); + + /** Reset the tick counter + * + */ + void reset(); + + private: + Timer _t; + unsigned int _lastTime; + unsigned int _time; + unsigned int _lastTicks; + unsigned int _ticks, _rise, _fall; + bool _new; + InterruptIn _interrupt; + void _increment(); + void _incRise(); + void _incFall(); +}; + +#endif \ No newline at end of file