ICRS Eurobot 2013

Dependencies:   mbed mbed-rtos Servo QEI

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?

UserRevisionLine numberNew contents of line
twighk 4:1be0f6c6ceae 1
twighk 4:1be0f6c6ceae 2 // Eurobot13 Colour.cpp
twighk 4:1be0f6c6ceae 3
twighk 4:1be0f6c6ceae 4 #include "Colour.h"
twighk 4:1be0f6c6ceae 5
madcowswe 7:4340355261f9 6 void Colour::ReadLed (DigitalOut &led, float &avg, float &stdev, const int measureNum){
twighk 4:1be0f6c6ceae 7 LedsOff();
madcowswe 7:4340355261f9 8 led = 1;
twighk 4:1be0f6c6ceae 9 double x = 0, x2 = 0;
twighk 4:1be0f6c6ceae 10 for (int i = measureNum; i != 0; i--) {
twighk 4:1be0f6c6ceae 11 float v = pt.read();
twighk 4:1be0f6c6ceae 12 x += v;
twighk 4:1be0f6c6ceae 13 x2+= v*v;
twighk 4:1be0f6c6ceae 14 }
twighk 4:1be0f6c6ceae 15 avg = x / measureNum;
twighk 4:1be0f6c6ceae 16 stdev = sqrt(x2 / measureNum - avg*avg);
twighk 4:1be0f6c6ceae 17 LedsOff();
twighk 4:1be0f6c6ceae 18 //pc.printf("Phototransistor Analog is: %f\t%f\n\r", avg, stdev);
twighk 4:1be0f6c6ceae 19 }
twighk 4:1be0f6c6ceae 20
madcowswe 7:4340355261f9 21 bool Colour::isColour(DigitalOut &led, const float &avg, const float &stdev, const float numstddev){
twighk 4:1be0f6c6ceae 22 float avg2, stdev2;
twighk 4:1be0f6c6ceae 23 ReadLed(led, avg2, stdev2);
twighk 4:1be0f6c6ceae 24
twighk 4:1be0f6c6ceae 25 if (avg + numstddev*stdev < avg2 - numstddev*stdev2) {
twighk 4:1be0f6c6ceae 26 return true;
twighk 4:1be0f6c6ceae 27 } else {
twighk 4:1be0f6c6ceae 28 return false;
twighk 4:1be0f6c6ceae 29 }
twighk 4:1be0f6c6ceae 30 }