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.
Dependencies: mbed
Fork of Piccolo_1C_Funciones by
Revision 2:f52a2c0dedb4, committed 2017-10-06
- Comitter:
- Vanessa620
- Date:
- Fri Oct 06 04:35:58 2017 +0000
- Parent:
- 1:f246d2321c06
- Commit message:
- SIS.EMB.PICOLO.V1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Sep 09 14:00:12 2017 +0000 +++ b/main.cpp Fri Oct 06 04:35:58 2017 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" -#define MAXPOS 50 -#define SS_TIME 500 +#include "math.h" +#define MAXPOS 50 // maxposX : 5.5cm ; maxposY : 4.5cm +#define SS_TIME 500 +#define PI 3.1415926 PwmOut myServoX(PB_3); PwmOut myServoY(PB_4); @@ -8,18 +10,17 @@ int coord2us(float coord) - { +{ if(0 <= coord <= MAXPOS) return int(750+coord*1900/50);// u6 - return 750; - } - -void vertex2d(float x, float y) + //return 750; + } +void vertex2d(float y) //, float y { - int pulseX = coord2us(x); - int pulseY = coord2us(y); + // int pulseX = coord2us(x); + int pulseY = coord2us(y); - myServoX.pulsewidth_us(pulseX); + //myServoX.pulsewidth_us(pulseX); myServoY.pulsewidth_us(pulseY); wait_ms(SS_TIME); } @@ -28,130 +29,147 @@ void home() { - - vertex2d(0,0); - myServoZ.pulsewidth_us(MAXPOS); - } + vertex2d(0); + } void maxpos() { - vertex2d(MAXPOS,MAXPOS); + vertex2d(MAXPOS); } + /* +void cuadrado(int x, int y, int l) + { + float a; + float b; + + wait(2);vertex2d(a,b); + printf("position x =%.2f\n",a); + printf("position y =%.2f\n",b); + a=a+l; + wait(2);vertex2d(a,b); + printf("position x =%.2f\n",a); + printf("position y =%.2f\n",b); + b=b+l; + wait(2);vertex2d(a,b); + printf("position x =%.2f\n",a); + printf("position y =%.2f\n",b); + a=a-l; + wait(2);vertex2d(a,b); + printf("position x =%.2f\n",a); + printf("position y =%.2f\n",b); + b=b-l; + wait(2);vertex2d(a,b); + printf("position x =%.2f\n",a); + printf("position y =%.2f\n",b); + + vertex2d(x,y); + // wait(2); + a=x+l; + vertex2d(a,y); + //wait(2); + b=y+l; + vertex2d(a,b); + //wait(2); + vertex2d(x,b); + // wait(2); + vertex2d(x,y); + } void diag() { - /* wait(2);vertex2d(0,0); + wait(2);vertex2d(0,0); wait(2);vertex2d(10,10); wait(2);vertex2d(20,20); wait(2);vertex2d(30,30); - wait(2);vertex2d(40,40); - - - - wait(1);vertex2d(0,0); + wait(2);vertex2d(40,40);*/ + + /*wait(1);vertex2d(0,0); wait(1);vertex2d(40,0); wait(1);vertex2d(40,40); wait(1);vertex2d(0,40); - wait(1);vertex2d(0,0); */ - } - -void cuadrado(int x, int y, int lado) - { - float l=lado; - float a=x; - float b=y; - - myServoZ.pulsewidth_us(MAXPOS); - vertex2d(a,b); - myServoX.pulsewidth_us(100); - a=a+l; - vertex2d(a,b); - b=b+l; - vertex2d(a,b); - a=a-l; - vertex2d(a,b); - b=b-l; - vertex2d(a,b); - } - -void line(int x0, int y0, int x1, int y1) { - home(); - wait(2); - vertex2d(x0,y0); -bool steep = abs(y1 - y0) > abs(x1 - x0); -int temp, deltax, deltay, error, y, x; - if (steep) { - temp = y0; - y0 = x0; - x0 = temp; - temp = y1; - y1 = x1; - x1 = temp; - } - if (x0 > x1) { - temp = x1; - x1 = x0; - x0 = temp; - temp = y1; - y1 = y0; - y0 = temp; - } + wait(1);vertex2d(0,0); - deltax = x1 - x0; - deltay = abs(y1 - y0); - error = deltax / 2; - y = y0; - /*if (y0 < y1) { - ystep = 1; - } else { - ystep = -1; - }*/ - for (x=x0; x<=x1; x++) { - if (steep) { - vertex2d(y,x); - } else { - vertex2d(x,y); + wait(1);vertex2d(10,0); + wait(1);vertex2d(10,40); + wait(1);vertex2d(20,40); + wait(1);vertex2d(20,0); + wait(1);vertex2d(30,0); + wait(1);vertex2d(30,40); + wait(1);vertex2d(40,40); + wait(1);vertex2d(40,0); } - } - } + + + + void Pendiente(int x0,int y0,int x1,int y1) +{ +float x; +float y; +float m; +for(x=x0; x<=x1; x=x+1) +{ +m=(y1-y0)/(x1-x0); +y=m*(x-x0)+y0; +vertex2d(x,y); + printf("position x =%.2f\n",x); + printf("position y =%.2f\n",y); +} +*/ +/* + vertex2d(x0,y0); + //wait(2); + vertex2d(x1,y1); +} -void circle(int cx, int cy, int radius) { - - int x = 0; - int y = radius; - int d = 3 - (2 * radius); - - home(); - wait(2); - vertex2d(cx,cy); - myServoX.pulsewidth_us(100); - myServoZ.pulsewidth_us(MAXPOS); - /*cx=cx+radius; - vertex2d(cx,cy);*/ - myServoX.pulsewidth_us(100); - - while (x <= y) { - vertex2d(cx + x, cy + y); - vertex2d(cx + y, cy + x); - vertex2d(cx - x, cy + y); - vertex2d(cx + y, cy - x); - vertex2d(cx - x, cy - y); - vertex2d(cx - y, cy - x); - vertex2d(cx + x, cy - y); - vertex2d(cx - y, cy + x); +void circle(float cx, float cy, float radio) + { + float y; + float x; + wait(2); vertex2d(cx,cy); + + + for(double i=PI/2; i<=PI ;i=i+0.5) + { + x=radio*cos(i); + y=radio*sin(i); + vertex2d(cx-x,cy-y); + printf("position x =%.2f\n",x); + printf("position y =%.2f\n",y); + } + wait(1); + for(double i=0; i<=PI/2 ;i+=0.5) + { + x=radio*cos(i); + y=radio*sin(i); + vertex2d(x+cx,y+cy); + printf("position x =%.2f\n",x); + printf("position y =%.2f\n",y); + } + + for(double i=PI; i<=(3*PI)/2 ;i=i+0.5) + { + x=radio*cos(i); + y=radio*sin(i); + vertex2d(x+y,cx+cy); + printf("position x =%.2f\n",x); + printf("position y =%.2f\n",y); + }*/ + /* + for(double i=3*PI/2; i<=2*PI ;i=i+0.1) + { + x=radio*cos(i); + y=radio*sin(i); + vertex2d(cx+x,cy-y); + printf("position x =%.2f\n",x); + printf("position y =%.2f\n",y); + } + } - if (d<0){ - d += (4 * x) + 6; - } else - { - d += (4 * (x - y)) + 10; - y--; - } - x++; - } - } + void Pendiente(int x0,int y0,int x1,int y1); - int main() + */ + + int main() { // configuracion de periodo myServoX.period_ms(20); @@ -159,19 +177,39 @@ myServoZ.period_ms(20); while(1) - { - home(); - wait(3); + { + home(); + wait(2); maxpos(); - wait(3); - //diag(); - cuadrado(10,10,20); - wait(3); - line(20,20,40,40); - wait(3); - circle(20,20,20); - wait(3); - - } - + wait(2); + home(); + + + /* wait(3); + //Pendiente(30,35,15,20); + //Pendiente(15,20,0,35); + //Pendiente(0,35,15,50); + //wait(3); + //Pendiente(15,50,30,35); + //wait(3); + + wait(3); + + Pendiente(30,20,30,40); + Pendiente(30,40,40,40); + Pendiente(40,40,40,20); + Pendiente(40,20,30,20); + wait(3); + Pendiente(20,0,50,0); + Pendiente(50,0,50,10); + Pendiente(50,10,30,15); + + cuadrado(0,0,10); + wait(2); + circle(30,0,15); + wait(3); + + diag(); + */ +} } \ No newline at end of file