Coordinates are always rotated around their relative position to the origin.
rotateY(-yaw); // yaw
rotateX(pitch); // RotateX pitch value
rotateZ(-roll); // roll
float yaw;
float pitch;
float roll;
void setup()
{
size(600, 500, P3D);
textSize(16); // set text size
textMode(SHAPE); // set text mode to shape
pitch=0.0;
roll=0.0;
yaw=1.0;
}
void draw()
{
pitch = pitch +0.01;
yaw = yaw+0.0;
roll = roll +0.0;
background(255); // set background to white
translate(width/2, height/2); // set position to centre
pushMatrix(); // begin object
rotateY(-yaw); // yaw
rotateX(pitch); // RotateX pitch value
rotateZ(-roll); // roll
drawArduino(); // function to draw rough Arduino shape
popMatrix(); // end of object
// Print values to console
print(pitch);
print("\t");
print(roll);
print("\t");
print(-yaw);
println("\t");
}
void drawArduino() {
/* function contains shape(s) that are rotated with the IMU */
stroke(0, 90, 90); // set outline colour to darker teal
fill(0, 130, 130); // set fill colour to lighter teal
box(300, 10, 200); // draw Arduino board base shape
stroke(0); // set outline colour to black
fill(80); // set fill colour to dark grey
translate(60, -10, 90); // set position to edge of Arduino box
box(170, 20, 10); // draw pin header as box
translate(-20, 0, -180); // set position to other edge of Arduino box
box(210, 20, 10); // draw other pin header as box
}
Ouch! You right, sorry you loose all this time around. The arduino visualizer it's simply wrong.After much frustration with wrong results in Arduino's orientation visualizer example, I finally arrived at this conclusion:
Well, no so much.The arduino visualizer it's simply wrong.
maybe Kris will update his bakeoff with the prop shield sensors ....
I'm seriously considering adding cal of the accelerometer and gyro offsets to the cal app. Anyone have opinions or feedback about that?
Probably best to do so *after* the final calibration software is published.
I'm seriously considering adding cal of the accelerometer and gyro offsets to the cal app. Anyone have opinions or feedback about that?
// tty3d y p r 1 9 0 + -
float sign=1.0, delta=0.1;
float yaw;
float pitch;
float roll;
String message;
String [] ypr = new String [3];
void setup()
{
size(600, 500, P3D);
textSize(16); // set text size
textMode(SHAPE); // set text mode to shape
}
void draw()
{
background(255); // set background to white
lights();
translate(width/2, height/2); // set position to centre
pushMatrix(); // begin object
rotateY(-yaw); // yaw
rotateX(pitch); // RotateX pitch value
rotateZ(-roll); // roll
drawArduino(); // function to draw rough Arduino shape
popMatrix(); // end of object
}
void keyPressed()
{
if(key == 'y') yaw += sign*delta;
if(key == 'p') pitch += sign*delta;
if(key == 'r') roll += sign*delta;
if(key == '+') sign = 1.0;
if(key == '-') sign = -1.0;
if(key == '1') delta = 0.1;
if(key == '9') delta = 3.14159/4.; // 45 degrees
if(key == '0') roll=yaw=pitch= 0.0;
// Print values to console
print(pitch);
print("\t");
print(roll);
print("\t");
print(yaw);
println("\t");
}
void drawArduino() {
/* function contains shape(s) that are rotated with the IMU */
stroke(0, 90, 90); // set outline colour to darker teal
fill(0, 130, 130); // set fill colour to lighter teal
box(300, 10, 200); // draw Arduino board base shape
stroke(0); // set outline colour to black
fill(80); // set fill colour to dark grey
translate(60, -10, 90); // set position to edge of Arduino box
box(170, 20, 10); // draw pin header as box
translate(-20, 0, -180); // set position to other edge of Arduino box
box(210, 20, 10); // draw other pin header as box
}
I'd like to propose a UI detail: Don't tell the user to hold the board still for "n" seconds, instead tell the user to put the board on an even surface and then use the variance of the incoming data do determine if the prop shield is held "still enough". Don't use data if variance is too high, use it and signal the user to do whatever comes next if variance is low enough.I'm seriously considering adding cal of the accelerometer and gyro offsets to the cal app. Anyone have opinions or feedback about that?
instead tell the user to put the board on an even surface and then use the variance of the incoming data do determine if the prop shield is held "still enough".
import processing.serial.*;
Serial myPort;
int newLine = 13; // new line character in ASCII
float yaw;
float pitch;
float roll;
String message;
String [] ypr = new String [3];
void setup()
{
size(600, 500, P3D);
lights();
/*Set my serial port to same as Arduino, baud rate 9600*/
//myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE COM port active
myPort = new Serial(this, "/dev/ttyACM0", 9600); // if you know the 101 COM port
textSize(16); // set text size
textMode(SHAPE); // set text mode to shape
}
void draw()
{
serialEvent(); // read and parse incoming serial message
background(255); // set background to white
translate(width/2, height/2); // set position to centre
pushMatrix(); // begin object
float c1 = cos(-roll);
float s1 = sin(-roll);
float c2 = cos(pitch);
float s2 = sin(pitch);
float c3 = cos(-yaw);
float s3 = sin(-yaw);
applyMatrix( c2*c3, s1*s3+c1*c3*s2, c3*s1*s2-c1*s3, 0,
-s2, c1*c2, c2*s1, 0,
c2*s3, c1*s2*s3-c3*s1, c1*c3+s1*s2*s3, 0,
0, 0, 0, 1);
drawArduino(); // function to draw rough Arduino shape
popMatrix(); // end of object
// Print values to console
print(roll);
print("\t");
print(pitch);
print("\t");
print(-yaw);
println();
myPort.write("s"); // write an "s" to receive more data from Arduino
}
void serialEvent()
{
message = myPort.readStringUntil(newLine); // read from port until new line (ASCII code 13)
if (message != null) {
ypr = split(message, ","); // split message by commas and store in String array
yaw = float(ypr[0]); // convert to float yaw
pitch = float(ypr[1]); // convert to float pitch
roll = float(ypr[2]); // convert to float roll
}
}
void drawArduino() {
/* function contains shape(s) that are rotated with the IMU */
stroke(0, 90, 90); // set outline colour to darker teal
fill(0, 130, 130); // set fill colour to lighter teal
box(300, 10, 200); // draw Arduino board base shape
stroke(0); // set outline colour to black
fill(80); // set fill colour to dark grey
translate(60, -10, 90); // set position to edge of Arduino box
box(170, 20, 10); // draw pin header as box
translate(-20, 0, -180); // set position to other edge of Arduino box
box(210, 20, 10); // draw other pin header as box
}
Is it ok to post the source code or does this fall under the "no pictures" rule?
int fpsMillis = 0;
int fps = 0;
void setup()
{
size(600, 500, P3D);
textSize(16); // set text size
textMode(SHAPE); // set text mode to shape
sphereDetail(15);
}
void draw()
{
background(255); // set background to white
if (millis() - fpsMillis > 500) {
fpsMillis = millis();
fps = (int)frameRate;
}
fill(0);
text(fps + " fps",10,20);
translate(width/2, height/2, 200); // set position to centre
pushMatrix(); // begin object
rotateX( sin(millis()/700.f)/1.6 - 3.1415f/4 );
rotateY( sin(millis()/2000.f)/2);
drawPropShield();
popMatrix(); // end of object
}
void drawPropShield() {
stroke(0); // black outline
fill(0, 128, 0); // fill color PCB green
box(190, 6, 70); // PCB base shape
fill(255, 215, 0); // gold color
noStroke();
//draw 14 contacts on Y- side
translate(65, 0, 30);
for (int i=0; i<14; i++) {
sphere(4.5); // draw gold contacts
translate(-10, 0, 0); // set new position
}
//draw 14 contacts on Y+ side
translate(10, 0, -60);
for (int i=0; i<14; i++) {
sphere(4.5); // draw gold contacts
translate(10, 0, 0); // set position
}
//draw 5 contacts on X+ side (DAC, 3v3, gnd)
translate(-10,0,10);
for (int i=0; i<5; i++) {
sphere(4.5);
translate(0,0,10);
}
//draw 4 contacts on X+ side (G C D 5)
translate(25,0,-15);
for (int i=0; i<4; i++) {
sphere(4.5);
translate(0,0,-10);
}
//draw 4 contacts on X- side (5V - + GND)
translate(-180,0,10);
for (int i=0; i<4; i++) {
sphere(4.5);
translate(0,0,10);
}
//draw audio amp IC
stroke(128);
fill(24); //Epoxy color
translate(30,-6,-25);
box(13,6,13);
//draw pressure sensor IC
stroke(64);
translate(32,0,0);
fill(192);
box(10,6,18);
//draw gyroscope IC
stroke(128);
translate(27,0,0);
fill(24);
box(16,6,16);
//draw flash memory IC
translate(40,0,-15);
box(20,6,20);
//draw accelerometer/magnetometer IC
translate(-5,0,25);
box(12,6,12);
//draw 5V level shifter ICs
translate(42.5,2,0);
box(6,4,8);
translate(0,0,-20);
box(6,4,8);
}
I managed to change the visualizer to use intrinsic roll, pitch, yaw.
Looks like the visualizers *and* Madgwick filter are using the same external frame Euler angle references.
If you run Madgwick and just watch the data, you can see spinning Teensy + Prop Shield on axis of the USB cable gives roll when the board is oriented one way, but it give pitch when you change the heading/yaw orientation by 90 degrees.
... reports it as pitch if you're flying towards Los Angles, but consides it roll when you're heading towards New York, or some of both if you're flying to Miami.