import processing.serial.*;
Serial puerto;
int dato;
void setup() {
puerto = new Serial(this, Serial.list()[0], 56000);
}
void serialEvent(Serial puerto)
{
dato = puerto.read();
}
void draw(){
println(dato);
}import processing.serial.*;
Serial myPort; // The serial port
float acc_angle=0;
float gyro_angle=0;
float angle=0;
void setup()
{
size(650,300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.write("m\r");
}
void draw ()
{
while (myPort.available() > 0)
{
String recibido = myPort.readStringUntil('\n');
if (recibido != null)
{
float[] val = float(split(recibido,","));
drawGraph(val);
}
}
}
void drawGraph(float[] val)
{
float x_acc = (val[0]-513)/97;
float y_acc = (val[1]-500)/105;
float z_acc = -(val[2]-511)/103;
float gyro = -(val[3]-455)/67; //*0.015;
float dt=0.1;
acc_angle = atan(z_acc/y_acc);
gyro_angle += gyro * dt;
angle = (0.95)*(angle + gyro * dt) + (0.05)*(acc_angle);
stroke(0);
background(255);
rectMode(CENTER);
textSize(14);
pushMatrix();
fill(255,100,100);
translate(100, 200);
text("acc angle = " + degrees(acc_angle) + "º" ,-90,-100);
rotate(acc_angle);
rect(0, 0, 100, 30);
popMatrix();
pushMatrix();
fill(100,255,100);
translate(300, 200);
text("gyro angle = " + degrees(gyro_angle) + "º" ,-90,-100);
rotate(gyro_angle);
rect(0, 0, 100, 30);
popMatrix();
pushMatrix();
fill(100,100,255);
translate(500, 200);
text("filtered angle = " + degrees(angle) + "º" ,-90,-100);
rotate(angle);
rect(0, 0, 100, 30);
popMatrix();
/*strokeWeight(10);
line(width/2 , height/2 +100, width/2 + v.x , height/2 + v.y +100);*/
}printf("%li,%li,%li,%li,%li,\n",val[0],val[1],val[2],val[3],val[4]);float[] val = float(split(recibido,","));import processing.serial.*;
Serial myPort; // The serial port
int i = 0; // counter
void setup()
{
size(800, 600);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600); // Serial.list()[0] modify that number if don't works
background(255,255,255);
//myPort.write(83);
}
void draw ()
{
while (myPort.available() > 0)
{
String a0 = myPort.readStringUntil('\n');
if (a0!=null)
{
float[] val = float(split (a0, ","));
//println (val[0] + "," + val[1] + "," + val[2]);
drawGraph_accel(val[0]*100,val[1]*100,val[2]*100); //100 is a scale factor
}
}
}
void drawGraph_accel (float d_ax, float d_vx, float d_px)
{
stroke(255,0,0,70);
line(i, height/4, i, height/4 - d_ax);
stroke(0,0,255,70);
line(i, height/4*2, i, height/4*2 - d_vx);
stroke(0,255,0,70);
line(i, height/4*3, i, height/4*3 - d_px);
if (i >= width-2)
{
i = 0;
background(255,255,255);
}
else
{
i++;
}
}printf(" %u ", datoentero); dato = puerto.read();
printf("%u\n",datoentero);String myString = null;
...
myString = myPort.readStringUntil(lf);float var1=3.14, var2=5.2, var3=6.4;
printf("%f,%f,%f,\n",var1,var2,var3);float[] val = float(split (a0, "\n"));
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1
at Medicion_angulo.drawGraph(Medicion_angulo.java:53)
at Medicion_angulo.draw(Medicion_angulo.java:46)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)printf("%f, %f, \r",anggrad,angacelgrad); //imprimo datos por puerto serieimport processing.serial.*;
Serial myPort; // The serial port
float acc_angle=0;
float gyro_angle=0;
float angle=0;
void setup()
{
size(650,300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 56000);
myPort.write("m\r");
}
void draw ()
{
while (myPort.available() > 0)
{
String recibido = myPort.readStringUntil('\n');
if (recibido != null)
{
float[] val = float(split(recibido,","));
drawGraph(val);
}
}
}
void drawGraph(float[] val)
{
acc_angle = ((val[1])*PI/180.0);
gyro_angle = ((val[0])*PI/180.0);
stroke(0);
background(255);
rectMode(CENTER);
textSize(14);
pushMatrix();
fill(255,100,100);
translate(100, 200);
text("acc angle = " + degrees(acc_angle) + "º" ,-90,-100);
rotate(acc_angle);
rect(0, 0, 100, 30);
popMatrix();
pushMatrix();
fill(100,255,100);
translate(300, 200);
text("gyro angle = " + degrees(gyro_angle) + "º" ,-90,-100);
rotate(gyro_angle);
rect(0, 0, 100, 30);
popMatrix();
pushMatrix();
fill(100,100,255);
translate(500, 200);
text("filtered angle = " + degrees(angle) + "º" ,-90,-100);
rotate(angle);
rect(0, 0, 100, 30);
popMatrix();Código: [Seleccionar]printf("%f, %f, \r",anggrad,angacelgrad); //imprimo datos por puerto serie
printf("%f,%f,\n",anggrad,angacelgrad);while(getc() != 'm');
...resto del codigo