gaztea tech 2015: 4. gt drawbot control

15
4. GT DRAWBOT Control GAZTEA TECH 2015 ROBÓTICA Svet Ivantchev Jon Agüero

Upload: svet-ivantchev

Post on 15-Aug-2015

119 views

Category:

Education


0 download

TRANSCRIPT

4. GT DRAWBOTControl

GAZTEA TECH 2015ROBÓTICA

Svet IvantchevJon Agüero

S1: 0º

S1: 90º

S2: 0ºS2: 180º

S1

S2

x

y

l1

l2

f1 q1

f2

Tenemos: x y yNecesitamos: f1 y f2

S1

S2

x

y

b

l1

l2

f1

q2

q1

q1 = tan�1(y/x)

b

2 = x

2 + y

2

f1 = q1 � q2

l22 = l21 + b2 � 2l1b cos(q2)

q2 = cos

�1

✓l21 � l22 + b2

2l1b

S1

S2

x

y

b

l1

l2

f2 b2

b2 = cos

�1

✓l21 + l22 � b2

2l1l2

f2 = ⇡ � b2

import processing.serial.*;import cc.arduino.*;

Arduino arduino;

void setup() { size(300,300); arduino = new Arduino(this, "/dev/tty.usbmodem1421", 57600); arduino.pinMode(4, Arduino.SERVO); arduino.pinMode(7, Arduino.SERVO);}

void draw() { int x,y; float l1=1000.0; float l2=1000.0; float q1,q2,f1,f2,b; x = 1200; y = 1200; b = sqrt(x*x+y*y); q1= atan2(y, x); q2= acos((l1*l1 - l2*l2 + b*b)/(2.0*l1*b)); f1=degrees(q1+q2) ; f2=degrees(acos((l1*l1 + l2*l2 -b*b)/(2*l1*l2))); if (q1 > f1 ) { f2 = (f2-90); } else { f2 = 180 - (f2-90); }; println(f1, f2); arduino.servoWrite(7, (int)f1); arduino.servoWrite(4, (int)f2); delay(30);

exit();}

PREPARACIÓN DE IMAGEN

PREPARACIÓN DE IMAGEN

Imagen en JPEG

Fichero SVG

DrawBot

StippleGen2

Processing sketch

COMO LEER EL SVGInstalar la librería geomerative: Sketch > Import Library … > Add Library …

COMO LEER EL SVGimport geomerative.*;

RShape s1;

void setup() { size(500,500); RG.init(this); s1 = RG.loadShape("star.svg");}

void draw() { float x,y; float maxx, maxy, minx, miny; RPoint[] pa = s1.getPoints(); println(pa.length); maxx = 0; maxy = 0; minx = 10000; miny = 10000; for (int i = 0; i < pa.length; i++) { x = pa[i].x; y = pa[i].y; if (x > maxx) { maxx = x;}; if (y > maxy) { maxy = y;}; if (x < minx) { minx = x;}; if (y < miny) { miny = y;}; } println(minx,maxx, miny, maxy); noFill(); beginShape(); for (int i = 0; i < pa.length; i++) { x = map( pa[i].x, minx, maxx, 0, 499); y = map( pa[i].y, miny, maxy, 0, 499); vertex(x,y); println(x,y); } endShape();}

Combinando lectura de SVG y el control del Drawbot

import geomerative.*;import processing.serial.*;import cc.arduino.*;

RShape s1;Arduino arduino;

void setup() { size(300,300); RG.init(this); s1 = RG.loadShape("star.svg"); arduino = new Arduino(this, "/dev/tty.usbmodem1421", 57600); arduino.pinMode(4, Arduino.SERVO); arduino.pinMode(7, Arduino.SERVO);}

void draw() { float x,y; float maxx, maxy, minx, miny; float l1=1000.0; float l2=1000.0; float q1,q2,f1,f2,b; RPoint[] pa = s1.getPoints(); println(pa.length); maxx=0; maxy=0; minx = 10000; miny = 10000; for (int i = 0; i < pa.length; i++) { x = pa[i].x; y = pa[i].y; if (x > maxx) { maxx = x;}; if (y > maxy) { maxy = y;}; if (x < minx) { minx = x;}; if (y < miny) { miny = y;}; }

println(minx,maxx, miny, maxy); noFill(); beginShape(); for (int i = 0; i < pa.length; i++) { x = map( pa[i].x, minx, maxx, 1050, 1450); y = map( pa[i].y, miny, maxy, 1050, 1450); vertex(x,y); println(x,y);

b = sqrt(x*x+y*y); q1= atan2(y, x); q2= acos((l1*l1 - l2*l2 + b*b)/(2.0*l1*b)); f1=degrees(q1+q2) ; f2=degrees(acos((l1*l1 + l2*l2 -b*b)/(2*l1*l2))); if (q1 > f1 ) { f2 = (f2-90); } else { f2 = 180 - (f2-90); }; println(f1, f2); arduino.servoWrite(7, (int)f1); arduino.servoWrite(4, (int)f2); delay(30); } endShape(); delay(500); exit();}