![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Allows the M3Pi to be used as a Sumo robot, using the sharp 100 distance sensors on the front. Run away strategy
SharpDigiDist100/SharpDigiDist100.h@0:11d0f3e0d1ad, 2012-06-18 (annotated)
- Committer:
- jonmarsh
- Date:
- Mon Jun 18 09:38:17 2012 +0000
- Revision:
- 0:11d0f3e0d1ad
Not tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jonmarsh | 0:11d0f3e0d1ad | 1 | #ifndef SHARPDIGIDIST100_H |
jonmarsh | 0:11d0f3e0d1ad | 2 | #define SHARPDIGIDIST100_H |
jonmarsh | 0:11d0f3e0d1ad | 3 | |
jonmarsh | 0:11d0f3e0d1ad | 4 | #include "mbed.h" |
jonmarsh | 0:11d0f3e0d1ad | 5 | |
jonmarsh | 0:11d0f3e0d1ad | 6 | /** A class which interfaces with a Sharp Digital Distance sensor (GP2Y0D810) |
jonmarsh | 0:11d0f3e0d1ad | 7 | * |
jonmarsh | 0:11d0f3e0d1ad | 8 | * Example: |
jonmarsh | 0:11d0f3e0d1ad | 9 | * @code |
jonmarsh | 0:11d0f3e0d1ad | 10 | * |
jonmarsh | 0:11d0f3e0d1ad | 11 | * @endcode |
jonmarsh | 0:11d0f3e0d1ad | 12 | * |
jonmarsh | 0:11d0f3e0d1ad | 13 | */ |
jonmarsh | 0:11d0f3e0d1ad | 14 | |
jonmarsh | 0:11d0f3e0d1ad | 15 | class SharpDigiDist100 |
jonmarsh | 0:11d0f3e0d1ad | 16 | { |
jonmarsh | 0:11d0f3e0d1ad | 17 | public: |
jonmarsh | 0:11d0f3e0d1ad | 18 | |
jonmarsh | 0:11d0f3e0d1ad | 19 | /** Create a sensor input |
jonmarsh | 0:11d0f3e0d1ad | 20 | * |
jonmarsh | 0:11d0f3e0d1ad | 21 | * @param pin The pin the output of the sensor is connected to |
jonmarsh | 0:11d0f3e0d1ad | 22 | */ |
jonmarsh | 0:11d0f3e0d1ad | 23 | |
jonmarsh | 0:11d0f3e0d1ad | 24 | SharpDigiDist100(PinName pin); |
jonmarsh | 0:11d0f3e0d1ad | 25 | |
jonmarsh | 0:11d0f3e0d1ad | 26 | /** The enum which makes up the output |
jonmarsh | 0:11d0f3e0d1ad | 27 | * |
jonmarsh | 0:11d0f3e0d1ad | 28 | */ |
jonmarsh | 0:11d0f3e0d1ad | 29 | |
jonmarsh | 0:11d0f3e0d1ad | 30 | enum Distance |
jonmarsh | 0:11d0f3e0d1ad | 31 | { |
jonmarsh | 0:11d0f3e0d1ad | 32 | Near = 1, |
jonmarsh | 0:11d0f3e0d1ad | 33 | Mid, |
jonmarsh | 0:11d0f3e0d1ad | 34 | Far |
jonmarsh | 0:11d0f3e0d1ad | 35 | }; |
jonmarsh | 0:11d0f3e0d1ad | 36 | |
jonmarsh | 0:11d0f3e0d1ad | 37 | /** Returns the distace as an enum |
jonmarsh | 0:11d0f3e0d1ad | 38 | * |
jonmarsh | 0:11d0f3e0d1ad | 39 | * @return The distance code: 1 is near, 2 is middle distance and 3 is far |
jonmarsh | 0:11d0f3e0d1ad | 40 | */ |
jonmarsh | 0:11d0f3e0d1ad | 41 | |
jonmarsh | 0:11d0f3e0d1ad | 42 | int getDistance(); |
jonmarsh | 0:11d0f3e0d1ad | 43 | |
jonmarsh | 0:11d0f3e0d1ad | 44 | /** Attaches a function which is called on distance change |
jonmarsh | 0:11d0f3e0d1ad | 45 | * |
jonmarsh | 0:11d0f3e0d1ad | 46 | * @param A pointer to a function with params/returns: void func(void) |
jonmarsh | 0:11d0f3e0d1ad | 47 | */ |
jonmarsh | 0:11d0f3e0d1ad | 48 | |
jonmarsh | 0:11d0f3e0d1ad | 49 | void attachOnChange(void (*ptr) (void)); |
jonmarsh | 0:11d0f3e0d1ad | 50 | |
jonmarsh | 0:11d0f3e0d1ad | 51 | |
jonmarsh | 0:11d0f3e0d1ad | 52 | protected: |
jonmarsh | 0:11d0f3e0d1ad | 53 | |
jonmarsh | 0:11d0f3e0d1ad | 54 | InterruptIn intin; |
jonmarsh | 0:11d0f3e0d1ad | 55 | |
jonmarsh | 0:11d0f3e0d1ad | 56 | DigitalIn pinin; |
jonmarsh | 0:11d0f3e0d1ad | 57 | |
jonmarsh | 0:11d0f3e0d1ad | 58 | Timer timer1; |
jonmarsh | 0:11d0f3e0d1ad | 59 | |
jonmarsh | 0:11d0f3e0d1ad | 60 | enum Distance current; |
jonmarsh | 0:11d0f3e0d1ad | 61 | |
jonmarsh | 0:11d0f3e0d1ad | 62 | enum Distance last; |
jonmarsh | 0:11d0f3e0d1ad | 63 | |
jonmarsh | 0:11d0f3e0d1ad | 64 | void onInt(); |
jonmarsh | 0:11d0f3e0d1ad | 65 | |
jonmarsh | 0:11d0f3e0d1ad | 66 | Timeout timeout; |
jonmarsh | 0:11d0f3e0d1ad | 67 | |
jonmarsh | 0:11d0f3e0d1ad | 68 | void (*onChange) (void); |
jonmarsh | 0:11d0f3e0d1ad | 69 | |
jonmarsh | 0:11d0f3e0d1ad | 70 | bool onChangeAttached; |
jonmarsh | 0:11d0f3e0d1ad | 71 | |
jonmarsh | 0:11d0f3e0d1ad | 72 | //DigitalOut Debug; |
jonmarsh | 0:11d0f3e0d1ad | 73 | }; |
jonmarsh | 0:11d0f3e0d1ad | 74 | |
jonmarsh | 0:11d0f3e0d1ad | 75 | #endif |