Allows the M3Pi to be used as a Sumo robot, using the sharp 100 distance sensors on the front. Run away strategy
SharpDigiDist100.h
00001 #ifndef SHARPDIGIDIST100_H 00002 #define SHARPDIGIDIST100_H 00003 00004 #include "mbed.h" 00005 00006 /** A class which interfaces with a Sharp Digital Distance sensor (GP2Y0D810) 00007 * 00008 * Example: 00009 * @code 00010 * 00011 * @endcode 00012 * 00013 */ 00014 00015 class SharpDigiDist100 00016 { 00017 public: 00018 00019 /** Create a sensor input 00020 * 00021 * @param pin The pin the output of the sensor is connected to 00022 */ 00023 00024 SharpDigiDist100(PinName pin); 00025 00026 /** The enum which makes up the output 00027 * 00028 */ 00029 00030 enum Distance 00031 { 00032 Near = 1, 00033 Mid, 00034 Far 00035 }; 00036 00037 /** Returns the distace as an enum 00038 * 00039 * @return The distance code: 1 is near, 2 is middle distance and 3 is far 00040 */ 00041 00042 int getDistance(); 00043 00044 /** Attaches a function which is called on distance change 00045 * 00046 * @param A pointer to a function with params/returns: void func(void) 00047 */ 00048 00049 void attachOnChange(void (*ptr) (void)); 00050 00051 00052 protected: 00053 00054 InterruptIn intin; 00055 00056 DigitalIn pinin; 00057 00058 Timer timer1; 00059 00060 enum Distance current; 00061 00062 enum Distance last; 00063 00064 void onInt(); 00065 00066 Timeout timeout; 00067 00068 void (*onChange) (void); 00069 00070 bool onChangeAttached; 00071 00072 //DigitalOut Debug; 00073 }; 00074 00075 #endif
Generated on Wed Aug 3 2022 20:07:45 by 1.7.2