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.
draw.cpp
- Committer:
- DANIELOM1916
- Date:
- 2018-03-13
- Revision:
- 0:cc4ffe9bb764
File content as of revision 0:cc4ffe9bb764:
#include "draw.h"
#include "mbed.h"
#include "math.h"
PwmOut myServoX(PB_3); // pin de salida del PWM X
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){ //SI
ss_time=vtime;
}
int coord2us(float coord)
{
if(0 <= coord <= MAXPOS)
return int(560+coord*1700/50);// calculo rango servomotor
return 560;
}
void sstime(uint8_t x, uint8_t y) // calculo para la posicion del piccolo
{
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(){ // posicion para dibujo
myServoZ.pulsewidth_us(POSDRAW);
wait_ms(ss_time*2);
}
void nodraw(){ // posicion eje z arrina
myServoZ.pulsewidth_us(MAXPOS);
wait_ms(ss_time*2);
}
void vertex2d(uint8_t x, uint8_t y){ // subprograma para dibujar
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){ //posicion inicial para dibujar
vertex2d (x,y);
draw();
}
void home(){ // posicion en reposo del piccolo
nodraw();
vertex2d(0 ,0);
}
void init_servo() // periodo de lo servos para su funcionamiento
{
myServoX.period_ms(20);
myServoY.period_ms(20);
myServoZ.period_ms(20);
}