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
- Committer:
- burgerking
- Date:
- 2020-05-03
- Revision:
- 24:731f8fbc4adb
- Parent:
- 23:f87e7472befe
- Child:
- 25:f986cbbaf4e8
File content as of revision 24:731f8fbc4adb:
#include "mbed.h"
#include "C12832.h"
#include "moteur.h"
#include "emissionIR.h"
/* Déclaration des objets glogaux ***************************/
C12832 lcd(D11, D13, D12, D7, D10);
AnalogIn pot1(A0);
AnalogIn pot2(A1);
DigitalOut LED_rouge(D5,1);
DigitalOut LED_verte(D9,1);
//DigitalOut LED_bleue(D8,1); // NE PAS UTILISER LA LED BLEUE
DigitalIn up(A2);
DigitalIn down(A3);
DigitalIn left(A4);
DigitalIn right(A5);
DigitalIn fire(D4);
// Détecteurs d'obstacles
AnalogIn IR_G(PB_1);AnalogIn IR_D(PC_2);
DigitalIn jack(PD_2);
DigitalIn bumpers(PB_7);
DigitalOut LED(PA_13);
// Détecteur de zone blanche
BusIn Arrivee(PC_9,PC_10,PC_11,PC_12,PA_12,PA_14);
Serial uartWifi(SERIAL_TX, SERIAL_RX);
//Serial uartWifi(PA_9, PA_10);
/* Déclaration des variables globales ****************************************/
/* Définition des fonctions gérant la machine à états ************************/
// définition des fonctions
void gestionEtat(){
}
void gestionAction(){
}
/******************************************************************************/
enum Machine_A_Etat
{
Depart,Navigation,Arrive,Evitement,Rotation
};
int main() {
int iState=Depart;
float distObsGauche=pot1.read();
float distObsDroite=pot2.read();
int SwitchBumpers=bumpers.read();
int SwitchUp=up.read();
int SwitchJack=jack.read();
int SwitchFire=fire.read();
lcd.cls();
lcd.locate(32,16);
lcd.printf("Module ER2 : template");
while(true){
wait(.5);
switch(iState){
case Depart :
LED_verte.write(1);
//printf.lcd("Depart");
break;
case Navigation :
//No Yellow LED
commandeMoteurs(50,50);
//printf.lcd("Navigation");
break;
case Arrive :
LED_verte.write(!LED_verte.read());
commandeMoteurs(0,0);
//printf.lcd("Arrive");
break;
case Evitement :
LED_rouge.write(1);
if(distObsDroite>distObsGauche)
commandeMoteurs(100,0);
//printf.lcd("Evitement1");
else
commandeMoteurs(0,100);
//printf.lcd("Evitement2");
break;
case Rotation :
LED_rouge.write(!LED_rouge.read());
if(distObsDroite>distObsGauche)
commandeMoteurs(100,0);
//printf.lcd("Rotation1");
else
commandeMoteurs(0,100);
//printf.lcd("Rotation2");
break;
}//switch
if(iState==Depart)
{
if(SwitchJack==0||SwitchFire==1)
iState=Navigation;
if(SwitchUp==1)
iState=Arrive;
}
if(iState==Navigation)
{
if(distObsGauche>20||distObsDroite>20)
iState=Rotation;
if(20<distObsGauche<40&&20<distObsDroite<40)
iState=Evitement;
if(/*white tested||*/SwitchBumpers==1)
iState=Arrive;
}
if(iState==Arrive)
{
if(SwitchUp==1)
iState=Depart;
}
if(iState==Evitement)
{
if(distObsGauche<20||distObsDroite<20)
iState=Rotation;
if(distObsGauche>40&&distObsDroite>40)
iState=Navigation;
if(/*white tested||*/SwitchBumpers==1)
iState=Arrive;
}
if(iState==Rotation)
{
if(distObsGauche>40&&distObsDroite>40)
iState=Navigation;
if(/*white tested||*/SwitchBumpers==1)
iState=Evitement;
}
}//while
}