Test

Dependencies:   mbed DRV8825

Revision:
22:f891c2bce091
Parent:
21:e5f0f5abb5ae
--- a/main.cpp	Sun Oct 25 22:36:51 2020 +0000
+++ b/main.cpp	Tue Oct 27 17:27:33 2020 +0000
@@ -1,87 +1,53 @@
-// Nom du fichier : main.cpp
+/* Équipe : Ares ENSEA
+ *  Coupe de France de robotique 2020
+ */
+
+
+/* #include */
 #include "pins.h"
 
-//#define TPS_DRAPEAU 20 // 95
-//#define TPS_FIN 100
-
-Ticker TimerGlobal;
-int cptGlobal = 0;
-
-bool Match = 0;
-DigitalOut led(LED1);
-DigitalIn tirette(PC_8);
-
-void btnFct()
-{
-    mot_dis();
-    aff_cd[0] = 0;
-    aff_cd[1] = 0;
-
-    pc.printf("comptG = %d\r\n",comptG);
-    pc.printf("comptD = %d\r\n",comptD);
-    bt.printf("comptG = %d\r\n",comptG);
-    bt.printf("comptD = %d\r\n",comptD);
-}
 
-void fctCptGlobal()
-{
-    cptGlobal++;
-    
-    if(cptGlobal==5) { //95
-        FlagGOTO(0);
-    }
-    
-    if(cptGlobal>=100) {
-        fnc=0;
-    }
-}
+/* Variables globales */
+Ticker TickerGlobal; // Comptage du temps écoulé
+int cptGlobal = 0;
+bool match = 0; // Match == 1 => Le match est en cours
 
-/*
-void cordonDem()
-{
-    indice++;
-    fnc = objEtape[indice];
-    xC = objX[indice];
-    yC = objY[indice];
-    mot_en();
-    myled = 0;
-}
-*/
+
+/* Prototypes */
+void btnBlueIT();
+void globalCounterIT();
 
 
 int main()
 {
-    //captUS_init();
-    tps.start();
-    FlagGOTO(90);
-    TimerGlobal.attach(&fctCptGlobal, 1.0);
-    
-    tirette.mode(PullDown);
-    //myled = 1;
+    pc.printf("\r\nAresCDF2020\r\n");
+    bt.printf("\r\nAresCDF2020\r\n");
+
+    /* Initialisation des drivers */
+    drv_init();
 
-    pc.printf("\r\nAresCDFMainCode\r\n");
-    bt.printf("\r\nAresCDFMainCode\r\n");
-
-    btn.rise(&btnFct);
+    /* Initialisation des codeurs */
+    cdgA.rise(&cdgaRise);
+    cddA.rise(&cddaRise);
+    cdgA.mode(PullUp);
+    cddA.mode(PullUp);
 
-    // debug
-    pc.attach(&serialIT); // Interruption liaison série
-    bt.attach(&bluetoothIT); // Interruption  bluetooth
-    pc.baud(9600);
-    pc.format(8,SerialBase::None,1);
-    bt.baud(9600);
-    bt.format(8,SerialBase::None,1);
+    /* Initialisation des broches */
+    Tirette.mode(PullDown);
+
+    /* Initialisation des pavillons */
+    FlagGOTO(90);
 
-    ticker_US.attach(&captUS_trig,0.1); // 0.2
-    //ticker_affUS.attach(&affUltrasons,1.0);
-    //ticker_affcd.attach(&affCodeurs,1.0);
-    //ticker_odo.attach(&odo2,0.02);
-    ticker_asserv.attach(&asserv,0.015);
-    //ticker_affodo.attach(&affOdo,1.0);
+    /* Timers & tickers */
+    TickerGlobal.attach(&globalCounterIT, 1.0);
+    TimUS.start();
 
-    // Init capteurs à ultrasons
-    //captUS_init();
-    echo1.rise(&echoRise1);
+    TickUS_actu.attach(&captUS_trig,0.2);
+    Ticker_asserv.attach(&asserv,0.015);
+    //Ticker_affUS.attach(&affUltrasons,1.0);
+
+    /* Initialisation des capteurs à ultrasons */
+    echo1.rise(&echoRise1); // Interruptions pour les capteurs à ultrasons
     echo1.fall(&echoFall1);
     echo2.rise(&echoRise2);
     echo2.fall(&echoFall2);
@@ -94,37 +60,61 @@
     echo6.rise(&echoRise6);
     echo6.fall(&echoFall6);
 
-    // Init DRV8825
-    drv_init();
+    /* debug */
+    pc.attach(&serialIT); // Interruption liaison série
+    bt.attach(&bluetoothIT); // Interruption bluetooth
+    pc.baud(9600);
+    pc.format(8,SerialBase::None,1);
+    bt.baud(9600);
+    bt.format(8,SerialBase::None,1);
 
-    // Init codeurs
-    cdgA.rise(&cdgaRise);
-    cddA.rise(&cddaRise);
-    cdgA.mode(PullUp);
-    cddA.mode(PullUp);
+    /* Autres */
+    //btnBlue.rise(&boutonBleu);
 
+    /* Boucle infinie */
     while(1) {
-        if (tirette == 1 && Match == 0) {
-            Match = 0;
-            led = 1;
-        } else if (tirette == 0 && Match == 0){
-            Match = 1;
+        if (Tirette == 1 && match == 0) { // Stand-by
+            // Le match n'a pas encore commencé
+            // La LED est allumée
+            // Le compteur du match reste à 0
+            Led = 1;
+            match = 0;
+            cptGlobal=0;
+        }
+
+        else if (Tirette == 0 && match == 0) { // Début du match
+            // Le match débute
+            // La LED s'éteind
+            Led = 0;
+            match = 1;
+            cptGlobal = 0;
             
-            led = 0;
-
-            //indice++;
-            indice=1;
+            indice= 1;
             fnc = objEtape[indice];
             xC = objX[indice];
             yC = objY[indice];
-            cptGlobal = 0;
-            //mot_en();
         }
 
         if (indice>=NbObj) {
             fnc = 0;
-            //mot_dis();
         }
-
     }
 }
+
+void btnBlueIT()
+{
+    /* Rien */
+}
+
+void globalCounterIT()
+{
+    cptGlobal++;
+
+    if(cptGlobal==95) { // Le drapeau doit être hissé à 95sec
+        FlagGOTO(0);
+    }
+
+    if(cptGlobal>=100) { // Le robot doit s'arrêter à 100sec
+        fnc=0;
+    }
+}