Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
IncrementalEncoder.h
00001 #ifndef __INCREMENTALENCODER_H 00002 #define __INCREMENTALENCODER_H 00003 00004 #include "mbed.h" 00005 00006 /** An interface for a simple, 1-track, incremental encoder. If using a simple reflectance sensor, then a voltage comparator 00007 * circuit will be required to generate the pulsetrain. See: http://www.bot-thoughts.com/2011/03/avc-bot-wheel-encoders.html 00008 * 00009 */ 00010 class IncrementalEncoder 00011 { 00012 public: 00013 /** Create an incremental encoder interface. Increments counter at every rise and fall signal 00014 * 00015 * @param pin -- the pin to which a digital pulsetrain is sent 00016 */ 00017 IncrementalEncoder(PinName pin); 00018 00019 /** Get ticks since last call 00020 * 00021 * @returns the number of ticks since the last call to this method 00022 */ 00023 unsigned int read(); 00024 00025 /** Get total tick count since last reset 00026 * 00027 * @returns total ticks since the last reset or instantiation 00028 */ 00029 unsigned int readTotal(); 00030 00031 /** Get total rise tick count 00032 * 00033 * @returns total rise ticks 00034 */ 00035 unsigned int readRise(); 00036 00037 /** Get total fall tick count 00038 * 00039 * @returns total fall ticks 00040 */ 00041 unsigned int readFall(); 00042 00043 /** Read time interval between ticks 00044 * 00045 * @returns filtered time between encoder pulses 00046 */ 00047 unsigned int readTime(); 00048 00049 /** Reset the tick counter 00050 * 00051 */ 00052 void reset(); 00053 00054 private: 00055 Timer _t; 00056 unsigned int _lastTime; 00057 unsigned int _time; 00058 unsigned int _lastTicks; 00059 unsigned int _ticks, _rise, _fall; 00060 bool _new; 00061 InterruptIn _interrupt; 00062 void _increment(); 00063 void _incRise(); 00064 void _incFall(); 00065 }; 00066 00067 #endif
Generated on Tue Jul 12 2022 14:09:25 by 1.7.2