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 "commande.h" 00003 #include <SRF08.h> 00004 #define adr 128 00005 00006 //*************************************************** 00007 //************** Déclaration des objets ************* 00008 //*************************************************** 00009 00010 Serial bt(p13, p14); 00011 PwmOut pwm(p26); //objet 00012 Serial pc(USBTX,USBRX); 00013 SRF08 capt(p28,p27,0xE0); 00014 AnalogIn optique(p15); 00015 00016 commande robot; 00017 00018 //*************************************************** 00019 //************** Prototypes fonctions *************** 00020 //*************************************************** 00021 00022 void PWM(void); // prototype fonction (cfr bas) 00023 void acqui(void); 00024 void autonomie(void); 00025 00026 00027 //*************************************************** 00028 //**************** Variables Gobales **************** 00029 //*************************************************** 00030 00031 float pulse; 00032 int distance; 00033 unsigned c; 00034 float droite, gauche,devant,capteur; 00035 int right,left,straight,vu; 00036 00037 //*************************************************** 00038 //********************** MAIN *********************** 00039 //*************************************************** 00040 00041 int main() 00042 { 00043 bt.baud(57600); 00044 while(1) 00045 { 00046 autonomie(); 00047 /*while(1){ 00048 char choix = bt.getc(); 00049 00050 if(choix=='0'){ 00051 robot.avancer(50);bt.printf("avance\n");} 00052 else if(choix=='1'){ 00053 robot.reculer(50);bt.printf("recule\n");} 00054 else if(choix=='2'){ 00055 robot.tourner_gauche(60);bt.printf("gauche\n");} 00056 else if(choix=='3'){ 00057 robot.tourner_droite(60);bt.printf("droite\n");} 00058 else if(choix=='4'){ 00059 robot.stop();bt.printf("stop\n\r");} 00060 else if(choix=='5') 00061 break; 00062 }*/ 00063 } 00064 } 00065 00066 //**************************************************** 00067 //******************** Fonctions ********************* 00068 //**************************************************** 00069 00070 00071 /*void direction ( int x) //objectif faire le CHOIX de la meilleure direction 00072 { 00073 if((straight < (left + 10)) && (straight < (right + 10)) 00074 {robot.avancer(50);bt.printf("avance\n");} 00075 if((left > (right + 15)) && (left >= (straight + 15))){ // pourquoi le + XX ? parce que le capteur est trop sensible pour varier suivant l'unité choisie 00076 robot.tourner_droite(60);bt.printf("droite\n"); // comparaison capteur relevé devant, à gauche et à droite, => la valeur la plus faible (= obstacle le + loin) l'emporte 00077 robot.avancer(50);bt.printf("avance\n");} 00078 if((right > (left + 15)) && (right >= (straight + 15))){ 00079 robot.tourner_gauche(60);bt.printf("gauche\n"); 00080 robot.avancer(50);bt.printf("avance\n");} 00081 }*/ 00082 void autonomie() 00083 { 00084 pwm.period_ms(20); //définition da la largeur de l'impulsion: 20 ms 00085 pulse=0.0715; 00086 00087 while(1) 00088 { 00089 00090 pulse=0.0715;pwm.write(pulse);acqui(); //capteur centre 00091 devant=vu; straight=capteur; 00092 if(straight>50) 00093 robot.avance(50); 00094 while(devant<60 && straight<50) 00095 { 00096 robot.stop(); 00097 pulse=0.095;wait(0.03);pwm.write(pulse);acqui(); //capteur gauche 00098 gauche=vu; left=capteur; 00099 00100 pulse=0.048;wait(0.03);pwm.write(pulse);acqui(); //dcapteur roite 00101 droite=vu; right=capteur; 00102 00103 if(gauche<droite) 00104 { 00105 robot.tourner_gauche(40); 00106 wait(0.6); 00107 robot.stop(); 00108 } 00109 else if(gauche>droite) 00110 { 00111 robot.tourner_droite(40); 00112 wait(0.6); 00113 robot.stop(); 00114 } 00115 pulse=0.0715;wait(0.03);pwm.write(pulse);acqui(); //capteur centre 00116 devant=vu; straight=capteur; 00117 } 00118 } 00119 } 00120 /* 00121 pulse=0.095;pwm.write(pulse);acqui(); //gauche 00122 gauche=vu; left=capteur; 00123 pulse=0.0715;pwm.write(pulse);acqui(); //centre 00124 devant=vu; straight=capteur; 00125 pulse=0.048;pwm.write(pulse);acqui(); //droite 00126 droite=vu; right=capteur;*/ 00127 00128 void acqui() 00129 { 00130 vu = optique.read_u16(); 00131 vu = 422006/(vu-3475); 00132 capteur = capt.read(); 00133 bt.printf("Sonar : %f.2\n",capt.read()); 00134 bt.printf("Optique : %d\n",vu); 00135 wait(0.1); 00136 }
Generated on Wed Jul 13 2022 19:52:49 by
1.7.2