AresENSEA-CDF2020 / Mbed 2 deprecated AresCDFMainCode_capteur_US

Dependencies:   mbed DRV8825

Files at this revision

API Documentation at this revision

Comitter:
Nanaud
Date:
Wed Jul 08 20:42:19 2020 +0000
Parent:
0:dc036b67c87c
Child:
2:094c09903a9c
Commit message:
Amelioration de la lisibilite du code

Changed in this revision

captUS.cpp Show annotated file Show diff for this revision Revisions of this file
captUS.h Show annotated file Show diff for this revision Revisions of this file
codeurs.cpp Show annotated file Show diff for this revision Revisions of this file
codeurs.h Show annotated file Show diff for this revision Revisions of this file
debug.cpp Show annotated file Show diff for this revision Revisions of this file
debug.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
motors.cpp Show annotated file Show diff for this revision Revisions of this file
motors.h Show annotated file Show diff for this revision Revisions of this file
pins.cpp Show annotated file Show diff for this revision Revisions of this file
pins.h Show annotated file Show diff for this revision Revisions of this file
--- a/captUS.cpp	Wed Jul 08 19:51:28 2020 +0000
+++ b/captUS.cpp	Wed Jul 08 20:42:19 2020 +0000
@@ -1,8 +1,15 @@
+//Nom du fichier : captUS.cpp
 #include "pins.h"
 
-void AresUltrasonsInit(){tps.start();}
+// Variables globales & timers
+float us_out[6];
+Timer tps;
+Ticker ticker_US;
 
