AresENSEA-CDF2020 / Mbed 2 deprecated AresCDFMainCode

Dependencies:   mbed DRV8825

Files at this revision

API Documentation at this revision

Comitter:
Nanaud
Date:
Wed Jul 08 19:51:28 2020 +0000
Child:
1:2fe8c402ee79
Commit message:
Code principal du projet

Changed in this revision

DRV8825.lib Show annotated file Show diff for this revision Revisions of this file
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
mbed.bld 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DRV8825.lib	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/AresENSEA-CDF2020/code/DRV8825/#41e1779ef9e4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/captUS.cpp	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,28 @@
+#include "pins.h"
+
+void AresUltrasonsInit(){tps.start();}
+
+void AresUltrasons(){
+    tps.reset();
+    trigger=1;
+    wait(0.00002);
+    trigger=0;
+}
+
+void echoRise1(){us_out[0]=tps.read_us();}
+void echoFall1(){us_out[0]=(tps.read_us()-us_out[0])/2;}
+
+void echoRise2(){us_out[1]=tps.read_us();}
+void echoFall2(){us_out[1]=(tps.read_us()-us_out[1])/2;}
+
+void echoRise3(){us_out[2]=tps.read_us();}
+void echoFall3(){us_out[2]=(tps.read_us()-us_out[2])/2;}
+
+void echoRise4(){us_out[3]=tps.read_us();}
+void echoFall4(){us_out[3]=(tps.read_us()-us_out[3])/2;}
+
+void echoRise5(){us_out[4]=tps.read_us();}
+void echoFall5(){us_out[4]=(tps.read_us()-us_out[4])/2;}
+
+void echoRise6(){us_out[5]=tps.read_us();}
+void echoFall6(){us_out[5]=(tps.read_us()-us_out[5])/2;}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/captUS.h	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,17 @@
+
+
+void AresUltrasons();
+void AresUltrasonsInit();
+
+void echoRise1();
+void echoFall1();
+void echoRise2();
+void echoFall2();
+void echoRise3();
+void echoFall3();
+void echoRise4();
+void echoFall4();
+void echoRise5();
+void echoFall5();
+void echoRise6();
+void echoFall6();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeurs.cpp	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,39 @@
+#include "pins.h"
+
+// Rise
+
+void cdgaRise(){
+    if(cdgB) cpt_cdgA++;
+    else cpt_cdgA--;
+}
+
+void cdgbRise(){
+    if(cdgA) cpt_cdgB--;
+    else cpt_cdgB++;    
+}
+
+void cddaRise(){
+    
+}
+
+void cddbRise(){
+    
+}
+
+// Fall
+
+void cdgaall(){
+
+}
+
+void cdgball(){
+    
+}
+
+void cddaall(){
+    
+}
+
+void cddball(){
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codeurs.h	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,4 @@
+
+
+void cdgaRise();
+void cdgbRise();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.cpp	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,137 @@
+#include "pins.h"
+
+void serialIT(){
+    //pc.printf("\n\rserialIT on\n\r");
+    static int i=0;
+    static char buffer[10]=""; // Tableau qui contient la chaine de caractère rentrée dans le terminal.
+    static char cmd[Lcmd]=""; // Variable qui retient que les premiers caractères qui représentent la commande.
+    char tampon = pc.getc();
+    
+    if((tampon >= 48 && tampon <=57) || (tampon>=97 && tampon<=122) || tampon==13)
+    {
+        buffer[i]=tampon; // Ajout du caractère dans le tableau buffer
+        pc.putc(buffer[i]); // Réécriture sur le terminal du caractère envoyé
+        i++;
+    }
+
+    if(buffer[i-1]=='\r'){ // Attente un appui sur la touche entrée
+        i=0;
+        copieTab(buffer,cmd); // Sauvegarde la commande dans le tableau cmd
+        cmdChoice(cmd); 
+    }  
+}
+
+void copieTab(char *tab1,char *tab2){ // Fonction qui recopie un tableau dans un autre
+    //pc.printf("\n\rcopieTab on\n\r");
+    //pc.printf("\n\r");
+    for(int j=0;j<Lcmd;j++){
+        tab2[j]=tab1[j];
+        //pc.printf("%c",tab2[j]);
+    }
+    //pc.printf("\n\r");
+}
+
+void cmdChoice(char *cmd){ // Fonction qui permet de choisir de l'activation d'une commande
+    //pc.printf("\n\rcmdChoice on\n\rcmd =");
+    
+    const char *options[]={
+    "help", //0
+    "usao", //1
+    "us1o", //2
+    "us2o", //3
+    "us3o", //4
+    "us4o", //5
+    "us5o", //6
+    "us6o", //7
+    "tdrv", //8
+    "cdon", //9
+    "cdga", //10
+    "cdgb", //11
+    0
+    };
+    
+    long option=-1;
+    
+    for (long a=0; options[a] && option<0; a++){
+        if (!strcmp(cmd,options[a]) || strcmp(cmd,options[a])==1){ // strcmp(cmd,options[a])==1 permet de contourner le problème, à revoir !!!
+            option=a;
+        }
+        //pc.printf("res = %d",strcmp(cmd,options[a]));
+    }
+            
+    switch (option) {
+        case 0:     //help
+            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("cdon : Affichage resultats codeurs\n\r");
+            pc.printf("cdgx : Affichage resultats codeur gauche phase x (a ou b)\n\r");
+            pc.printf("\n\r");
+            break;
+        case 1:     //usao
+            pc.printf("Capt US ALL ON/OFF\n\r");
+            aff_US[0]=!aff_US[0];aff_US[1]=!aff_US[1];aff_US[2]=!aff_US[2];
+            aff_US[3]=!aff_US[3];aff_US[4]=!aff_US[4];aff_US[5]=!aff_US[5];
+            break;
+        case 2:     //us1o
+            pc.printf("Capt US 1 ON/OFF\n\r");
+            aff_US[0]=!aff_US[0];
+            break;
+        case 3:     //us2o
+            pc.printf("Capt US 2 ON/OFF\n\r");
+            aff_US[1]=!aff_US[1];
+            break;
+        case 4:     //us3o
+            pc.printf("Capt US 3 ON/OFF\n\r");
+            aff_US[2]=!aff_US[2];
+            break;
+        case 5:     //us4o
+            pc.printf("Capt US 4 ON/OFF\n\r");
+            aff_US[3]=!aff_US[3];
+            break;
+        case 6:     //us5o
+            pc.printf("Capt US 5 ON/OFF\n\r");
+            aff_US[4]=!aff_US[4];
+            break;
+        case 7:     //us6o
+            pc.printf("Capt US 6 ON/OFF\n\r");
+            aff_US[5]=!aff_US[5];
+            break;
+        case 8:     //tdrv
+            pc.printf("Fonction test_drv()\n\r");
+            test_drv();
+            break;
+        case 9:     //cdon
+            pc.printf("Results ALL Encoders ON/OFF\n\r");
+            aff_cd[0]=!aff_cd[0];
+            aff_cd[1]=!aff_cd[1];
+            break;
+        case 10:    //cdga
+            pc.printf("Results Encoder Left A ON/OFF\n\r");
+            aff_cd[0]=!aff_cd[0];
+            break;
+        case 11:    //cdgb
+            pc.printf("Results Encoder Left B ON/OFF\n\r");
+            aff_cd[1]=!aff_cd[1];
+            break;
+        default:
+            pc.printf("Commande invalide\n\r");
+    }
+}
+
+void affUltrasons(){
+    if(aff_US[0]) printf("Tps US1 = %5.0f uS\n\r", us_out[0]); 
+    if(aff_US[1]) printf("Tps US2 = %5.0f uS\n\r", us_out[1]); 
+    if(aff_US[2]) printf("Tps US3 = %5.0f uS\n\r", us_out[2]); 
+    if(aff_US[3]) printf("Tps US4 = %5.0f uS\n\r", us_out[3]); 
+    if(aff_US[4]) printf("Tps US5 = %5.0f uS\n\r", us_out[4]); 
+    if(aff_US[5]) printf("Tps US6 = %5.0f uS\n\r", us_out[5]);
+    if(aff_US[0]||aff_US[1]||aff_US[2]||aff_US[3]||aff_US[4]||aff_US[5]) printf("\n\r"); 
+}
+
+void affCodeurs(){
+    if(aff_cd[0]) printf("CdgA = %d\n\r", cpt_cdgA);   
+    if(aff_cd[1]) printf("CdgB = %d\n\r", cpt_cdgB); 
+}    
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debug.h	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,7 @@
+
+
+void serialIT();
+void copieTab(char *tab1,char *tab2);
+void cmdChoice(char *cmd);
+void affUltrasons();
+void affCodeurs();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,36 @@
+#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
+    echo1.rise(&echoRise1);
+    echo1.fall(&echoFall1);
+    echo2.rise(&echoRise2);
+    echo2.fall(&echoFall2);
+    echo3.rise(&echoRise3);
+    echo3.fall(&echoFall3);
+    echo4.rise(&echoRise4);
+    echo4.fall(&echoFall4);
+    echo5.rise(&echoRise5);
+    echo5.fall(&echoFall5);
+    echo6.rise(&echoRise6);
+    echo6.fall(&echoFall6);
+    
+    drv_init();
+
+    ticker_affcd.attach(&affCodeurs,1.0); // On apelle cette fonction toutes les secondes
+    cdgA.rise(&cdgaRise);
+    cdgB.rise(&cdgbRise);
+    cdgA.mode(PullUp);
+    cdgB.mode(PullUp);
+    
+    aff_cd[0]=!aff_cd[0];
+    aff_cd[1]=!aff_cd[1];
+    
+    while(1) {
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motors.cpp	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,44 @@
+#include "pins.h"
+
+void drv_init(){
+    mot_dis();
+}
+
+void test_drv(){
+    mot_en();
+    motGauche_fwd();
+    drvGauche.move(1);  
+    wait(2);
+    motGauche_bck();
+    wait(2);
+    mot_dis();
+}
+
+// ENABLE/DISABLE // Les deux modules ont le même enable
+void mot_en(){
+    drvGauche.setEnable(START);
+    //drvDroite.setEnable(START);
+}
+
+void mot_dis(){
+    drvGauche.setEnable(STOP);
+    //drvDroite.setEnable(STOP);
+}
+
+// FORWARD
+void motGauche_fwd(){
+    drvGauche.setDir(FORWARD);
+}
+
+void motDroite_fwd(){
+    drvDroite.setDir(FORWARD);
+}
+
+// BACKWARD
+void motGauche_bck(){
+    drvGauche.setDir(BACKWARD);
+}
+
+void motDroite_bck(){
+    drvDroite.setDir(BACKWARD);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motors.h	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,11 @@
+
+
+void drv_init();
+void test_drv();
+
+void mot_en();
+void mot_dis();
+void motGauche_fwd();
+void motDroite_fwd();
+void motGauche_bck();
+void motDroite_bck();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pins.cpp	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,44 @@
+#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);
+InterruptIn echo3(PB_2);
+InterruptIn echo4(PB_1);
+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
+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);
+InterruptIn cdgB(PA_9);
+long cpt_cddA=0;
+long cpt_cddB=0;
+InterruptIn cddA(PA_0);
+InterruptIn cddB(PA_1);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pins.h	Wed Jul 08 19:51:28 2020 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "DRV8825.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];
+
+//Capteurs à ultrasons
+extern float us_out[6];
+extern Timer tps;
+extern Ticker ticker_US;
+extern DigitalOut trigger;
+extern InterruptIn echo1;
+extern InterruptIn echo2;
+extern InterruptIn echo3;
+extern InterruptIn echo4;
+extern InterruptIn echo5;
+extern InterruptIn echo6;
+
+// Drivers DRV8825 
+extern BusOut MODE;
+extern DRV8825 drvGauche; 
+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