sebastian martinez / Mbed 2 deprecated 01-04_Primer_Avance

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

Files at this revision

API Documentation at this revision

Comitter:
sebasmartinez
Date:
Fri Sep 07 23:58:14 2018 +0000
Parent:
3:60722da62531
Commit message:
V3

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
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
diff -r 60722da62531 -r ba51736778e1 main.cpp
--- a/main.cpp	Fri Sep 07 03:42:26 2018 +0000
+++ b/main.cpp	Fri Sep 07 23:58:14 2018 +0000
@@ -8,7 +8,7 @@
 
 
 Serial command(USBTX, USBRX);
-
+DigitalIn button(USER_BUTTON);
 
 
 int main() {
@@ -26,16 +26,16 @@
         switch (read_cc) {
 
             case  0x01: 
-            debug_m("Tc1\n");
+            debug_m("Tc 1 Iniciado..\n");
             moving();
-            debug_m("FTc1\n");
+            debug_m("Tc 1 Finalizado\n");
             break;
             case  0x02: 
-            debug_m("Tc2 :) \n");
-            //moving();
-            debug_m("FTc2\n");
+            debug_m("Tc 2 Iniciado.. \n");
+            pares();
+            debug_m("Tc 2 Finalizado\n");
             break;
-            default: debug_m("error de comando. \nSe espera  0x01 - 0x08 \n");break ;      
+            default: debug_m("Error de comando. \nSe espera  entre 0x01 - 0x08 \n");break ;      
         }
     }
 }
@@ -49,20 +49,47 @@
    // Datos  | Inicio | Tele-comando | Numero Motor | Grados | Cierre
     //char intc=command.getc();
     buffer[0] = command.getc();
-    buffer[1] = command.getc();
-    buffer[2] = command.getc();
-    buffer[3] = command.getc();
-    buffer[4] = command.getc();
+
+ inicio:   
+  
+    while(buffer[0] != 0xFF ){
     
-    char intc = buffer[0];
-    while(intc != 0xFF){
-    
-        intc=command.getc();
+        buffer[0] = command.getc();
         
         debug_m("comando inicio invalido \n");
         }
         
-        printf("encontrado: %c \n",  buffer[0] ); 
+        printf("inicio encontrado: %c \n",  buffer[0] ); 
+        
+            buffer[1] = command.getc();
+        if (buffer[1] != 0xFF && buffer[1] != 0xFD){     
+            buffer[2] = command.getc();
+            }else{
+                buffer[0] = buffer[1];
+                goto inicio; 
+            }
+        if (buffer[2] != 0xFF && buffer[2] != 0xFD){     
+            buffer[3] = command.getc();
+            }else{
+                buffer[0] = buffer[2];
+                goto inicio; 
+            }
+        if (buffer[3] != 0xFF && buffer[3] != 0xFD){     
+            buffer[4] = command.getc();
+            }else{
+                buffer[0] = buffer[3];
+                goto inicio; 
+            }
+     //para que evalue el cierre 
+        if (buffer[4] != 0xFF && buffer[4] == 0xFD){     
+            debug_m("comando Cierre valido \n");
+            }else{
+                buffer[0] = buffer[4];
+                goto inicio; 
+            }
+
+          
+          
         //intc=command.getc();
         int tele = buffer[1];
         printf("Tele siguente: %c \n",  tele ); 
@@ -87,14 +114,28 @@
     printf("Motor: %c \n",  nmotor ); 
     char grados = buffer[3];
     printf("Grados: %c \n",  grados ); 
-    char endc = buffer[4];
-    printf("Cierre: %c \n",  endc ); 
+    //char endc = buffer[4];
+    //printf("Cierre: %c \n",  endc ); 
     mover_ser(nmotor,grados); 
     
     debug_m("fin del comado mover..\n");    
     
 }
