programme course avec menu amélioré

Dependencies:   MMA8451Q mbed

Fork of Programme_course_2 by Freescale_Cachan

Files at this revision

API Documentation at this revision

Comitter:
leandre
Date:
Fri Mar 17 14:18:04 2017 +0000
Parent:
1:000a03402c6e
Commit message:
programme avec gestion des virage plus fluide

Changed in this revision

Mlib.cpp Show annotated file Show diff for this revision Revisions of this file
Mlib.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
traitement_image.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Mlib.cpp	Wed Feb 01 13:41:24 2017 +0000
+++ b/Mlib.cpp	Fri Mar 17 14:18:04 2017 +0000
@@ -149,24 +149,49 @@
 void fin_course()
 {
     static int arr = 0;
-    if(somme_derivee >= (Moyenne2(last_five, 5) + (SEUIL_NB_DERRIVEE+5*seuil_der)) || arr != 0)
+    static char moy_inter;
+    
+    /*if((somme_derivee >= (Moyenne2(last_five, 5) + (SEUIL_NB_DERRIVEE+seuil_der))) || arr != 0)
     {
-        if(t_debut.read() > 3 && S1 == 1 && arr == 0)
+        if(t_debut.read_ms() > 500 && S1 == 1 && arr == 0)
         {
-           arr = t_debut.read_ms();
+           arr = t_debut.read_ms(); 
         }
         else if(arr != 0 && t_debut.read_ms() > arr+100)
         {
             VIT = 0;
+            pc.printf("arret\ndelai:%d ms\n",(t_debut.read_ms()-arr));
         }
+        
+        
     }
+    
     for(int j = 4; j > 0; j--)
     {
         last_five[j] = last_five[j-1];
-//                pc.printf("%d\n", last_five[j]);
+    }*/
+     
+    if (t_debut.read_ms()>500){
+        moy_inter=Moyenne2(Interval, TAILLE_TAB_INT);
+        //pc.printf("%d\n",moy_inter);
+        
+        if((mem_a>6)&&(mem_b>6)){  // si la voiture n'est pas trop sur l'exterieur de la piste
+            if(S1 && (moy_inter<70) && (moy_inter>40)){  //si l'espace entre les deux lignes est plus petit que la normale (arret)
+             
+                //for(int i=0;i<5;i++)  pc.printf("%d ",Interval[i]);
+                //pc.printf("\n");
+                VIT=0;
+                pc.printf("\narret ");
+                pc.printf("\n%d ",moy_inter);
+        
+                }   
+            }
     }
-//            pc.printf("%d     |     %d\n", (somme_derivee), (Moyenne2(last_five, 5)));
-    last_five[0] = somme_derivee;
+        
+    for(int j = TAILLE_TAB_INT-1; j > 0; j--)
+    {
+        Interval[j] = Interval[j-1];
+    }   
 }
 
 
--- a/Mlib.h	Wed Feb 01 13:41:24 2017 +0000
+++ b/Mlib.h	Fri Mar 17 14:18:04 2017 +0000
@@ -19,16 +19,19 @@
 #define INCREM_BALANCE 300
 #define MARGE_LIGNE 5
 #define MARGE_DISTANCE_LIGNE 10
-#define LUMI_MOYENNE 80
+#define LUMI_MOYENNE 90
+
 #define CORRECTION_VIRAGE 1
 #define MAX_BATTERY 1.3
 #define SEUIL_NB_DERRIVEE 25
-#define KD 600  //valeur de base 400
+#define KD 400  //valeur de base 400
 #define KI 3
 
 #define BOSSE_ACTIVE S2
 
 #define VITESSE 40
+
+#define TAILLE_TAB_INT 6
 /***********************FONCTIONS**********************/
 /**/     /****************CAMERA****************/   /**/
 /**/    void F_GetData();                           /**/
@@ -87,6 +90,8 @@
 extern AnalogIn pot1;
 extern AnalogIn pot2;
 
+//extern DigitalOut RGB_R(LED_RED);
+
 /************TRAITEMENT_IMG************/
 extern Ticker t_clk; 
 extern Ticker t_finInte;
@@ -103,6 +108,9 @@
 extern int ralentire;
 extern MMA8451Q acc;
 extern char last_five[5];
+extern char mem_a;
+extern char mem_b;
+extern char Interval[TAILLE_TAB_INT];
 
 /*************AUTRES_VAR***************/
 extern Ticker t_cyc; 
--- a/main.cpp	Wed Feb 01 13:41:24 2017 +0000
+++ b/main.cpp	Fri Mar 17 14:18:04 2017 +0000
@@ -1,3 +1,5 @@
+
+
 #include "Mlib.h"
 
 
@@ -9,6 +11,7 @@
 DigitalOut led3(PTB10);
 DigitalOut led4(PTB11);
 
+
 AnalogIn pot1 (PTB3);
 AnalogIn pot2 (PTB2);
 
@@ -48,6 +51,9 @@
 int vitesse_virage = 0;
 int ligne_droite = 0;
 int integral;
+char Interval[TAILLE_TAB_INT];
+char mem_a;
+char mem_b;
 
 
 DigitalOut BP1(PTC13);//boutton A
@@ -166,7 +172,7 @@
             /****************Detection_arrivee*******************/
             
             fin_course();
-            
+            if(VIT==0) arret();
             
 
         }
--- a/traitement_image.cpp	Wed Feb 01 13:41:24 2017 +0000
+++ b/traitement_image.cpp	Fri Mar 17 14:18:04 2017 +0000
@@ -7,8 +7,8 @@
     unsigned char i;
     signed short save_a;
     signed short save_b;
+    
     int tempo = 0;
-    char mem_a, mem_b;
     char tab[3];
     char tab2[3];
     mem_a = 100;
@@ -51,20 +51,25 @@
         }
     }
     
-
-    if (mem_b == 100 && mem_a == 100)
+    Interval[0] = mem_a+mem_b;
+    if (mem_b == 100 && mem_a == 100)  // pas de ligne
     {
         baricentre = 0;
     }
-    else if (mem_b == 100)
+    else if (mem_b == 100)   //pas de ligne à gauche
     {
         //baricentre = (mem_a-MARGE_DISTANCE_LIGNE);
-        baricentre = (64-mem_a);
+        if(mem_a>25){
+            baricentre = (64-mem_a);
+        }
     }
-    else if (mem_a == 100)
+    else if (mem_a == 100)     // pas de ligne à droite
     {
         //baricentre = (MARGE_DISTANCE_LIGNE-mem_b);
-        baricentre = (64-mem_b);
+        if(mem_b>25){
+            baricentre = (64-mem_b);
+        }
+        
     }
     else
     {
@@ -150,6 +155,7 @@
     bari_bis = middle_3U(bary_tab_bis);//On calcul la médianne des 3 derniers bari
     integral += bari_bis;
     new_bari = (KI*integral+KP*bari_bis+KD*(bari_bis-last_bari))/1000;//On applique un KP et un KD (proportionnel et dérivé) au bari
+    //pc.printf("%d  ",new_bari);
     last_bari = bari_bis;
     
     led4 = ralentire;