Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compass heading from deviceorientation
Message
De
24/04/2014 11:14:44
 
 
À
24/04/2014 10:59:16
Information générale
Forum:
HTML5
Catégorie:
Problèmes de navigateur
Divers
Thread ID:
01598938
Message ID:
01598980
Vues:
30
>>
>>With that correction the heading does seems to remain fairly constant regardless of beta and gamma values. But changes on the x axis still result in the skip :-{
>>H
>
>
>Can you post the values of( alpha, beta, gamma , absolute) before and those that produce a 'skip' ?
>
>Update : and your current code

result: 83.22823217922902 alpha:192.3341040127786 beta: -0.397645519862364 gamma: -4.076214696522571
result: 275.89877882326147 alpha:167.6809889302929 beta: 0.4615772773377466 gamma: -4.0949466064380005

with a minute movement between the two consecutive readings. I note the beta went positive on the second result....

Current code:
function compassHeading2(alpha, beta, gamma , absolute) {

    var _x = beta ? beta * degtorad : 0; // beta value
    var _y = gamma ? gamma * degtorad : 0; // gamma value
    var _z = alpha ? alpha * degtorad : 0; // alpha value

    var cX = Math.cos(_x);
    var cY = Math.cos(_y);
    var cZ = Math.cos(_z);
    var sX = Math.sin(_x);
    var sY = Math.sin(_y);
    var sZ = Math.sin(_z);

    // Calculate Vx and Vy components
    var Vx = -cZ * sY - sZ * sX * cY;
    var Vy = -sZ * sY + cZ * sX * cY;

    // Calculate compass heading
    //var compassHeading = Math.atan(Vx / Vy);
    var compassHeading = Math.atan2(Vx ,Vy);

    // Convert compass heading to use whole unit circle
    if (Vy < 0) {
        compassHeading += Math.PI;
    } else if (Vx < 0) {
        compassHeading += 2 * Math.PI;
    }

    return compassHeading * (180 / Math.PI); // Compass Heading (in degrees)
}
called from orientation changed event:
lastOrientation = compassHeading2(data.alpha, data.beta, data.gamma, data.absolute);
            console.log('result: ' + lastOrientation + 'alpha:'+data.alpha+ ' beta: '+data.beta + ' gamma: '+data.gamma);
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform