![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
vf
Dependencies: Servo ServoArm mbed
Fork of PES_Official by
Diff: Sources/main.cpp
- Revision:
- 1:388c915756f5
- Parent:
- 0:d267b248eff4
- Child:
- 2:01e9de508316
diff -r d267b248eff4 -r 388c915756f5 Sources/main.cpp --- a/Sources/main.cpp Sat Mar 11 10:14:00 2017 +0000 +++ b/Sources/main.cpp Sun Mar 19 12:20:26 2017 +0000 @@ -3,22 +3,6 @@ #include <cstdlib> -#define NEAR 0.1f //Used for distance Sensors. If they're to near to a wall -> turn -#define LEFT //Arrayindex of the left Sensor -#define FWD //Arrayindex of the forward Sensor -#define RIGHT //Arrayindex of the right Sensor - - -//Robot related: -PwmOut left(PA_8); -PwmOut right(PA_3); - -DigitalOut powerSignal(PB_2); -DigitalIn errorSignal(PB_14); -DigitalIn overtemperatur(PB_15); - -Robot bot( &left, &right, &powerSignal ); - //DistanceSensors related: Serial pc(SERIAL_TX, SERIAL_RX); @@ -27,79 +11,40 @@ DigitalOut bit0(PH_1); DigitalOut bit1(PC_2); DigitalOut bit2(PC_3); -//Robot::DistanceSensors sensors[6]; + +//Leds related: +DigitalOut leds[6] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 }; -//LED related: -DigitalOut leds[] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 }; +//motor related: +PwmOut left(PA_8); +PwmOut right(PA_9); -void initialiseDistanceSensors(){ +DigitalOut powerSignal(PB_2); +DigitalIn errorSignal(PB_14); +DigitalIn overtemperatur(PB_15); + +//Farbsensor: +AnalogIn FarbVoltage(A0); + +Robot sam( &left, &right, &powerSignal, leds, &FarbVoltage ); //Implement the Farbsensor into the Robot init function!! + +void initializeDistanceSensors(){ for( int ii = 0; ii<6; ++ii) { - bot.sensors[ii].init(&sensorVoltage, &bit0, &bit1, &bit2, ii); + sam.sensors[ii].init(&sensorVoltage, &bit0, &bit1, &bit2, ii); - enable = 1; + enable = 1; } } -void fahralgorithmus(){ +/* */ +int main(){ - int rando = 0; //Will be used for rdandom actions. - - while( 1 ) { //Remember to change the indices. Also make into a seperate function - - if ( bot.sensors[0] < NEAR ) { //Left Sensor - while ( bot.sensors[0] < NEAR ) { - bot.turnRight(); - } - } - - else if ( bot.sensors[1] < NEAR ) { //Front Sensor - rando = rand() % 2; - while ( bot.sensors[1] < NEAR ) { - bot.turnAround(rando); - } - } - - else if ( bot.sensors[2] < NEAR ) { //Right Sensor - while ( bot.sensors[2] < NEAR ) { - bot.turnLeft(); - } - } - - else { - bot.drive(); - } - - } -} - -/* * / - - -int main(){ + initializeDistanceSensors(); + int counter = 0; //counts how many times the robot has turned, before driving + while( 1 ){ - bot.drive(); + sam.search(&counter); + wait( 0.1f ); } return 0; -} -/* */ - - -/* */ -int main() -{ - initialiseDistanceSensors(); - - while( 1 ){ - for(int i=0; i<6; i++){ - if(bot.sensors[i] > 0.05f){ - leds[i] = 1; - } - else{ - leds[i] = 0; - } - } - } - - return 0; -} -/* */ \ No newline at end of file +} \ No newline at end of file