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.
Revision 0:abaa541e10d5, committed 2018-03-07
- Comitter:
- fabeltranm
- Date:
- Wed Mar 07 01:00:46 2018 +0000
- Commit message:
- ejerciocio 2
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/draw.cpp Wed Mar 07 01:00:46 2018 +0000 @@ -0,0 +1,82 @@ + +#include "draw.h" +#include "mbed.h" +#include "math.h" + + + +PwmOut myServoX(PB_3); +PwmOut myServoY(PB_4); +PwmOut myServoZ(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=100; // 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(POSDRAW); +wait_ms(ss_time*2); +} + +void nodraw(){ +myServoZ.pulsewidth_us(MAXPOS); +wait_ms(ss_time*2); +} + + +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 Wed Mar 07 01:00:46 2018 +0000 @@ -0,0 +1,19 @@ +#ifndef DRAW_H +#define DRAW_H + +#include "mbed.h" + +#define MAXPOS 50 // en milimetros +#define POSDRAW 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 Wed Mar 07 01:00:46 2018 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +#include "draw.h" +#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 + + + + +Serial command(USBTX, USBRX); + + +void ejecutar(){ + command.printf("se esta ejecutando el dibujo..."); + // ubicar acà el codigo +} +void guardar(){ + command.printf("se inicia el comado de guardar.."); + // ubicar acà el codigo + +} +void init_serial() +{ + command.baud(9600); +} +int main() { + init_servo(); + init_serial(); + home(); + char read_cc; + while(1) + { + switch (read_cc) { + case CM_EJECUTAR: ejecutar(); break; + case CM_GUARDAR: guardar(); break; + default: command.printf("error de comando");break ; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 07 01:00:46 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/aa5281ff4a02 \ No newline at end of file