-void AresUltrasons(){
+void captUS_init(){
+    tps.start();}
+
+void captUS_trig(){
     tps.reset();
     trigger=1;
     wait(0.00002);
--- a/captUS.h	Wed Jul 08 19:51:28 2020 +0000
+++ b/captUS.h	Wed Jul 08 20:42:19 2020 +0000
@@ -1,7 +1,13 @@
-
+// Nom du fichier : captUS.h
 
-void AresUltrasons();
-void AresUltrasonsInit();
+// extern
+extern float us_out[6];
+extern Timer tps;
+extern Ticker ticker_US;
+
+// Prototypes
+void captUS_trig();
+void captUS_init();
 
 void echoRise1();
 void echoFall1();
--- a/codeurs.cpp	Wed Jul 08 19:51:28 2020 +0000
+++ b/codeurs.cpp	Wed Jul 08 20:42:19 2020 +0000
@@ -1,6 +1,11 @@
+// Nom du fichier : codeurs.cpp
 #include "pins.h"
 
-// Rise
+// Variables globales
+long cpt_cdgA=0; // Codeur de gauche
+long cpt_cdgB=0;
+long cpt_cddA=0; // Codeur de droite
+long cpt_cddB=0;
 
 void cdgaRise(){
     if(cdgB) cpt_cdgA++;
@@ -18,22 +23,4 @@
 
 void cddbRise(){
     
-}
-
-// Fall
-
-void cdgaall(){
-
-}
-
-void cdgball(){
-    
-}
-
-void cddaall(){
-    
-}
-
-void cddball(){
-    
 }
\ No newline at end of file
--- a/codeurs.h	Wed Jul 08 19:51:28 2020 +0000
+++ b/codeurs.h	Wed Jul 08 20:42:19 2020 +0000
@@ -1,4 +1,11 @@
+// Nom du fichier : codeurs.h
 
+// extern
+extern long cpt_cdgA;
+extern long cpt_cdgB;
+extern long cpt_cddA;
+extern long cpt_cddB;
 
+// Prototypes
 void cdgaRise();
 void cdgbRise();
\ No newline at end of file
--- a/debug.cpp	Wed Jul 08 19:51:28 2020 +0000
+++ b/debug.cpp	Wed Jul 08 20:42:19 2020 +0000
@@ -1,5 +1,13 @@
+// Nom du fichier : debug.cpp
 #include "pins.h"
 
+// Variables globales & timerse
+Serial pc(USBTX, USBRX);
+Ticker ticker_affUS;
+Ticker ticker_affcd;
+bool aff_US[6];
+bool aff_cd[4];
+
 void serialIT(){
     //pc.printf("\n\rserialIT on\n\r");
     static int i=0;
--- a/debug.h	Wed Jul 08 19:51:28 2020 +0000
+++ b/debug.h	Wed Jul 08 20:42:19 2020 +0000
@@ -1,5 +1,16 @@
+// Nom du fichier : debug.h
 
+// #define
+#define Lcmd 4 // Longueurs des commandes pour le debug
 
+// extern
+extern Serial pc;
+extern Ticker ticker_affUS;
+extern Ticker ticker_affcd;
+extern bool aff_US[6];
+extern bool aff_cd[4];
+
+// Prototypes
 void serialIT();
 void copieTab(char *tab1,char *tab2);
 void cmdChoice(char *cmd);
--- a/main.cpp	Wed Jul 08 19:51:28 2020 +0000
+++ b/main.cpp	Wed Jul 08 20:42:19 2020 +0000
@@ -1,11 +1,14 @@
+// Nom du fichier : main.cpp
 #include "pins.h"
 
 int main() {
     pc.printf("\r\nAresCDFMainCode\r\n");
-    pc.attach(&serialIT); // On met une interruption sur la liaison série avec le PC. Cette interruption lance la fonction serialIT.
-    AresUltrasonsInit();
-    ticker_US.attach(&AresUltrasons,0.2); // On apelle cette fonction toutes 0.2 secondes
-    ticker_affUS.attach(&affUltrasons,1.0); // On apelle cette fonction toutes les secondes
+    
+    // debug
+    pc.attach(&serialIT); // Interruption liaison série
+    
+    // Init capteurs à ultrasons
+    captUS_init();
     echo1.rise(&echoRise1);
     echo1.fall(&echoFall1);
     echo2.rise(&echoRise2);
@@ -19,18 +22,21 @@
     echo6.rise(&echoRise6);
     echo6.fall(&echoFall6);
     
+    // Init DRV8825
     drv_init();
-
-    ticker_affcd.attach(&affCodeurs,1.0); // On apelle cette fonction toutes les secondes
+    
+    // Init codeurs 
     cdgA.rise(&cdgaRise);
     cdgB.rise(&cdgbRise);
     cdgA.mode(PullUp);
     cdgB.mode(PullUp);
     
+    // Fonctions d'affichage pour les tests
+    ticker_US.attach(&captUS_trig,0.2); // On apelle cette fonction toutes 0.2 secondes
+    ticker_affUS.attach(&affUltrasons,1.0);
+    ticker_affcd.attach(&affCodeurs,1.0);
     aff_cd[0]=!aff_cd[0];
     aff_cd[1]=!aff_cd[1];
     
-    while(1) {
-
-    }
+    while(1) {}
 }
--- a/motors.cpp	Wed Jul 08 19:51:28 2020 +0000
+++ b/motors.cpp	Wed Jul 08 20:42:19 2020 +0000
@@ -1,3 +1,4 @@
+// Nom du fichier : motors.cpp
 #include "pins.h"
 
 void drv_init(){
--- a/motors.h	Wed Jul 08 19:51:28 2020 +0000
+++ b/motors.h	Wed Jul 08 20:42:19 2020 +0000
@@ -1,5 +1,6 @@
+// Nom du fichier : motors.h
 
-
+// Prototypes
 void drv_init();
 void test_drv();
 
--- a/pins.cpp	Wed Jul 08 19:51:28 2020 +0000
+++ b/pins.cpp	Wed Jul 08 20:42:19 2020 +0000
@@ -1,17 +1,7 @@
+// Nom du fichier : pins.cpp
 #include "pins.h"
 
-// Debug
-Serial pc(USBTX, USBRX);
-Ticker ticker_affUS;
-Ticker ticker_affcd;
-bool aff_US[6];
-bool aff_cd[4];
-
-
 // Capteurs à ultrasons
-float us_out[6];
-Timer tps;
-Ticker ticker_US;
 DigitalOut trigger(PB_9);
 InterruptIn echo1(PA_11);
 InterruptIn echo2(PB_12);
@@ -20,25 +10,18 @@
 InterruptIn echo5(PB_15);
 InterruptIn echo6(PB_14);
 
-
 // Drivers DRV8825 
-            //LSB       //MSB
-BusOut MODE(PB_0, PC_1, PC_0);
 #define STEP1 PA_6
 #define STEP2 PB_6
 #define DIR1 PC_2
 #define DIR2 PH_1
 #define EN PC_3
+BusOut MODE(PB_0, PC_1, PC_0); // LSB ... MSB
 DRV8825 drvGauche(EN,DIR1,STEP1); 
 DRV8825 drvDroite(EN,DIR2,STEP2); 
 
-
-// Codeurs LPJ3806-1000BM-G5-24E
-long cpt_cdgA=0;
-long cpt_cdgB=0;
-InterruptIn cdgA(PA_8);
+// Codeurs (Réf : LPJ3806-1000BM-G5-24E)
+InterruptIn cdgA(PA_8); // Codeur de gauche
 InterruptIn cdgB(PA_9);
-long cpt_cddA=0;
-long cpt_cddB=0;
-InterruptIn cddA(PA_0);
+InterruptIn cddA(PA_0); // Codeur de droite
 InterruptIn cddB(PA_1);
--- a/pins.h	Wed Jul 08 19:51:28 2020 +0000
+++ b/pins.h	Wed Jul 08 20:42:19 2020 +0000
@@ -1,25 +1,14 @@
+// Nom du fichier : pins.h
 #include "mbed.h"
 #include "DRV8825.h"
 
+#include <string.h>   
 #include "debug.h"
 #include "captUS.h"
 #include "motors.h"
-#include "codeurs.h"
-#include <string.h>      
-
-#define Lcmd 4
-
-// Debug
-extern Serial pc;
-extern Ticker ticker_affUS;
-extern Ticker ticker_affcd;
-extern bool aff_US[6];
-extern bool aff_cd[4];
+#include "codeurs.h"   
 
 //Capteurs à ultrasons
-extern float us_out[6];
-extern Timer tps;
-extern Ticker ticker_US;
 extern DigitalOut trigger;
 extern InterruptIn echo1;
 extern InterruptIn echo2;
@@ -34,11 +23,7 @@
 extern DRV8825 drvDroite; 
 
 // Codeurs
-extern long cpt_cdgA;
-extern long cpt_cdgB;
 extern InterruptIn cdgA;
 extern InterruptIn cdgB;
-extern long cpt_cddA;
-extern long cpt_cddB;
 extern InterruptIn cddA;
 extern InterruptIn cddB;
\ No newline at end of file