Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Roboshark_V9 by
Diff: main.cpp
- Revision:
- 15:8e8b23d4abb4
- Parent:
- 14:feafcee53fed
--- a/main.cpp Mon May 14 22:11:47 2018 +0000 +++ b/main.cpp Tue May 15 21:50:26 2018 +0000 @@ -55,6 +55,7 @@ int links = 0; int linksLast = 0; int skip = 0; +int BL = 1; //von main Vincent kopiert DigitalOut enableMotorDriver(PB_2); @@ -67,44 +68,26 @@ EncoderCounter counterLeft(PB_6, PB_7); EncoderCounter counterRight(PA_6, PC_7); -IRSensor iRSensor(IrRight, IrLeft, IrFront, dis2R, dis2L, dis2F, LineSensor); //von main Vincent kopiert +IRSensor iRSensor(IrRight, IrLeft, IrFront, dis2R, dis2L, dis2F, LineSensor, button); //von main Vincent kopiert Controller controller(pwmLeft, pwmRight, counterLeft, counterRight); Fahren fahren(controller, counterLeft, counterRight, iRSensor); //Reihenfolge!!!!!!!!!!!!!!!!!!! Ultra wichtig int main(){ - led0 = 1; enable = 1; enableMotorDriver = 1; // Schaltet den Leistungstreiber ein while(1) { - - if (button == 1){ - temp = 0; - ende = 0; - skip = 0; - } + - if(button != linksLast){ // Zustand button speichern + if(button == linksLast){ links = 1; + linksLast = links; } else { links = 0; } - linksLast = button; - - if ((links == 0) && (skip == 0)){ - ledRechtsAktiv = 1; - ledLinksAktiv = 0; - wait (2); - skip = 1; - } else { if ((links == 1) && ( skip == 0)){ - ledLinksAktiv = 1; - ledRechtsAktiv = 0; - wait (2); - skip = 1; - } - } + // IR Sensoren einlesen float disR = iRSensor.readR(); // Distanz in mm float disL = iRSensor.readL(); @@ -117,6 +100,21 @@ int IrF = iRSensor.codeF(); ende = iRSensor.get_ende(); // Line erkennt = 1 + BL = button; + if (button == 0){ + temp = 0; + ende = 0; + skip = 0; + } + + if ((links == 0) && (skip == 0)){ + wait (1); + skip = 1; + } else { if ((links == 1) && ( skip == 0)){ + wait (1); + skip = 1; + } + } /* printf (" ende = %d\n",ende); @@ -128,7 +126,8 @@ printf("IR Left = %d\n",IrL); printf("IR Front = %d\n",IrF);*/ - while ((links == 0) && (skip == 1)){ // State machine für methode Rechts + switch(links) { + case 0: // State machine für methode Rechts if((IrR==0) && (IrL==0) && (IrF==1) && (ende == 0)){ caseDrive = 2; } else if ((IrR==0) && (IrL==1) && (IrF==0) && (ende == 0)){ @@ -148,8 +147,9 @@ temp = 1; } else {caseDrive = 0; } - } - while ((links == 1) && (skip == 1)){ //State Machine für Methode Links + break; + + case 1: //State Machine für Methode Links if((IrR==0) && (IrL==0) && (IrF==0) && (ende == 0)){ caseDrive = 3; } else if ((IrR==1) && (IrL==0) && (IrF==0) && (ende == 0)){ @@ -160,7 +160,7 @@ caseDrive = 1; } else if ((IrR==0) && (IrL==0) && (IrF==1) && (ende == 0)){ caseDrive = 3; - } else if ((IrR==1) && (IrL==0)&& (IrF==1)&& (ende == 0)){ + } else if ((IrR==1) && (IrL==0)&& (IrF==1) && (ende == 0)){ caseDrive = 3; } else if ((IrR==0)&& (IrL==1) && (IrF==1) && (ende == 0)){ caseDrive = 2; @@ -174,8 +174,7 @@ } - // printf("caseDrive = %d\n",caseDrive); - //printf("ende = %d\n",ende); + printf("ende = %d\n",ende); wait (0.01);