Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:ad9b7355332e, committed 2020-07-18
- Comitter:
- Nanaud
- Date:
- Sat Jul 18 17:09:08 2020 +0000
- Parent:
- 3:3ba377aafdfd
- Child:
- 5:34ed652f8c31
- Commit message:
- Ajout du debug en Bluetooth (Module HC-05)
Changed in this revision
--- a/debug.cpp Wed Jul 15 17:51:04 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,184 +0,0 @@
-// 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];
-int cmdType=0;
-
-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
-
- switch(cmdType) {
- case 1 : // Commande test angle
- StringToAngle(cmd);
- cmdType=0;
- break;
- default : // Commande par défaut
- 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
- "tagl", //12
- 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("tagl : Tourne le robot sur lui-meme avec un angle a preciser\r\n");
- 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;
- case 12: //tagl
- pc.printf("Cmd Angle robot\r\n");
- pc.printf("Angle (entre 0 et 360 degres sous la forme xxx): ");
- cmdType=1;
- break;
- default:
- pc.printf("Commande invalide\n\r");
- }
-}
-
-void StringToAngle(char *cmd)
-{
- int cmd2 = 0;
- cmd2 += (cmd[0]-48)*100;
- cmd2 += (cmd[1]-48)*10;
- cmd2 += (cmd[2]-48)*1;
-
- if (cmd2>=0 && cmd2<=360) {
- pc.printf("\r\nCommande envoyee au robot : %d\r\n",cmd2);
- testAngle(cmd2);
- } else {
- pc.printf("\r\nAngle incorrect\r\n\n");
- cmd2 = 0;
- }
-}
-
-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);
-}
--- a/debug.h Wed Jul 15 17:51:04 2020 +0000 +++ b/debug.h Sat Jul 18 17:09:08 2020 +0000 @@ -1,20 +1,23 @@ -// Nom du fichier : debug.h +// Nom du fichier : debugPC.h // #define #define Lcmd 4 // Longueurs des commandes pour le debug // extern extern Serial pc; +extern Serial bt; extern Ticker ticker_affUS; extern Ticker ticker_affcd; extern bool aff_US[6]; extern bool aff_cd[4]; +extern int cmdType; // Prototypes void serialIT(); +void bluetoothIT(); void copieTab(char *tab1,char *tab2); void cmdChoice(char *cmd); void StringToAngle(char *cmd); void affUltrasons(); -void affCodeurs(); \ No newline at end of file +void affCodeurs();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/debugBT.cpp Sat Jul 18 17:09:08 2020 +0000
@@ -0,0 +1,38 @@
+// Nom du fichier : debugBT.cpp
+#include "pins.h"
+
+// Variables globales & timers
+Serial bt(PC_6,PC_7);
+
+void bluetoothIT()
+{
+ 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.
+
+ //printf("bt.readable = %d \r\n",bt.readable());
+ while(bt.readable()) { // if(bt.readable())
+ //pc.printf("bt.readable = %d \r\n",bt.readable());
+ buffer[i]=bt.getc();
+ pc.printf("%c",buffer[i]);
+ bt.printf("%c",buffer[i]);
+ i++;
+ }
+
+ if(buffer[i-1]=='\r') {
+ pc.printf("\r\n");
+ bt.printf("\r\n");
+ i=0;
+
+ copieTab(buffer,cmd);
+
+ switch(cmdType) {
+ case 1 : // Commande test angle
+ StringToAngle(cmd);
+ cmdType=0;
+ break;
+ default : // Commande par défaut
+ cmdChoice(cmd);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/debugPC.cpp Sat Jul 18 17:09:08 2020 +0000
@@ -0,0 +1,222 @@
+// Nom du fichier : debugPC.cpp
+#include "pins.h"
+
+// Variables globales & timers
+Serial pc(USBTX, USBRX);
+Ticker ticker_affUS;
+Ticker ticker_affcd;
+bool aff_US[6];
+bool aff_cd[4];
+int cmdType=0;
+
+void serialIT() // avec Tera Term
+{
+ //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
+
+ switch(cmdType) {
+ case 1 : // Commande test angle
+ StringToAngle(cmd);
+ cmdType=0;
+ break;
+ default : // Commande par défaut
+ 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
+{
+ 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
+ "tagl", //12
+ 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\r\n",strcmp(cmd,options[a]));
+ }
+
+ switch (option) {
+ case 0: //help
+ // pc
+ 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("tagl : Tourne le robot sur lui-meme avec un angle a preciser\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("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");
+ bt.printf("\n\r");
+ break;
+ case 1: //usao
+ pc.printf("Capt US ALL ON/OFF\n\r");
+ bt.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");
+ bt.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");
+ bt.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");
+ bt.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");
+ bt.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");
+ bt.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");
+ bt.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");
+ bt.printf("Fonction test_drv()\n\r");
+ test_drv();
+ break;
+ case 9: //cdon
+ pc.printf("Results ALL Encoders ON/OFF\n\r");
+ bt.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");
+ bt.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");
+ bt.printf("Results Encoder Left B ON/OFF\n\r");
+ aff_cd[1]=!aff_cd[1];
+ break;
+ case 12: //tagl
+ pc.printf("Cmd Angle robot\r\n");
+ pc.printf("Angle (entre 0 et 360 degres sous la forme xxx): ");
+ bt.printf("Cmd Angle robot\r\n");
+ bt.printf("Angle (entre 0 et 360 degres sous la forme xxx): ");
+ cmdType=1;
+ break;
+ default:
+ pc.printf("Commande invalide\n\r");
+ bt.printf("Commande invalide\n\r");
+ }
+}
+
+void StringToAngle(char *cmd)
+{
+ int cmd2 = 0;
+ cmd2 += (cmd[0]-48)*100;
+ cmd2 += (cmd[1]-48)*10;
+ 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);
+ } else {
+ pc.printf("\r\nAngle incorrect\r\n\n");
+ bt.printf("\r\nAngle incorrect\r\n\n");
+ cmd2 = 0;
+ }
+}
+
+void affUltrasons()
+{
+ // pc
+ if(aff_US[0]) pc.printf("Tps US1 = %5.0f uS\n\r", us_out[0]);
+ if(aff_US[1]) pc.printf("Tps US2 = %5.0f uS\n\r", us_out[1]);
+ if(aff_US[2]) pc.printf("Tps US3 = %5.0f uS\n\r", us_out[2]);
+ if(aff_US[3]) pc.printf("Tps US4 = %5.0f uS\n\r", us_out[3]);
+ if(aff_US[4]) pc.printf("Tps US5 = %5.0f uS\n\r", us_out[4]);
+ if(aff_US[5]) pc.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]) pc.printf("\n\r");
+
+ // bt
+ if(aff_US[0]) bt.printf("Tps US1 = %5.0f uS\n\r", us_out[0]);
+ if(aff_US[1]) bt.printf("Tps US2 = %5.0f uS\n\r", us_out[1]);
+ if(aff_US[2]) bt.printf("Tps US3 = %5.0f uS\n\r", us_out[2]);
+ if(aff_US[3]) bt.printf("Tps US4 = %5.0f uS\n\r", us_out[3]);
+ if(aff_US[4]) bt.printf("Tps US5 = %5.0f uS\n\r", us_out[4]);
+ if(aff_US[5]) bt.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]) bt.printf("\n\r");
+}
+
+void affCodeurs()
+{
+ if(aff_cd[0]) pc.printf("CdgA = %d\n\r", cpt_cdgA);
+ //if(aff_cd[1]) pc.printf("CdgB = %d\n\r", cpt_cdgB);
+
+ if(aff_cd[0]) bt.printf("CdgA = %d\n\r", cpt_cdgA);
+ //if(aff_cd[1]) bt.printf("CdgB = %d\n\r", cpt_cdgB);
+}
--- a/main.cpp Wed Jul 15 17:51:04 2020 +0000
+++ b/main.cpp Sat Jul 18 17:09:08 2020 +0000
@@ -1,12 +1,15 @@
// Nom du fichier : main.cpp
#include "pins.h"
-int main() {
+int main()
+{
pc.printf("\r\nAresCDFMainCode\r\n");
-
+ bt.printf("\r\nAresCDFMainCode\r\n");
+
// debug
pc.attach(&serialIT); // Interruption liaison série
-
+ bt.attach(&bluetoothIT); // Interruption bluetooth
+
// Init capteurs à ultrasons
captUS_init();
echo1.rise(&echoRise1);
@@ -21,21 +24,28 @@
echo5.fall(&echoFall5);
echo6.rise(&echoRise6);
echo6.fall(&echoFall6);
-
+
// Init DRV8825
drv_init();
-
- // Init codeurs
+
+ // 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];
-
+
+ //test_drv();
+
+ pc.baud(9600);
+ pc.format(8,SerialBase::None,1);
+ bt.baud(9600);
+ bt.format(8,SerialBase::None,1);
+
while(1) {}
}
--- a/motors.cpp Wed Jul 15 17:51:04 2020 +0000
+++ b/motors.cpp Sat Jul 18 17:09:08 2020 +0000
@@ -3,6 +3,8 @@
void drv_init(){
mot_dis();
+ //mot_en();
+ mode = 0b111; // M0, M1 et M2 sont à 1
}
// ENABLE/DISABLE // Les deux modules ont le même enable
@@ -22,7 +24,7 @@
}
void motDroite_fwd(){
- drvDroite.setDir(FORWARD);
+ drvDroite.setDir(BACKWARD);
}
// BACKWARD
@@ -31,7 +33,7 @@
}
void motDroite_bck(){
- drvDroite.setDir(BACKWARD);
+ drvDroite.setDir(FORWARD);
}
// TESTS
@@ -39,9 +41,12 @@
void test_drv(){
mot_en();
motGauche_fwd();
- drvGauche.moveLinSpeed(1);
+ motDroite_fwd();
+ drvGauche.moveLinSpeed(0.035);
+ drvDroite.moveLinSpeed(0.035);
wait(2);
motGauche_bck();
+ motDroite_bck();
wait(2);
mot_dis();
}
--- a/pins.cpp Wed Jul 15 17:51:04 2020 +0000 +++ b/pins.cpp Sat Jul 18 17:09:08 2020 +0000 @@ -16,9 +16,11 @@ #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); +#define rRoue 70 // peut être 71 mm +#define nbPas 1000 +BusOut mode(PB_0, PC_1, PC_0); // LSB ... MSB +DRV8825 drvGauche(EN,DIR1,STEP1,rRoue,nbPas); +DRV8825 drvDroite(EN,DIR2,STEP2,rRoue,nbPas); // Codeurs (Réf : LPJ3806-1000BM-G5-24E) InterruptIn cdgA(PA_8); // Codeur de gauche
--- a/pins.h Wed Jul 15 17:51:04 2020 +0000 +++ b/pins.h Sat Jul 18 17:09:08 2020 +0000 @@ -20,7 +20,7 @@ extern InterruptIn echo6; // Drivers DRV8825 -extern BusOut MODE; +extern BusOut mode; extern DRV8825 drvGauche; extern DRV8825 drvDroite;