Colour sensors calibrated

Dependencies:   mbed-rtos mbed Servo QEI

Fork of ICRSEurobot13 by Thomas Branch

Files at this revision

API Documentation at this revision

Comitter:
madcowswe
Date:
Fri Apr 05 16:37:36 2013 +0000
Parent:
6:995b3679155f
Child:
10:1f0cf0182067
Commit message:
Cleaned up bullshit uneeded stuff

Changed in this revision

Sensors/Colour/Colour.cpp Show annotated file Show diff for this revision Revisions of this file
Sensors/Colour/Colour.h Show annotated file Show diff for this revision Revisions of this file
Sensors/Colour/Led.h Show diff for this revision Revisions of this file
Sensors/Colour/Phototransistor.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Sensors/Colour/Colour.cpp	Fri Apr 05 15:45:00 2013 +0000
+++ b/Sensors/Colour/Colour.cpp	Fri Apr 05 16:37:36 2013 +0000
@@ -3,9 +3,9 @@
 
 #include "Colour.h"
 
-void Colour::ReadLed (Led &led, float &avg, float &stdev, const int measureNum){
+void Colour::ReadLed (DigitalOut &led, float &avg, float &stdev, const int measureNum){
     LedsOff();
-    led.on();
+    led = 1;
     double x = 0, x2 = 0;
     for (int i = measureNum; i != 0; i--) {
         float v = pt.read();
@@ -18,7 +18,7 @@
     //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){
+bool Colour::isColour(DigitalOut &led, const float &avg, const float &stdev, const float numstddev){
     float avg2, stdev2;
     ReadLed(led, avg2, stdev2);
 
--- a/Sensors/Colour/Colour.h	Fri Apr 05 15:45:00 2013 +0000
+++ b/Sensors/Colour/Colour.h	Fri Apr 05 16:37:36 2013 +0000
@@ -5,16 +5,14 @@
 //blue led use 10ohm
 
 #include "mbed.h"
-#include "Led.h"
-#include "Phototransistor.h"
 
 enum ColourEnum {BLUE, RED, WHITE, INCONCLUSIVE, BUG};
 
 class Colour{
 private:
-    Led blue;   float bavg, bstdev;
-    Led red;    float ravg, rstdev; 
-    Phototransistor pt;
+    DigitalOut blue;   float bavg, bstdev;
+    DigitalOut red;    float ravg, rstdev; 
+    AnalogIn pt;
     
 public:
     Colour(PinName bluePin, PinName redPin, PinName phototransistorPin)
@@ -46,8 +44,8 @@
     }
 
 private:
-    void LedsOff(){blue.off(); red.off();}
-    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
+    void LedsOff(){blue = 0; red = 0;}
+    void ReadLed (DigitalOut &led, float &avg, float &stdev, const int measureNum = 25); // Colour.cpp
+    bool isColour(DigitalOut &led, const float &avg, const float &stdev, const float numstddev = 2); // Colour.cpp
     
 };
\ No newline at end of file
--- a/Sensors/Colour/Led.h	Fri Apr 05 15:45:00 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#ifndef __led_h__
-#define __led_h__
-
-//Eurobot13 Led.h
-
-#include"mbed.h"
-
-class Led{
-    private:
-    DigitalOut led;
-    public:
-    Led(PinName digitalPin): led(digitalPin){ };
-    
-    void on(){
-        led = 1;
-    }
-    
-    void off(){
-        led = 0;
-    } 
-};
-
-#endif
--- a/Sensors/Colour/Phototransistor.h	Fri Apr 05 15:45:00 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef __Phototransistor_h__
-#define __Phototransistor_h__
-
-// Eurobot13 Phototransistor.h
-
-class Phototransistor{
-    private:
-    AnalogIn ain;
-    
-    public:
-    Phototransistor(PinName analogInPin)
-        : ain (analogInPin)
-        {   }
-        
-    float read() {return ain.read();}    
-    operator float() {return read();}
-    
-};
-
-#endif
--- a/main.cpp	Fri Apr 05 15:45:00 2013 +0000
+++ b/main.cpp	Fri Apr 05 16:37:36 2013 +0000
@@ -67,8 +67,6 @@
 #include "Actuators/MainMotors/MainMotor.h"
 #include "Sensors/Encoders/Encoder.h"
 #include "Sensors/Colour/Colour.h"
-#include "Sensors/Colour/Led.h"
-#include "Sensors/Colour/Phototransistor.h"
 
 
 
@@ -91,19 +89,19 @@
  *****************/
     //motortest();
     //encodertest();
-    motorencodetest();
+    //motorencodetest();
     //motorencodetestline();
     //motorsandservostest();
     //armtest();
     //motortestline();
-    //ledtest();
+    ledtest();
     //phototransistortest();
     //ledphototransistortest();
     //colourtest(); // Red SnR too low
 }
 
 void colourtest(){
-    Colour c(p9,p10,p20);
+    Colour c(P_COLOR_SENSOR_BLUE, P_COLOR_SENSOR_RED, P_COLOR_SENSOR_IN);
     c.Calibrate();
     while(true){
         wait(0.1);
@@ -130,17 +128,17 @@
 
 
 void ledphototransistortest(){
-    Led blue(p9), red(p10);
-    Phototransistor pt(p20); 
+    DigitalOut blue(P_COLOR_SENSOR_BLUE), red(P_COLOR_SENSOR_RED);
+    AnalogIn pt(P_COLOR_SENSOR_IN); 
     Serial pc(USBTX, USBRX);
 
     while(true){
-        blue.on();red.off();
+        blue = 1; red = 0;
         for(int i = 0; i != 5; i++){
             wait(0.1);
             pc.printf("Phototransistor Analog is (blue): %f \n\r", pt.read());
         }
-        blue.off();red.on();
+        blue = 0; red = 1;
         for(int i = 0; i != 5; i++){
             wait(0.1);
             pc.printf("Phototransistor Analog is (red ): %f \n\r", pt.read());
@@ -149,7 +147,7 @@
 }
 
 void phototransistortest(){
-    Phototransistor pt(p20); 
+    AnalogIn pt(P_COLOR_SENSOR_IN); 
     while(true){
         wait(0.1);
         pc.printf("Phototransistor Analog is: %f \n\r", pt.read());
@@ -158,11 +156,11 @@
 }
 
 void ledtest(){
-    Led blue(p9), red(p10);
+    DigitalOut blue(P_COLOR_SENSOR_BLUE), red(P_COLOR_SENSOR_RED);
     while(true){
-        blue.on();red.off();
+        blue = 1; red = 0;
         wait(0.2);
-        blue.off();red.on();
+        blue = 0; red = 1;
         wait(0.2);
     
     }
@@ -249,8 +247,8 @@
 }
 
 void motorencodetest(){
-    Encoder Eright(ENC_RIGHT_A, ENC_RIGHT_B), Eleft(ENC_LEFT_A, ENC_LEFT_B);
-    MainMotor mright(MOT_RIGHT_A, MOT_RIGHT_B), mleft(MOT_LEFT_A, MOT_LEFT_B);
+    Encoder Eright(P_ENC_RIGHT_A, P_ENC_RIGHT_B), Eleft(P_ENC_LEFT_A, P_ENC_LEFT_B);
+    MainMotor mright(P_MOT_RIGHT_A, P_MOT_RIGHT_B), mleft(P_MOT_LEFT_A, P_MOT_LEFT_B);
     Serial pc(USBTX, USBRX);
     
     const float speed = -0.3;