ICRS Eurobot 2013
Dependencies: mbed mbed-rtos Servo QEI
Sensors/Colour/Colour.h@20:70d651156779, 2013-04-09 (annotated)
- Committer:
- madcowswe
- Date:
- Tue Apr 09 15:33:36 2013 +0000
- Revision:
- 20:70d651156779
- Parent:
- 7:4340355261f9
Predict loop running, update loop not done.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
twighk | 3:717de74f6ebd | 1 | |
twighk | 3:717de74f6ebd | 2 | // Eurobot13 Colour.h |
twighk | 3:717de74f6ebd | 3 | |
madcowswe | 5:56a5fdd373c9 | 4 | //red led use 45ohm |
madcowswe | 5:56a5fdd373c9 | 5 | //blue led use 10ohm |
madcowswe | 5:56a5fdd373c9 | 6 | |
twighk | 3:717de74f6ebd | 7 | #include "mbed.h" |
twighk | 3:717de74f6ebd | 8 | |
twighk | 3:717de74f6ebd | 9 | enum ColourEnum {BLUE, RED, WHITE, INCONCLUSIVE, BUG}; |
twighk | 3:717de74f6ebd | 10 | |
twighk | 3:717de74f6ebd | 11 | class Colour{ |
twighk | 3:717de74f6ebd | 12 | private: |
madcowswe | 7:4340355261f9 | 13 | DigitalOut blue; float bavg, bstdev; |
madcowswe | 7:4340355261f9 | 14 | DigitalOut red; float ravg, rstdev; |
madcowswe | 7:4340355261f9 | 15 | AnalogIn pt; |
twighk | 3:717de74f6ebd | 16 | |
twighk | 3:717de74f6ebd | 17 | public: |
twighk | 3:717de74f6ebd | 18 | Colour(PinName bluePin, PinName redPin, PinName phototransistorPin) |
twighk | 3:717de74f6ebd | 19 | : blue(bluePin) |
twighk | 3:717de74f6ebd | 20 | , red (redPin) |
twighk | 3:717de74f6ebd | 21 | , pt (phototransistorPin) |
twighk | 3:717de74f6ebd | 22 | { |
twighk | 3:717de74f6ebd | 23 | LedsOff(); |
twighk | 3:717de74f6ebd | 24 | } |
twighk | 3:717de74f6ebd | 25 | |
twighk | 3:717de74f6ebd | 26 | void Calibrate(){ |
twighk | 3:717de74f6ebd | 27 | ReadLed(blue, bavg, bstdev); |
twighk | 3:717de74f6ebd | 28 | ReadLed( red, ravg, rstdev); |
twighk | 3:717de74f6ebd | 29 | } |
twighk | 3:717de74f6ebd | 30 | |
twighk | 3:717de74f6ebd | 31 | ColourEnum getColour(){ |
twighk | 3:717de74f6ebd | 32 | bool blueb = isColour(blue, bavg, bstdev) |
twighk | 3:717de74f6ebd | 33 | , redb = isColour( red, ravg, rstdev); |
twighk | 3:717de74f6ebd | 34 | |
twighk | 3:717de74f6ebd | 35 | if ( blueb && redb) |
twighk | 3:717de74f6ebd | 36 | {return WHITE;} |
twighk | 3:717de74f6ebd | 37 | else if ( blueb && !redb) |
twighk | 3:717de74f6ebd | 38 | {return BLUE;} |
twighk | 3:717de74f6ebd | 39 | else if (!blueb && redb) |
twighk | 3:717de74f6ebd | 40 | {return RED;} |
twighk | 3:717de74f6ebd | 41 | else if (!blueb && !redb) |
twighk | 3:717de74f6ebd | 42 | {return INCONCLUSIVE;} |
twighk | 3:717de74f6ebd | 43 | return BUG; |
twighk | 3:717de74f6ebd | 44 | } |
twighk | 3:717de74f6ebd | 45 | |
twighk | 3:717de74f6ebd | 46 | private: |
madcowswe | 7:4340355261f9 | 47 | void LedsOff(){blue = 0; red = 0;} |
madcowswe | 7:4340355261f9 | 48 | void ReadLed (DigitalOut &led, float &avg, float &stdev, const int measureNum = 25); // Colour.cpp |
madcowswe | 7:4340355261f9 | 49 | bool isColour(DigitalOut &led, const float &avg, const float &stdev, const float numstddev = 2); // Colour.cpp |
twighk | 3:717de74f6ebd | 50 | |
twighk | 3:717de74f6ebd | 51 | }; |