Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
Sensors/IncrementalEncoder/IncrementalEncoder.h@0:826c6171fc1b, 2012-06-20 (annotated)
- Committer:
- shimniok
- Date:
- Wed Jun 20 14:57:48 2012 +0000
- Revision:
- 0:826c6171fc1b
Updated documentation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:826c6171fc1b | 1 | #ifndef __INCREMENTALENCODER_H |
shimniok | 0:826c6171fc1b | 2 | #define __INCREMENTALENCODER_H |
shimniok | 0:826c6171fc1b | 3 | |
shimniok | 0:826c6171fc1b | 4 | #include "mbed.h" |
shimniok | 0:826c6171fc1b | 5 | |
shimniok | 0:826c6171fc1b | 6 | /** An interface for a simple, 1-track, incremental encoder. If using a simple reflectance sensor, then a voltage comparator |
shimniok | 0:826c6171fc1b | 7 | * circuit will be required to generate the pulsetrain. See: http://www.bot-thoughts.com/2011/03/avc-bot-wheel-encoders.html |
shimniok | 0:826c6171fc1b | 8 | * |
shimniok | 0:826c6171fc1b | 9 | */ |
shimniok | 0:826c6171fc1b | 10 | class IncrementalEncoder |
shimniok | 0:826c6171fc1b | 11 | { |
shimniok | 0:826c6171fc1b | 12 | public: |
shimniok | 0:826c6171fc1b | 13 | /** Create an incremental encoder interface. Increments counter at every rise and fall signal |
shimniok | 0:826c6171fc1b | 14 | * |
shimniok | 0:826c6171fc1b | 15 | * @param pin -- the pin to which a digital pulsetrain is sent |
shimniok | 0:826c6171fc1b | 16 | */ |
shimniok | 0:826c6171fc1b | 17 | IncrementalEncoder(PinName pin); |
shimniok | 0:826c6171fc1b | 18 | |
shimniok | 0:826c6171fc1b | 19 | /** Get ticks since last call |
shimniok | 0:826c6171fc1b | 20 | * |
shimniok | 0:826c6171fc1b | 21 | * @returns the number of ticks since the last call to this method |
shimniok | 0:826c6171fc1b | 22 | */ |
shimniok | 0:826c6171fc1b | 23 | unsigned int read(); |
shimniok | 0:826c6171fc1b | 24 | |
shimniok | 0:826c6171fc1b | 25 | /** Get total tick count since last reset |
shimniok | 0:826c6171fc1b | 26 | * |
shimniok | 0:826c6171fc1b | 27 | * @returns total ticks since the last reset or instantiation |
shimniok | 0:826c6171fc1b | 28 | */ |
shimniok | 0:826c6171fc1b | 29 | unsigned int readTotal(); |
shimniok | 0:826c6171fc1b | 30 | |
shimniok | 0:826c6171fc1b | 31 | /** Get total rise tick count |
shimniok | 0:826c6171fc1b | 32 | * |
shimniok | 0:826c6171fc1b | 33 | * @returns total rise ticks |
shimniok | 0:826c6171fc1b | 34 | */ |
shimniok | 0:826c6171fc1b | 35 | unsigned int readRise(); |
shimniok | 0:826c6171fc1b | 36 | |
shimniok | 0:826c6171fc1b | 37 | /** Get total fall tick count |
shimniok | 0:826c6171fc1b | 38 | * |
shimniok | 0:826c6171fc1b | 39 | * @returns total fall ticks |
shimniok | 0:826c6171fc1b | 40 | */ |
shimniok | 0:826c6171fc1b | 41 | unsigned int readFall(); |
shimniok | 0:826c6171fc1b | 42 | |
shimniok | 0:826c6171fc1b | 43 | /** Read time interval between ticks |
shimniok | 0:826c6171fc1b | 44 | * |
shimniok | 0:826c6171fc1b | 45 | * @returns filtered time between encoder pulses |
shimniok | 0:826c6171fc1b | 46 | */ |
shimniok | 0:826c6171fc1b | 47 | unsigned int readTime(); |
shimniok | 0:826c6171fc1b | 48 | |
shimniok | 0:826c6171fc1b | 49 | /** Reset the tick counter |
shimniok | 0:826c6171fc1b | 50 | * |
shimniok | 0:826c6171fc1b | 51 | */ |
shimniok | 0:826c6171fc1b | 52 | void reset(); |
shimniok | 0:826c6171fc1b | 53 | |
shimniok | 0:826c6171fc1b | 54 | private: |
shimniok | 0:826c6171fc1b | 55 | Timer _t; |
shimniok | 0:826c6171fc1b | 56 | unsigned int _lastTime; |
shimniok | 0:826c6171fc1b | 57 | unsigned int _time; |
shimniok | 0:826c6171fc1b | 58 | unsigned int _lastTicks; |
shimniok | 0:826c6171fc1b | 59 | unsigned int _ticks, _rise, _fall; |
shimniok | 0:826c6171fc1b | 60 | bool _new; |
shimniok | 0:826c6171fc1b | 61 | InterruptIn _interrupt; |
shimniok | 0:826c6171fc1b | 62 | void _increment(); |
shimniok | 0:826c6171fc1b | 63 | void _incRise(); |
shimniok | 0:826c6171fc1b | 64 | void _incFall(); |
shimniok | 0:826c6171fc1b | 65 | }; |
shimniok | 0:826c6171fc1b | 66 | |
shimniok | 0:826c6171fc1b | 67 | #endif |