Closed jhasse closed 8 years ago
Okay the reason it fails, is that magnet
is a null vector when the device doesn't have a magnetic sensor. This results in normH
being 0 here and thus getRotationMatrix
returning false. Thus SensorManger.getOrientation
never gets called in this function:
// calculates orientation angles from accelerometer and magnetometer output
public void calculateAccMagOrientation() {
if (SensorManager.getRotationMatrix(rotationMatrix, null, accel, magnet)) {
SensorManager.getOrientation(rotationMatrix, accMagOrientation);
}
}
MainActivity.java
is only using accMagOrientation[1]
here. getOrientation
sets this to Math.asin(-rotationMatrix[7])
here. rotationMatrix[7]
is set to
gravity[1] / Math.sqrt(gravity[0]*gravity[0]+gravity[1]*gravity[1]+gravity[2]*gravity[2])
here. gravity
is accel
in MainActivity.java
.
To sum it up, the magnet sensor information isn't used at all. The calls to getRotationMatrix
and getOrientation
are unnecessary.
Many users report that gas and brake work, but steering doesn't.