Llibreria per fer servir un HC-06 o HC-05 en mode esclau. És compatible amb les llibreries RTOS de mbed.

Dependents:   projecte_v4_rtos ProjecteRobotFinal

Files at this revision

API Documentation at this revision

Comitter:
jcabello7
Date:
Wed Dec 23 15:04:55 2015 +0000
Parent:
2:298c9cc5af48
Child:
4:de2112ca0735
Commit message:
Millorada l'estructura de la llibreria (ara cedeix el control del c?lcul dels motors al programa principal)

Changed in this revision

Hc05.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Hc05.cpp	Mon Dec 21 19:04:55 2015 +0000
+++ b/Hc05.cpp	Wed Dec 23 15:04:55 2015 +0000
@@ -70,13 +70,18 @@
         void Hc05::tractaString(){
             if ((strLlegit[0] == 'a') && (strLlegit[1] == 'v') && (strLlegit[2] == 'a') && (strLlegit[3] == 'n'))
                 mode = 1;
-            if ((strLlegit[0] == 'r') && (strLlegit[1] == 'o') && (strLlegit[2] == 't') && (strLlegit[3] == 'a'))
+            else if ((strLlegit[0] == 'r') && (strLlegit[1] == 'o') && (strLlegit[2] == 't') && (strLlegit[3] == 'a'))
                 mode = 2;
-            if ((strLlegit[0] == 's') && (strLlegit[1] == 't') && (strLlegit[2] == 'o') && (strLlegit[3] == 'p')){
+            else if ((strLlegit[0] == 'm') && (strLlegit[1] == 'o') && (strLlegit[2] == 'd') && (strLlegit[3] == 'e') && (strLlegit[5] == 'a') && (strLlegit[6] == 'u') && (strLlegit[7] == 't') && (strLlegit[8] == 'o'))
+                mode = 3;
+            else if ((strLlegit[0] == 'm') && (strLlegit[1] == 'o') && (strLlegit[2] == 'd') && (strLlegit[3] == 'e') && (strLlegit[5] == 'm') && (strLlegit[6] == 'a') && (strLlegit[7] == 'n') && (strLlegit[8] == 'u'))
+                mode = 4;
+            else if ((strLlegit[0] == 's') && (strLlegit[1] == 't') && (strLlegit[2] == 'o') && (strLlegit[3] == 'p')){
                 mode = 0;
                 vel = 0;
                 ang = 0;
             }
+            else ;
             if ((mode == 1) || (mode==2)){
                 char svel[5], sang[5];
                 for(int i = 0; i<=4;i++){
@@ -87,24 +92,9 @@
                 vel = atoi(svel);
                 ang = atoi(sang);
             }
-            if ((strLlegit[0] == 'm') && (strLlegit[1] == 'o') && (strLlegit[2] == 'd') && (strLlegit[3] == 'e') && (strLlegit[5] == 'a') && (strLlegit[6] == 'u') && (strLlegit[7] == 't') && (strLlegit[8] == 'o'))
-                mode = 3;
-            calculaMotors();
-            char cDireccio[3];
-            if (m1<0)
-                cDireccio[0]='B';
-            else cDireccio[0]='F';
-            if (m2<0)
-                cDireccio[1]='B';
-            else cDireccio[1]='F';
-            if (m3<0)
-                cDireccio[2]='B';
-            else cDireccio[2]='F';
+            //Calcul dels motors
+            //calculaMotors();
             
-            snprintf(strM1, longString, "V%.3i%cM1", abs(m1), cDireccio[0]);
-            snprintf(strM2, longString, "V%.3i%cM2", abs(m2), cDireccio[1]);
-            snprintf(strM3, longString, "V%.3i%cM3", abs(m3), cDireccio[2]);
-            snprintf(strPos, longString, "X=%g   Y=%g", x, y);
         };
         
         int Hc05::getMode(){return mode;};
@@ -130,7 +120,7 @@
         
         //Calculs motors
         void Hc05::calculaMotors(){
-            if(mode==1){
+            if(mode==1){ //Falta afegir una condició perquè no deixi avançar en determinada direcció si detecta els ultrasons
                 x = cos(ang*pi/180);
                 y = sin(ang*pi/180);
                 m1 = (-y)*vel;
@@ -147,6 +137,22 @@
             else {
                 m1 = m2 = m3 = x = y = 0;
             }
+            //Omple els strings per enviar a l'arduino
+            char cDireccio[3];
+            if (m1<0)
+                cDireccio[0]='B';
+            else cDireccio[0]='F';
+            if (m2<0)
+                cDireccio[1]='B';
+            else cDireccio[1]='F';
+            if (m3<0)
+                cDireccio[2]='B';
+            else cDireccio[2]='F';
+            
+            snprintf(strM1, longString, "V%.3i%cM1", abs(m1), cDireccio[0]);
+            snprintf(strM2, longString, "V%.3i%cM2", abs(m2), cDireccio[1]);
+            snprintf(strM3, longString, "V%.3i%cM3", abs(m3), cDireccio[2]);
+            snprintf(strPos, longString, "X=%g   Y=%g", x, y);
         };
         
         void Hc05::getStringM1(char* str){