sebastian martinez / Mbed 2 deprecated Movimiento_8Servos

Dependencies:   mbed

Fork of 01-04_Primer_Avance by sebastian martinez

Files at this revision

API Documentation at this revision

Comitter:
sebasmartinez
Date:
Sat Oct 06 17:45:42 2018 +0000
Parent:
4:ba51736778e1
Commit message:
Programa Movimiento 1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h 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
mover.cpp Show annotated file Show diff for this revision Revisions of this file
mover.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Sep 07 23:58:14 2018 +0000
+++ b/main.cpp	Sat Oct 06 17:45:42 2018 +0000
@@ -1,22 +1,17 @@
 #include "mbed.h"
-
 #include "main.h"
-
 #define MEM_SIZE 5
 #define MEM_TYPE char
 MEM_TYPE buffer[MEM_SIZE];
-
+Serial command(USBTX, USBRX); // Usar Serial PC USB
+//Serial command(PC_10,PC_11); //Tx, RX. Usar Bluetooth HC-06.
 
-Serial command(USBTX, USBRX);
 DigitalIn button(USER_BUTTON);
 
-
 int main() {
     init_servo();
     init_serial();
     debug_m("inicio \n");
-    
-    
     uint32_t read_cc;
     while(1)
     {
@@ -35,6 +30,19 @@
             pares();
             debug_m("Tc 2 Finalizado\n");
             break;
+            case  0x03: 
+            debug_m("Tc 3 Iniciado.. \n");
+            caminar();
+            debug_m("Tc 3 Finalizado\n");
+            break;
+            case  0x05: 
+            debug_m("Tc 5 Centrar Iniciado.. \n");
+            centro(01);
+            centro(02);
+            centro(03);
+            centro(04);
+            debug_m("Tc 5 Centrar Finalizado\n");
+            break;
             default: debug_m("Error de comando. \nSe espera  entre 0x01 - 0x08 \n");break ;      
         }
     }
@@ -52,14 +60,15 @@
 
  inicio:   
   
