Steven Vasquez
/
Piccolo2
Piccolo
Fork of Piccolo1 by
Revision 0:4828681bf1f8, committed 2018-04-17
- Comitter:
- Stevenvasquez
- Date:
- Tue Apr 17 00:28:17 2018 +0000
- Commit message:
- lalod
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/draw.cpp Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,81 @@ + +#include "draw.h" +#include "mbed.h" +#include "math.h" + + +PwmOut myServoZ(PB_3); +PwmOut myServoX(PB_4); +PwmOut myServoY(PB_5); + +uint8_t posx_old=0; // posición anterior del eje X +uint8_t posy_old=0; // posición anterior del eje Y +uint8_t ss_time=50; // tiempo de espera para moverse 1 mm en microsegundos + +void put_sstime(uint8_t vtime){ + ss_time=vtime; + +} + +int coord2us(float coord) +{ + if(0 <= coord <= MAXPOS) + return int(750+coord*1900/50);// u6 + return 750; + +} + +void sstime(uint8_t x, uint8_t y) +{ + double dx=abs(x-posx_old); + double dy=abs(y-posy_old); + double dist= sqrt(dx*dx+dy*dy); + wait_ms((int)(ss_time*dist)); + posx_old =x; + posy_old=y; + + } + +void draw(){ +myServoZ.pulsewidth_us(coord2us(POSDRAW)); +wait_ms(ss_time*10); +} + +void nodraw(){ +myServoZ.pulsewidth_us(coord2us(POSNODRAW)); +wait_ms(ss_time*10); +} + + +void vertex2d(uint8_t x, uint8_t y){ + + int pulseX = coord2us(x); + int pulseY = coord2us(y); + + myServoX.pulsewidth_us(pulseX); + myServoY.pulsewidth_us(pulseY); + + sstime(x,y); + +} + +void initdraw(float x, float y){ + vertex2d (x,y); + draw(); +} + +void home(){ + nodraw(); + vertex2d(0 ,0); +} + + + +void init_servo() +{ + myServoX.period_ms(20); + myServoY.period_ms(20); + myServoZ.period_ms(20); + + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/draw.h Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,20 @@ +#ifndef DRAW_H +#define DRAW_H + +#include "mbed.h" + +#define MAXPOS 50 // en milimetros +#define POSDRAW 50 +#define POSNODRAW 10 + + +void init_servo(); +void draw(); +void nodraw(); +void vertex2d(uint8_t x, uint8_t y); + +void home(); +void initdraw(float x, float y); +void put_sstime(uint8_t vtime); + +#endif // DRAW_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,158 @@ +#include "mbed.h" +#define POSMAX 50 // en milimetros +#define POSDRAW 30 // en milimetros +#define BAUD 9600 // Configuracion de baudios +#define MEM_SIZE 10 +#define MEM_TYPE uint32_t + +#define CM_EJECUTAR 0xff +#define CM_GUARDAR 0xfe +#define CM_VERTEX2D 0xfd +#define CM_DRAW 0xfc +#define CM_NODRAW 0xfb +#define CM_STOP 0xfa +#define CM_END 0xf0 + +PwmOut ServoX(PB_3); //D3 +PwmOut ServoY(PB_4); //D5 +PwmOut ServoZ(PB_10); //D6 + +MEM_TYPE buffer[MEM_SIZE]; +Serial pc(USBTX,USBRX); // Comunicación Serial + +uint8_t posx_old=0; // posición anterior del eje X +uint8_t posy_old=0; // posición anterior del eje Y +uint8_t ss_time=100; // tiempo de espera para moverse 1 mm en microsegundos +int mem_head; +int mem_tail; +uint8_t full; + +uint8_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; +} +uint8_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 mem_free() +{ + mem_head=0; + full=0; +} +void sstime(uint8_t x, uint8_t y) +{ + double dx=abs(x-posx_old); + double dy=abs(y-posy_old); + double dist= sqrt(dx*dx+dy*dy); + wait_ms((int)(ss_time*dist)); + posx_old = x; + posy_old= y; + +} +int coord2pulse(float coord) // conversión de coordenadas en Y +{ + if(0 <= coord <= POSMAX) + return int(700+coord*1900/50); + return 700; +} +void vertex2d(uint8_t x, uint8_t y) // Funcion de llamado de conversiones X y Y +{ + int pulseX = coord2pulse(x); + int pulseY = coord2pulse(y); + ServoX.pulsewidth_us(pulseX); + ServoY.pulsewidth_us(pulseY); + sstime(x,y); + wait_ms(ss_time); +} +void draw() // Función para enviarle la posicion de dibujo a Z, lo mueve hacia abajo. + { + int pulseZ=coord2pulse(POSDRAW); + ServoZ.pulsewidth_us(pulseZ); + pc.printf(" Dibujando..."); + wait_ms(ss_time*2); + } +void nodraw() // Función para enviarle la posicion de no dibujar a Z, lo mueve hacia arriba. + { + int pulseZ=coord2pulse(0); + ServoZ.pulsewidth_us(pulseZ); + pc.printf(" Dibujo Terminado..."); + wait_ms(ss_time*2); + } +void ejecutar(){ + pc.printf("se esta ejecutando el dibujo..."); + // ubicar acà el codigo +} +void guardar(){ + pc.printf("se inicia el comado de guardar.."); + // ubicar acà el codigo + +} +void init_serial() // configuracion de baudios a pc +{ + pc.baud(BAUD); +} +void init_servos() // configuracion de periodo +{ + ServoX.period_ms(20); + ServoY.period_ms(20); + ServoZ.period_ms(20); +} +void init_draw(float x, float y) +{ + vertex2d (x,y); + wait_ms(ss_time); + draw(); +} +void home() +{ + nodraw(); + vertex2d(0,0); + pc.printf("Posicion Home"); + wait_ms(ss_time); +} +void put_sstime(uint8_t vtime) +{ + ss_time=vtime; + +} + + +int main() { + + init_servos(); + init_serial(); + int posx=0; + int posy=0; + draw(); + while(1) + { + wait(1); + vertex2d(posx,posy); + posx+=5; + posy+=5; + if (posx > POSMAX and posy > POSMAX) + { + posx=0; + posy=0; + nodraw(); + } + + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,59 @@ +#ifndef MAIN_H +#define MAIN_H + + +#include "draw.h" +#include "memory.h" +//****************************************************************************** +// Desarrollado por ferney beltran fbeltran@ecci.edu.co +//****************************************************************************** + +//***************************************************************************** +// COMANDOS +// |POS_0|POS_1|POS_2| POS_3 | +// | #C | a | b | c | +// +// #C -> Indica el comando FF, FE, ... +// a -> es el fin de comando F0 en otros casos es el valor de la coord X +//b -> Coordenada Y +// c -> fin de comando F0 + +// Nota: El fin de comando no se almacena +//****************************************************************************** + +/* +prueba 1 +ff f0 + +prueba 2 +fe f0 fd 00 00 f0 fc f0 fd 00 32 f0 fd 32 32 f0 fd 32 00 f0 fd 00 00 f0 fb f0 fa f0 +ff f0 + +prueba 3 +fe f0 fd 00 00 f0 fc f0 fd 00 0A f0 fd 32 0A f0 fd 32 14 f0 fd 00 14 f0 fd 00 1E f0 fd 32 1E f0 fd 32 28 f0 fd 00 28 f0 fa f0 +ff f0 + + + +*/ + +#define DEBUG 1 + + +void debug_m(char *s , ... ); +uint32_t read_command(); +void init_serial(); +void drawing(); +void saving(); + + +/********************* PARAMETROS PARA DEFINIR EL COMMANDO ******************/ +#define CM_DRAWING 0xff +#define CM_SAVING 0xfe +#define CM_VERTEX2D 0xfd +#define CM_DRAW 0xfc +#define CM_NODRAW 0xfb +#define CM_STOP 0xfa +#define CM_END 0xf0 + +#endif // MAIN_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/994bdf8177cb \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memory.cpp Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "memory.h" + +int mem_head = 0; +int mem_tail = 0; +uint8_t full = 0; + +MEM_TYPE buffer[MEM_SIZE]; + +void tail_reset() +{ + mem_tail=0; +} + +void mem_free() +{ + mem_head=0; + full=0; +} + + +uint8_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; +} + +uint8_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; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memory.h Tue Apr 17 00:28:17 2018 +0000 @@ -0,0 +1,18 @@ +#ifndef MEMORY_ARRAY_H +#define MEMORY_ARRAY_H + +#include "mbed.h" + +#define MEM_SIZE 10 +#define MEM_TYPE uint32_t + + + +void tail_reset(); +void mem_free(); +uint8_t mem_put(MEM_TYPE data); +uint8_t mem_get(MEM_TYPE* data); + + + +#endif // MEMORY_H \ No newline at end of file