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