Skip to content

Instantly share code, notes, and snippets.

@shurru
Created November 7, 2014 05:09
Show Gist options
  • Save shurru/da1fa8c4451d0fe7f236 to your computer and use it in GitHub Desktop.
Save shurru/da1fa8c4451d0fe7f236 to your computer and use it in GitHub Desktop.
Robot IMU
import processing.serial.*;
Serial myPort;
int count = 1;
float roll1,pitch1,yaw1;
float [] roll_1= new float[999999];
float [] pitch_1= new float[999999];
float [] yaw_1= new float[999999];
///////////////////////////////////////////////////////////////////
//robot variables
int armAngle = 0;
void setup(){
size(displayWidth, displayHeight);
background(0);
smooth();
frameRate(30);
myPort = new Serial(this, Serial.list()[0], 115200);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
}
void draw(){
background(255);
pushMatrix();
translate(50,50);
robot();
popMatrix();
}
void robot(){
left();
right();
noStroke();
line(550,0,550,800);
stroke(255);
line(1100,0,1100,800);
stroke(#F7F000);
//robot body
fill(38, 38, 200);
rect(200,100,150,150);
//abdomen
fill(#EE05FF);
rect(180,560,80,250);
fill(#044252);
rect(270,560,80,250);
//end
stroke(0);
}
void left(){
pushMatrix();
translate (150,275);
rotate(radians(pitch1));
rect(-60,0,50,200);
popMatrix();
}
void right(){
fill(#FA0505);
pushMatrix();
translate(410,275);
rotate(radians (-pitch1));
rect(0,0,50,200);
popMatrix();
}
void serialEvent( Serial myPort){
String inString = new String(myPort.readBytesUntil('\n'));
// t =inString.length();
if (inString== null)
{
println("You got NULL");
}
if (inString != null){
println("Hello i'm q.length");
String[] q = splitTokens(inString, "\\\t ");
println(q.length + " values found"); // Prints "4 values found"
roll1=float(q[3]);
pitch1=float(q[4]);
yaw1=float(q[5]);
// println(yaw1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment