Steven Ortiz / Mbed 2 deprecated PICCOLO_CNC1

Dependencies:   mbed Move_Servos Step_Motor

Files at this revision

API Documentation at this revision

Comitter:
Stevenor1997
Date:
Tue Apr 10 14:08:32 2018 +0000
Parent:
10:ccaea947ee2b
Child:
12:794bcad2db6f
Commit message:
ya funciona, el anterior programa conten?a un error que no debaja mover nada, ya solucionado;

Changed in this revision

Memoria.lib Show diff for this revision Revisions of this file
Move_Servos.lib Show annotated file Show diff for this revision Revisions of this file
Step_Motor.lib 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
--- a/Memoria.lib	Wed Apr 04 18:11:36 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/Stevenor1997/code/Memoria/#646600e5a927
--- a/Move_Servos.lib	Wed Apr 04 18:11:36 2018 +0000
+++ b/Move_Servos.lib	Tue Apr 10 14:08:32 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/Stevenor1997/code/Move_Servos/#19fc8a39d4ab
+https://os.mbed.com/users/Stevenor1997/code/Move_Servos/#50dac58ed944
--- a/Step_Motor.lib	Wed Apr 04 18:11:36 2018 +0000
+++ b/Step_Motor.lib	Tue Apr 10 14:08:32 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/Stevenor1997/code/Step_Motor/#ea300190c1f5
+https://os.mbed.com/users/Stevenor1997/code/Step_Motor/#4c622abe2483
--- a/main.cpp	Wed Apr 04 18:11:36 2018 +0000
+++ b/main.cpp	Tue Apr 10 14:08:32 2018 +0000
@@ -1,19 +1,57 @@
 #include "mbed.h"
 #include "Servo_X.h"
 #include "Step_Motor.h"
-#include "Memoria.h"
-
+ 
 DigitalOut myled(LED1);
-
+ 
 Serial pc(USBTX,USBRX);      //pines de transmision y recepcion asignados a puerto USB tipo B
-
-int NCA=0;
-
-
+ 
+stepmotor smotor1(PA_9,PC_7,PB_6,PA_7);
+#define MEM_SIZE 10000
+#define MEM_TYPE uint32_t
+uint32_t mem_head = 0;
+uint32_t mem_tail = 0;
+uint32_t full = 0;
+ 
+MEM_TYPE buffer[MEM_SIZE];
+ 
+void mem_free()
+{
+    mem_head=0;
+    full=0;
+    mem_tail=0;   
+}
+ 
+uint32_t mem_put(MEM_TYPE data)
+{
+    if(full){
+        return 1;
+    }
+    buffer [mem_head] = data;
+    mem_head +=1;
+    if(mem_head == MEM_SIZE)
+    full=1;
+    return 0;
+}
+ 
+uint32_t mem_get(MEM_TYPE* data)
+{
+    if(mem_head == 0)
+        return 1;
+    if (mem_head == mem_tail)
+        return 1;
+        
+    *data=buffer[mem_tail];
+    mem_tail +=1;
+    
+    return 0;
+}
+ 
+void S_EMPIEZA();
 void program_serial();
 void ejecutar();
 int guardar();
-
+ 
 int main() 
 {
     program_serial();
@@ -32,8 +70,7 @@
         switch(letra)
         {
             case CM_EJECUTAR:
-                myled!=myled;
-                if(get_mem_head!=get_mem_tail)
+                if(mem_head!=mem_tail)
                 { 
                     ejecutar();
                 }
@@ -42,7 +79,6 @@
                 } 
             break;
             case CM_GUARDAR: 
-                myled!=myled;
                 if(guardar()==0)
                 {
                     pc.printf("el programa se guardo correctamente \n");
@@ -66,31 +102,39 @@
     pc.baud(9600);              //programar los baudios
     pc.format(8,SerialBase::None,1);        //el numero de datos en bits, el bit de paridad, el bit de stop
 }
-
+void S_EMPIEZA()
+{
+    
+}
 void ejecutar()
 {
     program_serial();
     Servo Servos;
     pc.printf("el programa se esta ejecutando \n");
     uint8_t a=0,b=0,c=0,d=0;
+    uint32_t letra,letra1,letra2,letra3;
     MEM_TYPE val;
-    stepmotor smotor1(PB_3,PB_5,PB_4,PB_10);
-    smotor1.set_speed(1100);
+    
     mem_get(&val);
-    c=(val&0xff00)>>8;
-    b=(val&0xff0000)>>16;
-    a=(val&0xff000000)>>24;
-    d=val&0xff;
+    letra1=(val&0xff00)>>8;
+    letra2=(val&0xff0000)>>16;
+    letra3=(val&0xff000000)>>24;
+    letra=val&0xff;
     while(c!=CM_END)
     {
+        a=letra3;
         pc.putc(a);
+        b=letra2;
         pc.putc(b);
+        c=letra1;
         pc.putc(c);
+        d=letra;
         pc.putc(d);
         if(a==CM_SERVO)
         {
             Servos.SetServo(b,c);
         }
+        
         else if(c==CM_SDRAW)
         {
             Servos.SetZ(DRAW);
@@ -101,20 +145,21 @@
         }
         else if(a==CM_STEPMOTOR)
         {
-            c=c&0x1;
-            NCA=b;
-            uint32_t cuadrante=NUME_PASOS/RADIO_R;
-            smotor1.step((cuadrante*NCA),c);
+            uint8_t NCA=b;
+            uint32_t cuadrante=(NUME_PASOS/RADIO_R);
+            cuadrante=cuadrante*NCA;
+            smotor1.step(cuadrante,c);
+            pc.printf("ya lo movi \n");
         }
         mem_get(&val);
-        c=(val&0xff00)>>8;
-        b=(val&0xff0000)>>16;
-        a=(val&0xff000000)>>24;
-        d=val&0xff;
+        letra1=(val&0xff00)>>8;
+        letra2=(val&0xff0000)>>16;
+        letra3=(val&0xff000000)>>24;
+        letra=val&0xff;
         wait(1);
     }
     pc.printf("el programa se termino de ejecutar \n");
-    reset_tail();
+    mem_tail=0;
 }
 int guardar()
 {
@@ -126,6 +171,7 @@
     pc.printf("el programa se esta guardando \n");
     subletra=pc.getc();
     pc.putc(subletra);
+    //mem_put(letra);
     while(subletra!=CM_END)
     {
         switch(subletra)
@@ -171,20 +217,25 @@
                 }
                 letra=letra+subletra;
                 mem_put(letra);
-            break;
+            break; 
             case CM_STEPMOTOR:
                 letra=letra+subletra<<8;
-                subletra=pc.getc();         //ingresa # de cuadrante
-                letra=letra+subletra<<8;
-                subletra=pc.getc();         //ingresa direccion
-                letra=letra+subletra<<8;
-                subletra=pc.getc();         //se ingresa f0
+                subletra=pc.getc();
+                letra=letra+subletra;
+                pc.putc(letra);
+                letra=letra<<8;
+                subletra=pc.getc();
+                letra=letra+subletra;
+                pc.putc(letra);
+                letra=letra<<8;
+                subletra=pc.getc();
                 if(subletra!=CM_STOP)
                 {
                     pc.printf("comando End no definido \n");
                     return 1;
                 }
                 letra=letra+subletra;
+                pc.putc(letra);
                 mem_put(letra);
             break;
         }
@@ -195,4 +246,5 @@
     pc.printf("el programa termino de guardar \n");
     mem_put(0xfaf0);
     return 0;
-}
\ No newline at end of file
+}
+            
\ No newline at end of file