![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
noraml
main.cpp
- Committer:
- rakul
- Date:
- 2019-01-23
- Revision:
- 0:7e4a20d28a90
File content as of revision 0:7e4a20d28a90:
#include "IHM.h" // contient mbed.h #include "Nboard.h" #define ENFONCE 0 #define CONSTANTE 0.7 IHM ihm; Timer timer; char rar; float vpot,capt_eg,capt_cg,capt_cd,capt_rac,capt_ed; void test(); void course(); void nouvel_suivi_automate(); void raccourci(); /*-------------------------------------------------------------------------------------------------*/ int main(void) { unsigned char choix=0; ihm.LCD_clear(); timer.reset(); timer.start(); while (timer.read()<3) { if (BP0==ENFONCE) choix=1; } if (choix==1) { test(); } else course(); return 0; } /*----------------------------------------------------------------------------------------------------------*/ void test(void) { ihm.LCD_gotoxy(0,0); ihm.LCD_printf("TEST Robot D3"); wait(1.0); pwmg.period_us(50); pwmd.period_us(50); ihm.LCD_clear(); while (1) { BusSelectMux = Ana1;//centre gauche wait_us(1); capt_cg=AnaIn.read(); BusSelectMux = Ana2;//centre droit wait_us(1); capt_cd=AnaIn.read(); BusSelectMux = Ana0;//gauche wait_us(1); capt_eg=AnaIn.read(); BusSelectMux = Ana5;//droite wait_us(1); capt_ed=AnaIn.read(); BusSelectMux = Ana4;//raccourci wait_us(1); capt_rac=AnaIn.read(); if (capt_rac>CONSTANTE) led4=1; else led4=0; if (capt_eg>CONSTANTE) led3=1; else led3=0; if (capt_cg>CONSTANTE) led2=1; else led2=0; if (capt_cd>CONSTANTE) led1=1; else led1=0; if (capt_ed>CONSTANTE) LED0=1; else LED0=0; ihm.LCD_gotoxy(0,0); ihm.LCD_printf("%3.2f", capt_rac);//raccourci ihm.LCD_gotoxy(1,3); ihm.LCD_printf("%3.2f ", capt_eg);//gauche ihm.LCD_gotoxy(0,6); ihm.LCD_printf("%3.2f", capt_cg);//centre gauche ihm.LCD_gotoxy(1,9); ihm.LCD_printf("%3.2f", capt_cd);//centre droit ihm.LCD_gotoxy(0,12); ihm.LCD_printf("%3.2f", capt_ed);//droite //Test moteurs. if(BP2==0)//gauche { pwmg.write(0); pwmd.write(0.25); wait(2); pwmg.write(0); pwmd.write(0); } if(BP1==0)//droite { pwmg.write(0.25); pwmd.write(0); wait(2); pwmg.write(0); pwmd.write(0); } if(BP0 == 0) { while(BP0==0) { BusSelectMux = Vpot; wait_us(1); vpot=AnaIn.read(); pwmd.write(vpot); pwmg.write(vpot); } pwmg.write(0); pwmd.write(0); } //Test Bouton Poussoir. if (BP==1) led7=1; else led7=0; if (Jack==0) course(); } } /*----------------------------------------------------------------------------------------------------------*/ void course(void) { ihm.LCD_clear(); LEDs=0x80; pwmg.period_us(50); pwmd.period_us(50); ihm.LCD_gotoxy(0,0); ihm.LCD_printf("COURSE D3: Jack?"); //Attente du Jack. while (Jack==1) { BusSelectMux = Vpot; wait_us(1); vpot=AnaIn.read(); ihm.LCD_gotoxy(1,0); ihm.LCD_printf("%3.2f",vpot); //Affichage valeur potentiomètre. //Chenillard d'attente. LEDs=LEDs>>1; wait(0.5-vpot); if(LEDs==0x01) { LEDs=0x80; wait(0.5-vpot); } } //Lancement du timer. timer.reset(); timer.start(); //Départ du robot sur la ligne. while(1) { /*if (0<rar && rar<3) {raccourci();} else*/ nouvel_suivi_automate(); } } /*--------------------------------------------------------------------------------------------------------------------------*/ void nouvel_suivi_automate(void) { typedef enum {ligne, sortieD, attente, sortieG,arret} type_suivi ; static type_suivi suivi = ligne ; BusSelectMux = Ana1;//centre gauche wait_us(1); capt_cg=AnaIn.read(); BusSelectMux = Ana2;//centre droit wait_us(1); capt_cd=AnaIn.read(); BusSelectMux = Ana0;//gauche wait_us(1); capt_eg=AnaIn.read(); BusSelectMux = Ana5;//droite wait_us(1); capt_ed=AnaIn.read(); BusSelectMux = Ana4;//raccourci wait_us(1); capt_rac=AnaIn.read(); switch(suivi) { case ligne: pwmg.write(0.26+vpot); pwmd.write(0.25+vpot); /* if(capt_rac>CONSTANTE && capt_ed<CONSTANTE) { rar=1; }*/ if(capt_cg > CONSTANTE && capt_cd < CONSTANTE) { suivi = sortieD; } else if(capt_cg < CONSTANTE && capt_cd > CONSTANTE) { suivi = sortieG; } break; case sortieD: //correction sortie droite pwmg.write(0.15+vpot); pwmd.write(0.45+vpot); if(capt_cg > CONSTANTE && capt_cd > CONSTANTE) { suivi = ligne; } break; case sortieG: //correction sortie gauche pwmg.write(0.45+vpot); pwmd.write(0.15+vpot); if(capt_cg > CONSTANTE && capt_cd > CONSTANTE) { suivi = ligne; } break; case arret: timer.stop(); ihm.LCD_gotoxy(1,7); ihm.LCD_printf("%.2fsec",timer.read()); pwmg.write(0); pwmd.write(0); if (Jack==1) { wait(0.2); while(Jack==1); course(); } break; } if (BP==1) suivi=arret; } /*---------------------------------------------------------------------------------------*/ void raccourci(void) { typedef enum {ligne, sortieD, attente, sortieG,raccour} type_suivi ; static type_suivi suivi = ligne ; BusSelectMux = Ana1;//centre gauche wait_us(1); capt_cg=AnaIn.read(); BusSelectMux = Ana2;//centre droit wait_us(1); capt_cd=AnaIn.read(); BusSelectMux = Ana0;//gauche wait_us(1); capt_eg=AnaIn.read(); BusSelectMux = Ana5;//droite wait_us(1); capt_ed=AnaIn.read(); BusSelectMux = Ana4;//raccourci wait_us(1); capt_rac=AnaIn.read(); BusSelectMux = Vpot;//potentiometre wait_us(1); vpot=AnaIn.read(); switch(suivi) { case ligne: pwmg.write(0.257); pwmd.write(0.25); if(capt_cg < CONSTANTE && capt_cd > CONSTANTE) { suivi = sortieG; } if(capt_cg > CONSTANTE && capt_cd < CONSTANTE) { suivi = sortieD; } break; case sortieD: //correction sortie droite pwmg.write(0.15); pwmd.write(0.25); if(capt_cg > CONSTANTE && capt_cd >CONSTANTE) { suivi = ligne; } break; case sortieG: //correction sortie gauche pwmg.write(0.25); pwmd.write(0.15); if(capt_cg > CONSTANTE && capt_cd > CONSTANTE) { suivi = ligne; } break; case attente: //correction sortie gauche pwmg.write(0.257); pwmd.write(0.25); if(capt_rac > CONSTANTE ) { suivi = raccour; } break; case raccour: //correction sortie gauche while(capt_ed<CONSTANTE) { pwmg.write(0.01); pwmd.write(0.2); } suivi = ligne; rar++; break; if(capt_rac>0.8) {suivi =attente;} } }