projet neotim mpp / Mbed 2 deprecated projet_v4

Dependencies:   mbed

Revision:
4:1d58769720c6
Parent:
3:b95fe07153f1
Child:
5:3e44d8755e88
--- a/main.cpp	Mon May 25 13:04:07 2020 +0000
+++ b/main.cpp	Fri Jun 05 06:33:21 2020 +0000
@@ -5,6 +5,7 @@
 volatile int flag_timer_reglage_vitesse=0; //ce timer lit le réglage de la vitesse tous les 0.1 s
 volatile int flag_fc_haut=0; //interruption sur SW2
 volatile int flag_contact=0; //interruption sur SW3
+volatile int flag_retour=0;
 /*************** Interfaces utilisés *************************/
 Serial pc(USBTX, USBRX,9600); // liaison USB
 Ticker timer_etat;                     // Interruptions temporelles (timout)
@@ -32,6 +33,9 @@
 void IT_contact(){                  // contact avec echantillon (OK)
     flag_contact=1;
     }  
+void IT_retour(){
+    flag_retour=1;
+    }
 /*************** Programme Principal *************************/
 int main() {
     // declaration des variables
@@ -83,6 +87,13 @@
                 ENB=0;
                 Nb_pas=0;
                 }
+            else if (strcmp(command,"retour")==0){
+                sens=-1;
+                ENA=1;
+                ENB=1;
+                Nb_pas--;
+                Nb_pas=0;
+                }
             else if (strcmp(command,"contact")==0){
                 sens=0;                     // si j'ai reçu "contact" désactivation du L298 et position = 0
                 ENA=0;
@@ -115,6 +126,16 @@
                 consigne_position=atoi(command);
                 
                 }
+            else if (Nb_pas<=0){
+                sens=0;
+                ENA=0;
+                ENB=0;
+                }
+            else if (position_mesuree<=0){
+                sens=0;
+                ENA=0;
+                ENB=0;
+                }
             }     
         // on traite la commande du moteur   
         if (flag_timer_etat==1)
@@ -191,6 +212,12 @@
                 ENB=0;
                 flag_fc_haut=0;
                 }
+    if (flag_retour==1){
+                sens=-1;
+                ENA=1;
+                ENB=1;
+                flag_retour=0;
+                }
     if (flag_contact==1){       // si j'ai un appui sur BP contact : désactivation du L298 et envoi de la position
                 sens=0;                     // si j'ai reçu "contact" désactivation du L298 et position = 0
                 ENA=0;
@@ -210,7 +237,8 @@
                 /***********************************************************************************************************/
                 // en mode test sur système avec capteur de position 
                 position_mesuree=Nb_pas*0.0125;
-                printf("Npas : %d , Vpos : %f , Position mesuree : %f \n", Nb_pas,Vpos,position_mesuree);                              
+                printf("Npas : %d , Vpos : %f , Position mesuree : %f mm \n", Nb_pas,Vpos,position_mesuree);  
+                flag_contact=0;                            
                 }
     if (flag_timer_reglage_vitesse==1){
                 Vpot=ain0.read(); // Vpot varie de 0 à 100% (0 à 1) en fonction du réglage vitesse
@@ -220,4 +248,4 @@
                 flag_timer_reglage_vitesse=0;
                 }
     }
-}
\ No newline at end of file
+}