Capteur_US

Dependencies:   mbed DRV8825

Revision:
10:0714feaaaee1
Parent:
8:eb9bbab312ff
Child:
12:2c312916a621
--- a/debugPC.cpp	Thu Jul 30 19:43:16 2020 +0000
+++ b/debugPC.cpp	Fri Sep 11 10:56:08 2020 +0000
@@ -9,7 +9,9 @@
 bool aff_cd[4];
 bool m_dis = true;    // 0 : START // 1 : STOP
 bool m_avance = false;   // 0 : BACKWARD // 1 : FORWARD
+bool mtrt_sens = false;
 int cmdType=0;
+long comptG_saved = 0, comptD_saved = 0; // Sauvegarde nombre de tics codeurs
 
 void serialIT() // avec Tera Term
 {
@@ -39,6 +41,10 @@
                 StringToVitesse(cmd);
                 cmdType=0;
                 break;
+            case 3 : // Commande distance a parcourir
+                StringToDist(cmd);
+                cmdType=0;
+                break;
             default : // Commande par défaut
                 cmdChoice(cmd);
         }
@@ -76,6 +82,9 @@
         "mtdr", //14
         "mtvt", //15
         "mtrt", //16
+        "cofr", //17
+        "cofa", //18
+        "parc", //19
         0
     };
 
@@ -94,7 +103,7 @@
             pc.printf("\n\n\r###HELP###\n\r");
             pc.printf("usao : Affichage resultats capteurs a ultrasons\n\r");
             pc.printf("usxo : Affichage resultat capteur ultrasons x\n\r");
-            pc.printf("tdrv : Lance la fonction test_drv()\n\r");
+            pc.printf("tdrv : Appelle une fonction test\n\r");
             pc.printf("cdon : Affichage resultats codeurs\n\r");
             pc.printf("cdgx : Affichage resultats codeur gauche phase x (a ou b)\n\r");
             pc.printf("tagl : Tourne le robot sur lui-meme avec un angle a preciser\r\n");
@@ -102,12 +111,15 @@
             pc.printf("mtdr : Changement de de sens de rotation des moteurs\r\n");
             pc.printf("mtvt : Changement de la vitesse de rotation (vitesse a preciser)\r\n");
             pc.printf("mtrt : Sens de rotation des moteurs opposes\r\n");
+            pc.printf("cofr : Enregistrement nb tics et reset\r\n");
+            pc.printf("cofa : Affichage nb tics\r\n");
+            pc.printf("parc : Distance a parcourir\r\n");
             pc.printf("\n\r");
             // bt
             bt.printf("\n\n\r###HELP###\n\r");
             bt.printf("usao : Affichage resultats capteurs a ultrasons\n\r");
             bt.printf("usxo : Affichage resultat capteur ultrasons x\n\r");
-            bt.printf("tdrv : Lance la fonction test_drv()\n\r");
+            bt.printf("tdrv : Appelle une fonction test\n\r");
             bt.printf("cdon : Affichage resultats codeurs\n\r");
             bt.printf("cdgx : Affichage resultats codeur gauche phase x (a ou b)\n\r");
             bt.printf("tagl : Tourne le robot sur lui-meme avec un angle a preciser\r\n");
@@ -115,6 +127,9 @@
             bt.printf("mtdr : Changement de de sens de rotation des moteurs\r\n");
             bt.printf("mtvt : Changement de la vitesse de rotation (vitesse a preciser)\r\n");
             bt.printf("mtrt : Sens de rotation des moteurs opposes\r\n");
+            bt.printf("cofr : Enregistrement nb tics et reset\r\n");
+            bt.printf("cofa : Affichage nb tics\r\n");
+            bt.printf("parc : Distance a parcourir\r\n");
             bt.printf("\n\r");
             break;
         case 1:     //usao
@@ -160,7 +175,10 @@
         case 8:     //tdrv
             pc.printf("Fonction test_drv()\n\r");
             bt.printf("Fonction test_drv()\n\r");
-            test_drv();
+            //test_drv();
+            comptG = 0;
+            comptD = 0;
+            //test1();
             break;
         case 9:     //cdon
             pc.printf("Results ALL Encoders ON/OFF\n\r");
@@ -220,11 +238,35 @@
             bt.printf("Vitesse en mm/s (sous la forme xxxx): ");
             cmdType=2;
             break;
-        case 16:
-            pc.printf("Rotation du robot");
-            bt.printf("Rotation du robot");
-            motGauche_fwd();
-            motDroite_bck();
+        case 16:    // mtrt
+            pc.printf("Rotation du robot - Changement de sens");
+            bt.printf("Rotation du robot - Changement de sens");
+            mtrt_sens = !mtrt_sens;
+            if(mtrt_sens) {
+                motGauche_fwd();
+                motDroite_bck();
+            } else {
+                motGauche_bck();
+                motDroite_fwd();
+            }
+            break;
+        case 17 :
+            comptG_saved = comptG;
+            comptD_saved = comptD;
+            comptG=0;
+            comptD=0;
+            pc.printf("comptG et comptD sauvegardes\r\n");
+            bt.printf("comptG et comptD sauvegardes\r\n");
+            break;
+        case 18 :
+            pc.printf("comptG_saved = %ld\r\n",comptG_saved);
+            pc.printf("comptD_saved = %ld\r\n",comptD_saved);
+            bt.printf("comptG_saved = %ld\r\n",comptG_saved);
+            bt.printf("comptD_saved = %ld\r\n",comptD_saved);
+            break;
+        case 19 : //
+            bt.printf("Distance a parcourir : ");
+            cmdType=3;
             break;
         default:
             pc.printf("Commande invalide\n\r");
@@ -240,9 +282,12 @@
     cmd2 += (cmd[2]-48)*1;
 
     if (cmd2>=0 && cmd2<=360) {
-        pc.printf("\r\nCommande envoyee au robot : %d\r\n",cmd2);
-        bt.printf("\r\nCommande envoyee au robot : %d\r\n",cmd2);
-        testAngle(cmd2);
+        //consigneAngle = cmd2;
+        //bt.printf("\r\nCommande envoyee au robot : %lf\r\n",consigneAngle);
+        comptG=0; // Reset des compteurs
+        comptD=0;
+        //calculIntervalles();
+        //state=1;
     } else {
         pc.printf("\r\nAngle incorrect\r\n\n");
         bt.printf("\r\nAngle incorrect\r\n\n");
@@ -250,6 +295,26 @@
     }
 }
 
+void StringToDist(char *cmd)
+{
+    int cmd4 = 0;
+    cmd4 += (cmd[0]-48)*1000;
+    cmd4 += (cmd[1]-48)*100;
+    cmd4 += (cmd[2]-48)*10;
+    cmd4 += (cmd[3]-48)*1;
+
+    if (cmd4>=0 && cmd4<=9999) {
+        //consigneDistance = cmd4;
+        //pc.printf("\r\nCommande envoyee au robot : %lf\r\n",consigneDistance);
+        //bt.printf("\r\nCommande envoyee au robot : %lf\r\n",consigneDistance);
+
+    } else {
+        pc.printf("\r\nDistance incorrecte\r\n\n");
+        bt.printf("\r\nDistance incorrecte\r\n\n");
+        cmd4 = 0;
+    }
+}
+
 void StringToVitesse(char *cmd)
 {
     for(int y=0; y<Lcmd ; y++) {