-    while(buffer[0] != 0xFF ){
+    while(buffer[0] != 0xFF ){ //7B y 7D  son { y }
     
         buffer[0] = command.getc();
         
         debug_m("comando inicio invalido \n");
         }
-        
-        printf("inicio encontrado: %c \n",  buffer[0] ); 
+        debug_m("comando inicio Valido \n");
+        char ini = buffer[0];
+        printf("inicio encontrado: %x \n",  ini); 
         
             buffer[1] = command.getc();
         if (buffer[1] != 0xFF && buffer[1] != 0xFD){     
@@ -92,7 +101,8 @@
           
         //intc=command.getc();
         int tele = buffer[1];
-        printf("Tele siguente: %c \n",  tele ); 
+        char telec = buffer[1];
+        printf("Tele comando: %x \n",  telec ); 
 
 
     return tele;
@@ -111,9 +121,9 @@
     debug_m("se inicia el comado mover..\n");    
     
     char nmotor = buffer[2];
-    printf("Motor: %c \n",  nmotor ); 
+    printf("Motor: %x \n",  nmotor ); 
     char grados = buffer[3];
-    printf("Grados: %c \n",  grados ); 
+    printf("Grados: %x \n",  grados ); 
     //char endc = buffer[4];
     //printf("Cierre: %c \n",  endc ); 
     mover_ser(nmotor,grados); 
@@ -125,17 +135,33 @@
     debug_m("se inicia el comado pares..\n");    
     
     char par = buffer[2];
-    printf("Par: %c \n",  par ); 
+    printf("Par: %x \n",  par ); 
     char dire = buffer[3];
-    printf("Dir: %c \n",  dire ); 
+    printf("Dir: %x \n",  dire ); 
     char endcc = buffer[4];
-    printf("Cierre: %c \n",  endcc ); 
+    printf("Cierre: %x \n",  endcc ); 
     while(button == 0) {
     mover_par(par,dire); 
     }
     centro(par);
     debug_m("fin del comado pares..\n"); 
     }
+    
+void caminar(){
+    debug_m("Caminando..\n");    
+    
+    char par = buffer[2];
+    printf("Par: %x \n",  par ); 
+    char dire = buffer[3];
+    printf("Dir: %x \n",  dire ); 
+    char endcc = buffer[4];
+    printf("Cierre: %x \n",  endcc ); 
+    while(button == 0) {
+    mover_par(par,dire); 
+    }
+    centro(par);
+    debug_m("Stop..\n"); 
+    }
 void debug_m(char *s , ... ){
     #if DEBUG
     command.printf(s);
--- a/main.h	Fri Sep 07 23:58:14 2018 +0000
+++ b/main.h	Sat Oct 06 17:45:42 2018 +0000
@@ -1,19 +1,11 @@
 #ifndef MAIN_H   
 #define MAIN_H  
-
-
 #include "mover.h"
-
-
-
 #define DEBUG 1
-
-
 void debug_m(char *s , ... );
 uint32_t read_command();
 void init_serial();
-
 void moving();
 void pares();
-
+void caminar();
 #endif //  MAIN_H 
\ No newline at end of file
--- a/mbed.bld	Fri Sep 07 23:58:14 2018 +0000
+++ b/mbed.bld	Sat Oct 06 17:45:42 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file
--- a/mover.cpp	Fri Sep 07 23:58:14 2018 +0000
+++ b/mover.cpp	Sat Oct 06 17:45:42 2018 +0000
@@ -1,18 +1,25 @@
-
 #include "mover.h"
 #include "mbed.h"
 #include "math.h"
 
+PwmOut Servo1(PB_14); //ROJO
 
-PwmOut Servo1(PA_1);
-PwmOut Servo2(PB_8);
-PwmOut Servo3(PB_14);
-PwmOut Servo4(PB_15);
-PwmOut Servo5(PA_8);
-PwmOut Servo6(PB_6);
-PwmOut Servo7(PA_9);
-PwmOut Servo8(PA_10);
+PwmOut Servo2(PB_0); //BLANCO
+
+PwmOut Servo3(PA_11); //VERDE
+PwmOut Servo4(PA_8);  //NEGRO
+PwmOut Servo5(PB_6);  //NARANJA
+
+PwmOut Servo6(PB_1);  //CAFE
 
+PwmOut Servo7(PA_10); //AZUL
+
+PwmOut Servo8(PA_6);  //AMARILLO
+
+/*
+PwmOut Servo6(PB_1);  //CAFE
+PwmOut Servo7(PA_7); //AZUL
+PwmOut Servo8(PA_6);  //AMARILLO
 
 uint8_t  ss_time=50;     // tiempo  de espera para moverse 1 mm en microsegundos
 
@@ -20,11 +27,12 @@
     ss_time=vtime;
     
 }
-
+*/
 int coord2us(float coord)
 {
     if(0 <= coord <= MAXPOS)
-        return int(500+coord*2000/180);// u6
+       { return int(500+coord*2000/180);// u6
+        }
     return 500;
 /*
 Secuencia 0, 180, 135, 90, 45, 0.
@@ -99,69 +107,70 @@
             wait(0.5);
           }
     break;
-  case 0x02: 
-     if(dir==0x01){
-            Servo1.pulsewidth_us(ARRIBA);
+    case 0x02: 
+        if(dir==0x01){
+            Servo3.pulsewidth_us(ARRIBA);
             wait(0.5);
-            Servo2.pulsewidth_us(ADELANTE);
+            Servo4.pulsewidth_us(ADELANTE);
             wait(0.5);
-            Servo1.pulsewidth_us(ABAJO);
+            Servo3.pulsewidth_us(ABAJO);
             wait(0.5);
-            Servo2.pulsewidth_us(ATRAS);
+            Servo4.pulsewidth_us(ATRAS);
             wait(0.5);
          }else{
-            Servo1.pulsewidth_us(ARRIBA);
-            wait(0.5);
-            Servo2.pulsewidth_us(ATRAS);
-            wait(0.5);
-            Servo1.pulsewidth_us(ABAJO);
+            Servo3.pulsewidth_us(ARRIBA);
             wait(0.5);
-            Servo2.pulsewidth_us(ADELANTE);
-            wait(0.5);
-          }
-    break;    
-  case 0x03: 
-     if(dir==0x01){
-            Servo1.pulsewidth_us(ARRIBA);
+            Servo4.pulsewidth_us(ATRAS);
             wait(0.5);
-            Servo2.pulsewidth_us(ADELANTE);
-            wait(0.5);
-            Servo1.pulsewidth_us(ABAJO);
-            wait(0.5);
-            Servo2.pulsewidth_us(ATRAS);
+            Servo3.pulsewidth_us(ABAJO);
             wait(0.5);
-         }else{
-            Servo1.pulsewidth_us(ARRIBA);
-            wait(0.5);
-            Servo2.pulsewidth_us(ATRAS);
-            wait(0.5);
-            Servo1.pulsewidth_us(ABAJO);
-            wait(0.5);
-            Servo2.pulsewidth_us(ADELANTE);
+            Servo4.pulsewidth_us(ADELANTE);
             wait(0.5);
           }
     break;
-  case 0x04: 
-     if(dir==0x01){
-            Servo1.pulsewidth_us(ARRIBA);
+    case 0x03: 
+        if(dir==0x01){
+            Servo5.pulsewidth_us(ARRIBA);
             wait(0.5);
-            Servo2.pulsewidth_us(ADELANTE);
+            Servo6.pulsewidth_us(ADELANTE);
             wait(0.5);
-            Servo1.pulsewidth_us(ABAJO);
+            Servo5.pulsewidth_us(ABAJO);
             wait(0.5);
-            Servo2.pulsewidth_us(ATRAS);
+            Servo6.pulsewidth_us(ATRAS);
             wait(0.5);
          }else{
-            Servo1.pulsewidth_us(ARRIBA);
+            Servo5.pulsewidth_us(ARRIBA);
             wait(0.5);
-            Servo2.pulsewidth_us(ATRAS);
+            Servo6.pulsewidth_us(ATRAS);
             wait(0.5);
-            Servo1.pulsewidth_us(ABAJO);
+            Servo5.pulsewidth_us(ABAJO);
             wait(0.5);
-            Servo2.pulsewidth_us(ADELANTE);
+            Servo6.pulsewidth_us(ADELANTE);
             wait(0.5);
           }
     break;
+    case 0x04: 
+        if(dir==0x01){
+            Servo7.pulsewidth_us(ARRIBA);
+            wait(0.5);
+            Servo8.pulsewidth_us(ADELANTE);
+            wait(0.5);
+            Servo7.pulsewidth_us(ABAJO);
+            wait(0.5);
+            Servo8.pulsewidth_us(ATRAS);
+            wait(0.5);
+         }else{
+            Servo7.pulsewidth_us(ARRIBA);
+            wait(0.5);
+            Servo8.pulsewidth_us(ATRAS);
+            wait(0.5);
+            Servo7.pulsewidth_us(ABAJO);
+            wait(0.5);
+            Servo8.pulsewidth_us(ADELANTE);
+            wait(0.5);
+          }
+    break;
+
      default: break;
 }
     }
@@ -205,6 +214,16 @@
    Servo6.period_ms(20);
    Servo7.period_ms(20);
    Servo8.period_ms(20);
-    
+   /*
+   //Posicion inicial a cada servo CENTRO
+   Servo1.pulsewidth_us(CENTRO);
+   Servo2.pulsewidth_us(CENTRO);
+   Servo3.pulsewidth_us(CENTRO);
+   Servo4.pulsewidth_us(CENTRO);
+   Servo5.pulsewidth_us(CENTRO);
+   Servo6.pulsewidth_us(CENTRO);
+   Servo7.pulsewidth_us(CENTRO);
+   Servo8.pulsewidth_us(CENTRO);
+   */
 }
 
--- a/mover.h	Fri Sep 07 23:58:14 2018 +0000
+++ b/mover.h	Sat Oct 06 17:45:42 2018 +0000
@@ -1,16 +1,14 @@
 #ifndef DRAW_H   
-#define DRAW_H  
-
+//#define DRAW_H  
 #include "mbed.h"
-
 #define MAXPOS 180       // en milimetros
-#define POSDRAW 50  
-#define POSNODRAW 10  
+//#define POSDRAW 50  
+//#define POSNODRAW 10  
 #define ARRIBA 1700
-#define CENTRO 1300
-#define ABAJO 900
-#define ADELANTE 500
-#define ATRAS 2500
+#define CENTRO 1500
+#define ABAJO 600
+#define ADELANTE 720
+#define ATRAS 2200
 
 void init_servo();
 void draw();