![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is some awesome robot code
Dependencies: mbed-rtos mbed QEI
Fork of ICRSEurobot13 by
Diff: main.cpp
- Revision:
- 3:717de74f6ebd
- Parent:
- 2:45da48fab346
- Child:
- 4:1be0f6c6ceae
--- a/main.cpp Fri Mar 29 20:09:21 2013 +0000 +++ b/main.cpp Mon Apr 01 15:33:48 2013 +0000 @@ -1,12 +1,17 @@ +#pragma Otime // Compiler Optimisations // Eurobot13 main.cpp #include "mbed.h" +Serial pc(USBTX, USBRX); #include "Actuators/MainMotors/MainMotor.h" #include "Sensors/Encoders/Encoder.h" #include "Actuators/Arms/Arm.h" #include "Others/EmergencyStop/EmergencyStop.h" +#include "Sensors/Colour/Led.h" +#include "Sensors/Colour/Colour.h" +#include "Sensors/Colour/Phototransistor.h" @@ -17,24 +22,102 @@ void motorsandservostest(); void armtest(); void motortestline(); +void ledtest(); +void phototransistortest(); +void ledphototransistortest(); +void colourtest(); int main() { -/* Setup Emergency stop for actuators, - Derive all actuators from the pure virtual actuator class +/* Setup EmergencyStop button for actuators. + Derive all actuators from the pure virtual actuator class! */ EmergencyStop EStop(p8); +/***************** + * Test Code * + *****************/ //motortest(); //encodertest(); //motorencodetest(); //motorencodetestline(); //motorsandservostest(); - armtest(); + //armtest(); //motortestline(); + //ledtest(); + //phototransistortest(); + //ledphototransistortest(); + colourtest(); // Red SnR too low +} + +void colourtest(){ + Colour c(p9,p10,p20); + c.Calibrate(); + while(true){ + wait(0.1); + ColourEnum ce = c.getColour(); + switch(ce){ + case BLUE : + pc.printf("BLUE\n\r"); + break; + case RED: + pc.printf("RED\n\r"); + break; + case WHITE: + pc.printf("WHITE\n\r"); + break; + case INCONCLUSIVE: + pc.printf("INCONCLUSIVE\n\r"); + break; + default: + pc.printf("BUG\n\r"); + } } +} + + +void ledphototransistortest(){ + Led blue(p9), red(p10); + Phototransistor pt(p20); + Serial pc(USBTX, USBRX); + + while(true){ + blue.on();red.off(); + 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(); + for(int i = 0; i != 5; i++){ + wait(0.1); + pc.printf("Phototransistor Analog is (red ): %f \n\r", pt.read()); + } + } +} + +void phototransistortest(){ + Phototransistor pt(p20); + Serial pc(USBTX, USBRX); + while(true){ + wait(0.1); + pc.printf("Phototransistor Analog is: %f \n\r", pt.read()); + } + +} + +void ledtest(){ + Led blue(p9), red(p10); + while(true){ + blue.on();red.off(); + wait(0.2); + blue.off();red.on(); + wait(0.2); + + } +} + void armtest(){ - Arm white(p26), black(p25, false,0.0005, 180); - while(1){ + Arm white(p26), black(p25, false, 0.0005, 180); + while(true){ white(0); black(0); wait(1); @@ -137,7 +220,7 @@ Encoder E1(p28, p27); Encoder E2(p29, p30); Serial pc(USBTX, USBRX); - while(1){ + while(true){ wait(0.1); pc.printf("Position is: %i \t %i \n\r", E1.getPoint(), E2.getPoint()); } @@ -145,7 +228,7 @@ } void motortest(){ MainMotor mright(p22,p21), mleft(p23,p24); - while(1) { + while(true) { wait(1); mleft(0.8); mright(0.8); wait(1);