Colour sensors calibrated
Dependencies: mbed-rtos mbed Servo QEI
Fork of ICRSEurobot13 by
Revision 4:1be0f6c6ceae, committed 2013-04-03
- Comitter:
- twighk
- Date:
- Wed Apr 03 17:54:53 2013 +0000
- Parent:
- 3:717de74f6ebd
- Child:
- 5:56a5fdd373c9
- Commit message:
- State on 3rd of april
Changed in this revision
--- a/Actuators/Actuator.h Mon Apr 01 15:33:48 2013 +0000 +++ b/Actuators/Actuator.h Wed Apr 03 17:54:53 2013 +0000 @@ -6,7 +6,7 @@ class Actuator { private: - static Actuator *Head; + static Actuator *Head; // Actuator.cpp Actuator *next; public: @@ -24,15 +24,14 @@ virtual void halt (void) = 0; static void haltandCatchFire(void){ - //halt - for(Actuator* nxt = Head; nxt != NULL; nxt = nxt->next){ - nxt->halt(); - } - DigitalOut myled(LED1); - myled = 1; - - //catchFire - while(true); + DigitalOut myled(LED1); + myled = 1; + //halt + for(Actuator* nxt = Head; nxt != NULL; nxt = nxt->next){ + nxt->halt(); + } + //catchFire + while(true); }
--- a/Actuators/Arms/Arm.h Mon Apr 01 15:33:48 2013 +0000 +++ b/Actuators/Arms/Arm.h Wed Apr 03 17:54:53 2013 +0000 @@ -11,7 +11,12 @@ bool updirn; public: - Arm(PinName yellow, bool upflip = false, float range = 0.0005, float degrees = 45.0) : Servo(yellow) { + Arm ( PinName yellowPWM + , bool upflip = false + , float range = 0.0005, float degrees = 45.0 + ) + : Servo(yellowPWM) + { calibrate(range, degrees); updirn = upflip; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sensors/Colour/Colour.cpp Wed Apr 03 17:54:53 2013 +0000 @@ -0,0 +1,30 @@ + +// Eurobot13 Colour.cpp + +#include "Colour.h" + +void Colour::ReadLed (Led &led, float &avg, float &stdev, const int measureNum){ + LedsOff(); + led.on(); + double x = 0, x2 = 0; + for (int i = measureNum; i != 0; i--) { + float v = pt.read(); + x += v; + x2+= v*v; + } + avg = x / measureNum; + stdev = sqrt(x2 / measureNum - avg*avg); + LedsOff(); + //pc.printf("Phototransistor Analog is: %f\t%f\n\r", avg, stdev); +} + +bool Colour::isColour(Led &led, const float &avg, const float &stdev, const float numstddev){ + float avg2, stdev2; + ReadLed(led, avg2, stdev2); + + if (avg + numstddev*stdev < avg2 - numstddev*stdev2) { + return true; + } else { + return false; + } +} \ No newline at end of file
--- a/Sensors/Colour/Colour.h Mon Apr 01 15:33:48 2013 +0000 +++ b/Sensors/Colour/Colour.h Wed Apr 03 17:54:53 2013 +0000 @@ -1,7 +1,6 @@ // Eurobot13 Colour.h - #include "mbed.h" #include "Led.h" #include "Phototransistor.h" @@ -45,32 +44,7 @@ private: void LedsOff(){blue.off(); red.off();} - void ReadLed (Led &led, float &avg, float &stdev, const int measureNum = 25){ - LedsOff(); led.on(); - double x = 0, x2 = 0; - for (int i = measureNum; i != 0; i--){ - float v = pt.read(); - x += v; - x2+= v*v; - } - avg = x / measureNum; - stdev = sqrt(x2 / measureNum - avg*avg); - LedsOff(); - - pc.printf("Phototransistor Analog is: %f\t%f\n\r", avg, stdev); - } + void ReadLed (Led &led, float &avg, float &stdev, const int measureNum = 25); // Colour.cpp + bool isColour(Led &led, const float &avg, const float &stdev, const float numstddev = 2); // Colour.cpp - bool isColour(Led &led, const float &avg, const float &stdev, const float numstddev = 2 ){ - float avg2, stdev2; - ReadLed(led, avg2, stdev2); - - if (avg + numstddev*stdev < avg2 - numstddev*stdev2){ - return true; - } else { - return false; - } - } - - - }; \ No newline at end of file
--- a/Sensors/Colour/Phototransistor.h Mon Apr 01 15:33:48 2013 +0000 +++ b/Sensors/Colour/Phototransistor.h Wed Apr 03 17:54:53 2013 +0000 @@ -1,7 +1,6 @@ #ifndef __Phototransistor_h__ #define __Phototransistor_h__ - // Eurobot13 Phototransistor.h class Phototransistor{
--- a/main.cpp Mon Apr 01 15:33:48 2013 +0000 +++ b/main.cpp Wed Apr 03 17:54:53 2013 +0000 @@ -5,12 +5,12 @@ #include "mbed.h" Serial pc(USBTX, USBRX); +#include "Actuators/Arms/Arm.h" #include "Actuators/MainMotors/MainMotor.h" +#include "Others/EmergencyStop/EmergencyStop.h" #include "Sensors/Encoders/Encoder.h" -#include "Actuators/Arms/Arm.h" -#include "Others/EmergencyStop/EmergencyStop.h" +#include "Sensors/Colour/Colour.h" #include "Sensors/Colour/Led.h" -#include "Sensors/Colour/Colour.h" #include "Sensors/Colour/Phototransistor.h" @@ -96,7 +96,6 @@ void phototransistortest(){ Phototransistor pt(p20); - Serial pc(USBTX, USBRX); while(true){ wait(0.1); pc.printf("Phototransistor Analog is: %f \n\r", pt.read()); @@ -132,7 +131,7 @@ Encoder Eleft(p27, p28), Eright(p30, p29); MainMotor mleft(p24,p23), mright(p21,p22); Arm sTop(p25), sBottom(p26); - Serial pc(USBTX, USBRX); + //Serial pc(USBTX, USBRX); const float speed = 0.0; const float dspeed = 0.0; @@ -177,7 +176,7 @@ void motorencodetestline(){ Encoder Eleft(p27, p28), Eright(p30, p29); MainMotor mleft(p24,p23), mright(p21,p22); - Serial pc(USBTX, USBRX); + //Serial pc(USBTX, USBRX); const float speed = 0.2; const float dspeed = 0.1;