noraml
Revision 0:7e4a20d28a90, committed 2019-01-23
- Comitter:
- rakul
- Date:
- Wed Jan 23 18:40:02 2019 +0000
- Commit message:
- yolo;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IHM_V2.lib Wed Jan 23 18:40:02 2019 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/teams/NBoard/code/IHM_V2/#ad91067e3f6d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Nboard.h Wed Jan 23 18:40:02 2019 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" + +DigitalOut LED0(PB_3); +DigitalOut led1(PA_7); +DigitalOut led2(PA_6); +DigitalOut led3(PA_5); +DigitalOut led4(PA_3); +DigitalOut led5(PA_1); +DigitalOut led6(PA_0); +DigitalOut led7(PA_2); + +DigitalIn BP0(PA_9,PullUp); +DigitalIn BP1(PA_10,PullUp); +DigitalIn BP2(PB_0,PullUp); +//DigitalIn BP3(PB_7,PullUp); + + +DigitalIn Jack(PB_6,PullUp); +DigitalIn BP(PB_7,PullUp); + +AnalogIn AnaIn(PB_1); +PwmOut pwmd(PB_4); +PwmOut pwmg(PB_5); + +BusOut LEDs(PB_3,PA_7,PA_6,PA_5,PA_3,PA_1,PA_0,PA_2); +BusOut BusSelectMux (PA_8,PF_1,PF_0); + +#define Ana0 0 +#define Ana1 1 +#define Ana2 2 +#define Ana3 3 +#define Ana4 4 +#define Ana5 5 +#define AIn 6 +#define Vpot 7 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Jan 23 18:40:02 2019 +0000
@@ -0,0 +1,391 @@
+#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;}
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jan 23 18:40:02 2019 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file