-
+void pares(){
+    debug_m("se inicia el comado pares..\n");    
+    
+    char par = buffer[2];
+    printf("Par: %c \n",  par ); 
+    char dire = buffer[3];
+    printf("Dir: %c \n",  dire ); 
+    char endcc = buffer[4];
+    printf("Cierre: %c \n",  endcc ); 
+    while(button == 0) {
+    mover_par(par,dire); 
+    }
+    centro(par);
+    debug_m("fin del comado pares..\n"); 
+    }
 void debug_m(char *s , ... ){
     #if DEBUG
     command.printf(s);
diff -r 60722da62531 -r ba51736778e1 main.h
--- a/main.h	Fri Sep 07 03:42:26 2018 +0000
+++ b/main.h	Fri Sep 07 23:58:14 2018 +0000
@@ -14,6 +14,6 @@
 void init_serial();
 
 void moving();
-
+void pares();
 
 #endif //  MAIN_H 
\ No newline at end of file
diff -r 60722da62531 -r ba51736778e1 mover.cpp
--- a/mover.cpp	Fri Sep 07 03:42:26 2018 +0000
+++ b/mover.cpp	Fri Sep 07 23:58:14 2018 +0000
@@ -40,7 +40,9 @@
 void mover_ser(uint8_t motor, uint8_t pos){
 
     int pulseX = coord2us(pos);
-
+    //int pulseX = 900;
+    //int pulseY = 1500;
+   // myServo1.pulsewidth_us(pulseX);
  switch ( motor ) {
   
   case 0x01: 
@@ -72,7 +74,127 @@
 }
 
 }
-
+void mover_par(uint8_t pares, uint8_t dir){
+     
+     switch ( pares ) {
+  
+  case 0x01: 
+        if(dir==0x01){
+            Servo1.pulsewidth_us(ARRIBA);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+            Servo1.pulsewidth_us(ABAJO);
+            wait(0.5);
+            Servo2.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);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+          }
+    break;
+  case 0x02: 
+     if(dir==0x01){
+            Servo1.pulsewidth_us(ARRIBA);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+            Servo1.pulsewidth_us(ABAJO);
+            wait(0.5);
+            Servo2.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);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+          }
+    break;    
+  case 0x03: 
+     if(dir==0x01){
+            Servo1.pulsewidth_us(ARRIBA);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+            Servo1.pulsewidth_us(ABAJO);
+            wait(0.5);
+            Servo2.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);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+          }
+    break;
+  case 0x04: 
+     if(dir==0x01){
+            Servo1.pulsewidth_us(ARRIBA);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+            Servo1.pulsewidth_us(ABAJO);
+            wait(0.5);
+            Servo2.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);
+            wait(0.5);
+            Servo2.pulsewidth_us(ADELANTE);
+            wait(0.5);
+          }
+    break;
+     default: break;
+}
+    }
+void centro(uint8_t pos_p){
+switch ( pos_p ) {
+  
+  case 0x01: 
+            Servo1.pulsewidth_us(CENTRO);
+            wait(1);
+            Servo2.pulsewidth_us(CENTRO);
+            wait(1);
+    break;
+  case 0x02: 
+            Servo3.pulsewidth_us(CENTRO);
+            wait(1);
+            Servo4.pulsewidth_us(CENTRO);
+            wait(1);
+    break;    
+  case 0x03: 
+            Servo5.pulsewidth_us(CENTRO);
+            wait(1);
+            Servo6.pulsewidth_us(CENTRO);
+            wait(1);
+    break;
+  case 0x04: 
+            Servo7.pulsewidth_us(CENTRO);
+            wait(1);
+            Servo8.pulsewidth_us(CENTRO);
+            wait(1);
+    break;
+      default: break;
+}
+    }    
 void init_servo()
 {
    Servo1.period_ms(20);
diff -r 60722da62531 -r ba51736778e1 mover.h
--- a/mover.h	Fri Sep 07 03:42:26 2018 +0000
+++ b/mover.h	Fri Sep 07 23:58:14 2018 +0000
@@ -6,13 +6,17 @@
 #define MAXPOS 180       // en milimetros
 #define POSDRAW 50  
 #define POSNODRAW 10  
-
+#define ARRIBA 1700
+#define CENTRO 1300
+#define ABAJO 900
+#define ADELANTE 500
+#define ATRAS 2500
 
 void init_servo();
 void draw();
 void nodraw();
 void mover_ser(uint8_t motor, uint8_t pos);
-
-
+void mover_par(uint8_t pares, uint8_t dir);
+void centro(uint8_t pos_p);
 
 #endif //  DRAW_H 
\ No newline at end of file