Wrong acceleration.x values in degree


#1

I want to simply detect and output the tilt value of the phone with the deviceMotion.

Im using Math.round(((acceleration.x) / 9.81) * 90) to turn the 1-10 x values into 0-90 degree.

It’s working fine but somehow if I’m tilting it to 45 degree its shows me about 27 degree.

does anyone know why?

my controller:

.controller('DiagWinkelACtrl', function($scope,$state,$rootScope) {

$scope.myDeg = 90;

$rootScope.getDiagWinkelAData = function() {
$('#DZB_winkel_a').val($scope.myDeg);
$('#DZB_winkel_a').change();
$state.go('tab.diagz');
};


document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

function onSuccess(acceleration) {
    var element = document.getElementById('accX');
    iDeg  = Math.round(((acceleration.x) / 9.81) * 90);
    myDeg = 90;
    if(iDeg > 0) {
        myDeg = 90 - iDeg;
    } else {
        myDeg = 90 + iDeg;
    }

    element.innerHTML  = myDeg + '°';
    $('img#daDreh').css('transform', 'rotate('+iDeg+'deg)').css('transition', '300ms linear all');
    $scope.myDeg = myDeg;
};

function onError() {
    alert('onError!');
};

var options = { frequency: 300 };  // Update every 3 seconds

var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
}

#2

just for better understanding here a screen from my App.

the degree values are not accurate / right if I’m tilting the phone… only 90° and 0° are pretty much right.


#3

No one can help me with this?