codigo incompleto picolo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #define MEM_SIZE 5000
00003 #define MEM_TYPE uint32_t
00004 #define MAXPOS 50       // en milimetros
00005 #define SS_TIME 100     // en microsegundos
00006 #define POSDRAW 10   
00007 #define periodo 20
00008 #define CM_EJECUTAR 0xff
00009 #define CM_GUARDAR 0xfe
00010 #define CM_VERTEX2D 0xfd
00011 #define CM_DRAW 0xfc
00012 #define CM_NODRAW 0xfb
00013 #define CM_STOP 0xfa
00014 #define CM_END 0xf0
00015 
00016 MEM_TYPE arreglo2[MEM_SIZE];
00017 Serial pc(USBTX, USBRX); 
00018 PwmOut motor_x(A3), motor_y(A1), motor_z(A0);
00019 int mem_head = 0,i;
00020 int mem_tail = 0;
00021 uint8_t full = 0;
00022 char b;
00023 MEM_TYPE comando,px,py,condicionf;
00024 
00025 
00026 
00027 int coord2us(float coord);
00028 void draw();
00029 void nodraw();
00030 void vertex2d(float x, float y);
00031 ///////////////////////////////////////////////////////
00032 void ejecutar(){
00033     pc.printf("se esta ejecutando el dibujo...");    
00034     for(i=0;i<mem_head-1;i++)
00035     {   
00036         if (arreglo2[i]==CM_VERTEX2D)//FD F0
00037         {
00038             i++;
00039             px=arreglo2[i]
00040             
00041         }
00042     }
00043 
00044 }
00045 /////////////////////////////////////////////////////////////
00046 void guardar(){
00047     pc.printf("se inicia el comado de guardar..");    
00048     mem_head=0;
00049             do
00050             {
00051                 pc.printf("entro while llenar\n\r");
00052                 arreglo2[mem_head]=pc.getc();
00053                 b=arreglo2[mem_head];
00054                 //pc.printf("posicion %i %c",mem_head,arreglo2[mem_head]);
00055                 mem_head++;  
00056             }
00057             while(b!=CM_STOP);
00058     
00059  }
00060  
00061 int main() {
00062      // configuracion de  periodo
00063     motor_x.period_ms(periodo);
00064     motor_y.period_ms(periodo);
00065     motor_z.period_ms(periodo);
00066     motor_x.pulsewidth_us(725);
00067     motor_y.pulsewidth_us(725);
00068     motor_z.pulsewidth_us(725);
00069     int posx=0;
00070     int posy=0;
00071     char caracter;
00072   while(1)
00073     {
00074         caracter=pc.getc();
00075         switch (caracter) {
00076             case  CM_EJECUTAR: ejecutar(); break;
00077             case  CM_GUARDAR: guardar(); break;
00078             default: pc.printf("error de comando\r\n");break ;      
00079         }
00080     }
00081 }
00082 
00083 
00084 int coord2us(float coord)
00085 {
00086     if(0 <= coord <= MAXPOS)
00087         return int(750+coord*1900/50);// u6
00088     return 750;
00089  
00090 }
00091  
00092 void draw()
00093 {
00094 motor_z.pulsewidth_us(POSDRAW);
00095 wait(1);
00096 }
00097 void nodraw()
00098 {
00099 motor_z.pulsewidth_us(MAXPOS);
00100 wait(1);
00101 }
00102 void vertex2d(float x, float y){
00103  
00104     int pulseX = coord2us(x);
00105     int pulseY = coord2us(y);
00106     
00107     motor_x.pulsewidth_us(pulseX);
00108     motor_y.pulsewidth_us(pulseY);
00109     wait_ms(SS_TIME);
00110  
00111 }