2016-12-08 2 views
0

c'est une partie du code, qui visualise la rotation de mon arduino. Malheureusement, le rouleau est "inversé" ... Il est appelé chaque tick avec des valeurs mises à jour.Transformation Matrix (roll inversed?)

Par inversé je veux dire: Si je roule l'arduino vers la droite, la visualisation le fait rouler vers la gauche et vice versa.

pushMatrix(); // begin object 
translate(width/4, height/4); // set position 
float c1 = cos(radians(roll)); 
float s1 = sin(radians(roll)); 
float c2 = cos(radians(pitch)); 
float s2 = sin(radians(pitch)); 
float c3 = cos(radians(yaw)); 
float s3 = sin(radians(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(); 
popMatrix(); // end of object 

Quelqu'un voit-il l'erreur que j'ai faite?

Voici comment je calculer les valeurs que je passe dans la matrice:

int aix, aiy, aiz, tax, tay, taz; 
int gix, giy, giz; 
float ax, ay, az; 
float gx, gy, gz; 
float roll, pitch, heading; 

CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz); 

// convert from raw data to gravity and degrees/second units 
ax = convertRawAcceleration(aix); 
ay = convertRawAcceleration(aiy); 
az = convertRawAcceleration(aiz); //acceleration for 2g 
gx = convertRawGyro(gix); 
gy = convertRawGyro(giy); 
gz = convertRawGyro(giz); 

// update the filter, which computes orientation 
filter.updateIMU(gx, gy, gz, ax, ay, az); 


// print the heading, pitch and roll 
roll = filter.getRoll(); 
pitch = filter.getPitch(); 
heading = filter.getYaw(); 

Répondre

0

Une option consiste à inverser la valeur du rouleau: cela peut être fait en soustrayant la valeur de roulis de la valeur maximale qu'il peut avoir

inverted = max - current 

Je vois que vous utilisez degrés, alors voici la démo que vous pouvez exécuter la façon d'inverser la valeur en supposant que votre valeur maximale est de 360:

  • cliquez et faites glisser pour tourner
  • appuyer sur une touche pour inverser la rotation

var roll, pitch, yaw; 
 

 
var maxRoll = 360; 
 
var invertRoll = false; 
 

 

 
function setup(){ 
 
    createCanvas(300,300); 
 
    rectMode(CENTER); 
 
} 
 
function draw(){ 
 
    var rollValue = roll; 
 
    if(invertRoll){ 
 
    
 
    rollValue = maxRoll - roll; 
 
    
 
    background(0); 
 
    }else{ 
 
    background(255); 
 
    } 
 
    
 
    background(invertRoll ? color(0) : color(255)); 
 
    translate(width * 0.5, height * 0.5); 
 
    rotate(radians(rollValue)); 
 
    rect(0,0,100,100); 
 
} 
 

 
function mouseDragged(){ 
 
    roll = map(mouseX,0,width,0,360); 
 
} 
 

 
function keyPressed(){ 
 
    invertRoll = !invertRoll; 
 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.5/p5.min.js"></script>

Si elle aide, voici une esquisse de test de traitement en fonction de votre extrait ci-dessus:

float roll, pitch, yaw; 

float maxRoll = 360; 
boolean invertRoll; 

void setup() { 
    size(400,400,P3D); 
} 

void draw() { 
    background(255); 

    pushMatrix(); // begin object 
    translate(width/4, height/4); // set position 

    float rollValue = roll; 

    if(invertRoll) rollValue = maxRoll - roll; 

    float c1 = cos(radians(rollValue)); 
    float s1 = sin(radians(rollValue)); 

    float c2 = cos(radians(pitch)); 
    float s2 = sin(radians(pitch)); 
    float c3 = cos(radians(yaw)); 
    float s3 = sin(radians(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(); 
    popMatrix(); // end of object 
} 

void drawArduino() { 
    box(100); 
} 

void mouseDragged(){ 
    roll = map(mouseX,0,width,0,360); 
} 

void keyPressed(){ 
    invertRoll = !invertRoll; 
} 

Une autre option consiste à mettre à l'échelle l'axe que vous voulez inverser par -1 puis traduisez pour reculer à la position que vous voulez dessiner.

+0

fonctionne comme un charme, merci beaucoup. –