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.
main.cpp
00001 #include "mbed.h" 00002 #include "C12832.h" 00003 #include "moteur.h" 00004 #include "emissionIR.h" 00005 00006 /* Déclaration des objets glogaux ***************************/ 00007 00008 C12832 lcd(D11, D13, D12, D7, D10); 00009 00010 AnalogIn pot1(A0); 00011 AnalogIn pot2(A1); 00012 00013 DigitalOut LED_rouge(D5,1); 00014 DigitalOut LED_verte(D9,1); 00015 //DigitalOut LED_bleue(D8,1); // NE PAS UTILISER LA LED BLEUE 00016 00017 DigitalIn up(A2); 00018 DigitalIn down(A3); 00019 DigitalIn left(A4); 00020 DigitalIn right(A5); 00021 DigitalIn fire(D4); 00022 00023 00024 // Détecteurs d'obstacles 00025 AnalogIn IR_G(PB_1);AnalogIn IR_D(PC_2); 00026 00027 DigitalIn jack(PD_2); 00028 DigitalIn bumpers(PB_7); 00029 DigitalOut LED(PA_13); 00030 00031 // Détecteur de zone blanche 00032 BusIn Arrivee(PC_9,PC_10,PC_11,PC_12,PA_12,PA_14); 00033 00034 Serial uartWifi(SERIAL_TX, SERIAL_RX); 00035 //Serial uartWifi(PA_9, PA_10); 00036 00037 /* Déclaration des variables globales ****************************************/ 00038 00039 00040 /* Définition des fonctions gérant la machine à états ************************/ 00041 00042 // définition des fonctions 00043 void gestionEtat(){ 00044 } 00045 00046 void gestionAction(){ 00047 } 00048 00049 /******************************************************************************/ 00050 enum Machine_A_Etat 00051 { 00052 Depart,Navigation,Arrive,Evitement,Rotation 00053 }; 00054 00055 int main() { 00056 lcd.cls(); 00057 lcd.locate(32,16); 00058 lcd.printf("Module ER2 : template"); 00059 while(true){ 00060 int iState=Depart; 00061 float distObsGauche=pot1.read(); 00062 float distObsDroite=pot2.read(); 00063 int SwitchBumpers=bumpers.read(); 00064 int SwitchUp=up.read(); 00065 int SwitchJack=jack.read(); 00066 int SwitchFire=fire.read(); 00067 int iFlag=0; 00068 /*wait(.5); /*this time depends on the speed of the robot*/ 00069 switch(iState){ 00070 case Depart : 00071 if(iFlag==0) 00072 { 00073 LED_verte.write(1); 00074 LED_rouge.write(0); 00075 initVariateurs(); 00076 iFlag=1; 00077 } 00078 if(SwitchJack==0||SwitchFire==1) 00079 iState=Navigation; 00080 break; 00081 00082 case Navigation : 00083 LED_verte.write(0); 00084 LED_rouge.write(0); 00085 //No Yellow LED 00086 commandeMoteurs(50,50); 00087 if(distObsGauche<0.2||distObsDroite<0.2)/*0.2=20cm,0.4=40cm*/ 00088 iState=Rotation; 00089 else if((distObsGauche>0.2&&distObsGauche<0.4)||(distObsDroite>0.2&&distObsDroite<0.4)) 00090 iState=Evitement; 00091 else if(/*white tested||*/SwitchBumpers==1) 00092 iState=Arrive; 00093 break; 00094 00095 case Arrive : 00096 wait(.1); 00097 LED_rouge.write(0); 00098 LED_verte.write(!LED_verte.read()); 00099 commandeMoteurs(0,0); 00100 if(SwitchUp==1) 00101 { 00102 iState=Depart; 00103 iFlag=0; 00104 } 00105 break; 00106 00107 case Evitement : 00108 wait(.1); 00109 LED_rouge.write(1); 00110 LED_verte.write(0); 00111 if(distObsDroite>distObsGauche) 00112 commandeMoteurs(100,0);/*turn right*/ 00113 else 00114 commandeMoteurs(0,100);/*turn left*/ 00115 if(distObsGauche<0.2||distObsDroite<0.2) 00116 iState=Rotation; 00117 else if(distObsGauche>0.4&&distObsDroite>0.4) 00118 iState=Navigation; 00119 else if(/*white tested||*/SwitchBumpers==1) 00120 iState=Arrive; 00121 break; 00122 00123 case Rotation : 00124 LED_verte.write(0); 00125 LED_rouge.write(!LED_rouge.read()); 00126 if(distObsDroite>distObsGauche) 00127 commandeMoteurs(100,0);/*turn right*/ 00128 else 00129 commandeMoteurs(0,100);/*turn left*/ 00130 if(distObsGauche>0.4&&distObsDroite>0.4) 00131 iState=Navigation; 00132 if(/*white tested||*/SwitchBumpers==1) 00133 iState=Arrive; 00134 if(distObsGauche>0.4&&distObsDroite>0.4) 00135 iState=Navigation; 00136 else if(/*white tested||*/SwitchBumpers==1) 00137 iState=Arrive; 00138 break; 00139 }//switch 00140 00141 }//while 00142 }
Generated on Mon Jul 18 2022 11:01:27 by
