对于一个项目,我需要检测 Android 设备的倾斜度(俯仰)。为此,我使用了加速度传感器和磁场传感器,一切正常。该装置能够悬卡在钟摆上向前和向后移动。如果我有摆/设备的角度,我可以计算加速度。问题是:所有这些都只能静止不动。如果该设备位于行驶中的汽车中,则它不再起作用。当汽车制动时,摆锤向前移动,倾斜度发生变化,但设备无法检测到这一点,因为力仍然沿 y 轴“向下”作用。
这种情况下是否可以检测倾斜角度?
不确定我是否清楚地解释了我的问题。我需要的是由设备传感器检测到的移动钟摆的角度。
<<编辑>>
我需要的是正确测量的摆锤角度,即使它位于移动的汽车内(请查看我的 Dropbox 中的 pdf 文件): https://dl.dropboxusercontent.com/u/5655235/sensors.pdf
正如您在图像上看到的,如果盒子正在加速,测量的角度不正确。
这是我的代码:
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
acc = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
mag = event.values;
if (acc != null && mag != null) {
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, acc, mag);
if (success) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
phiRad = orientation[1];
phi = Math.toDegrees(phiRad);
}
}
最佳答案
我希望我正确理解你的问题!所以你想检测设备在行驶的汽车中时的倾斜度...
首先,当你这么说时:
When the car is braking, the pendulum moves forward and the inclination changes, but the device cannot detect that because the force is still acting "downward" along the y-axis.
您确定设备保持垂直吗?
因此,当汽车移动时,摆锤将获得汽车向前方向的加速度。这里,向前并不意味着它指向设备的 x 轴,而是指向汽车/表面的 x 轴。根据我的理解,您正在尝试检查摆锤向 x 轴的运动,但您应该检查设备的位置。如果我正确理解你的问题,希望它能有所帮助。
关于java - android:检测设备倾斜角度的主要问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27609334/