Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 02_LAB_serial_protocol by
Revision 20:b7f2e428b24c, committed 2017-10-20
- Comitter:
- fabeltranm
- Date:
- Fri Oct 20 00:50:00 2017 +0000
- Parent:
- 19:082e74f5e5ab
- Commit message:
- update debug draw
Changed in this revision
--- a/draw.cpp Thu Oct 19 23:43:31 2017 +0000 +++ b/draw.cpp Fri Oct 20 00:50:00 2017 +0000 @@ -3,6 +3,10 @@ #include "mbed.h" #include "math.h" +#if DEBUG_DRAW + Serial debugdraw(USBTX, USBRX); +#endif + DigitalOut led(LED1); PwmOut myServoX(PB_3); @@ -64,7 +68,7 @@ myServoX.pulsewidth_us(pulseX); myServoY.pulsewidth_us(pulseY); - wait_ms(ss_time); //TODO: CALCULAR EL TIEMPO DE DONDE VIENE + sstime(); } @@ -88,14 +92,17 @@ if (abs(m)<=1){ b=(float)yf-(float)(m*xf); - // command.printf(" m = %f b= %f \n", m,b); + #if DEBUG_DRAW + debugdraw.printf("debugdraw m = %f b= %f \n", m,b); + #endif xp =xi; while(run) { yp =m*xp+b; vertex2d(xp ,yp); - //print_bin2hex(xp); print_bin2hex(yp); - //command.printf(" \n"); + #if DEBUG_DRAW + debugdraw.printf(" debugdraw %f %f \n", xp,yp); + #endif if (xf>xi){ xp=xp+st; if (xp>xf)run=0; @@ -108,14 +115,17 @@ }else{ m=(float)(xf-xi)/(yf-yi); b=(float)xf-(float)(m*yf); - // command.printf(" m = %f b= %f \n", m,b); + #if DEBUG_DRAW + debugdraw.printf("debugdraw m = %f b= %f \n", m,b); + #endif yp =yi; while(run) { xp =m*yp+b; vertex2d(xp ,yp); - // print_bin2hex(xp); print_bin2hex(yp); - // command.printf(" \n"); + #if DEBUG_DRAW + debugdraw.printf("debugdraw %f %f \n", xp,yp); + #endif if (yf>yi){ yp=yp+st; if (yp>yf)run=0;
--- a/draw.h Thu Oct 19 23:43:31 2017 +0000 +++ b/draw.h Fri Oct 20 00:50:00 2017 +0000 @@ -7,7 +7,9 @@ #define RSTEP 2 // en milimetros #define POSDRAW 10 - + + +#define DEBUG_DRAW 1 void led_on(uint16_t ts, uint16_t tms ); void draw(); @@ -18,6 +20,7 @@ void initdraw(float x, float y); void line(float xi, float yi, float xf, float yf); void rectangle(float x, float y, float width,float height); +void circle(float x, float y, float radio); void put_sstime(uint8_t vtime); #endif // DRAW_H \ No newline at end of file
--- a/main.cpp Thu Oct 19 23:43:31 2017 +0000 +++ b/main.cpp Fri Oct 20 00:50:00 2017 +0000 @@ -7,7 +7,6 @@ Serial command(USBTX, USBRX); -#define DEBUG 1 uint8_t buffer_cmd[BUFF_SIZE]={0,0,0,0}; @@ -87,55 +86,9 @@ command.printf("draw line: "); command.printf("Coord Xi= %i Coord Yi = %i Coord Xf= %i Coord Yf = %i\n", xi,yi,xf,yf); #endif - // line( xi, yi, xf, yf); - - float xp; float yp; - float m=100000; float b; - int st=1 ; - m=(float)(yf-yi)/(xf-xi); + line( xi, yi, xf, yf); - int run=1; - if (abs(m)<=1){ - b=(float)yf-(float)(m*xf); - command.printf(" m = %f b= %f \n", m,b); - xp =xi; - while(run) - { - yp =m*xp+b; - - print_bin2hex(xp); print_bin2hex(yp); - command.printf(" \n"); - if (xf>xi){ - xp=xp+st; - if (xp>xf)run=0; - }else { - xp-=st; - if (xp<xf)run=0; - } - - } - }else{ - m=(float)(xf-xi)/(yf-yi); - b=(float)xf-(float)(m*yf); - command.printf(" m = %f b= %f \n", m,b); - yp =yi; - while(run) - { - xp =m*yp+b; - - print_bin2hex(xp); print_bin2hex(yp); - command.printf(" \n"); - if (yf>yi){ - yp=yp+st; - if (yp>yf)run=0; - }else { - yp-=st; - if (yp<yf)run=0; - } - - } - } -} + } void command_rectangle(){ uint8_t x=buffer_cmd[REC_POS_X]; @@ -150,9 +103,14 @@ rectangle( x, y, width, height); } void command_cicle(){ + uint8_t x=buffer_cmd[CICLE_POS_X]; + uint8_t y=buffer_cmd[CICLE_POS_Y]; + uint8_t r=buffer_cmd[CICLE_POS_R]; #if DEBUG command.printf("draw cicle: "); + command.printf("Centro X= %i Centro Y = %i radio= %i \n", x,y,r); #endif + circle(x,y,r); } void command_home(){ #if DEBUG @@ -168,6 +126,7 @@ void command_sstime(){ #if DEBUG command.printf("config tiempo entre movimientos de los servos: "); + command.printf("SSTIME = %i\n", buffer_cmd[POS_1]); #endif put_sstime(buffer_cmd[POS_1]); } @@ -178,17 +137,17 @@ } void command_pause(){ #if DEBUG - command.printf("picolo en pausa "); + command.printf("piccolo en pausa "); #endif } void command_reanudar(){ #if DEBUG - command.printf("reanuda picolo "); + command.printf("reanuda piccolo "); #endif } void command_stepmotor(){ #if DEBUG - command.printf("comando mover picolo: "); + command.printf("comando mover piccolo: "); #endif }
--- a/main.h Thu Oct 19 23:43:31 2017 +0000 +++ b/main.h Fri Oct 20 00:50:00 2017 +0000 @@ -21,6 +21,7 @@ +#define DEBUG 1 /********************* PARAMETROS PARA DEFINIR EL COMMANDO ******************/ #define BUFF_SIZE 6 //Tamaño del buffer @@ -91,7 +92,22 @@ // COMANDOS +/********************* PARAMETROS COMMANDO DRAW CICLE*********************/ + +// el comando indica la posicion en X y Y del centro del circulo +// y r es el radio del circlo +// +// |POS_i|POS_0|POS_1|POS_2| POS_3 | POS_4 | POS_5 | +// | < | 03 | x | y | r | xxx | > | + + #define COMMAND_CICLE 4 + +#define CICLE_POS_X POS_1 // Posición de la coordenada central X +#define CICLE_POS_Y POS_2 // Posición de la cordenada central de y +#define CICLE_POS_R POS_3 // radio del circulo + + #define COMMAND_HOME 5 #define COMMAND_RSTEPSERVO 6 //RESOLUCIÓN; número de lineas que dibuja para // la figura completa