简体   繁体   English

从没有磁力计的设备获取音高

[英]Getting pitch from devices that dont have magnetometer

I need to get the orientation of the device(pitch to be specific), I am using a method that involves implementing SensorEventListener the accelerometer and the magnetometer 我需要获取设备的方向(具体来说是音高),我使用的方法涉及实现SensorEventListener加速度计和磁力计

The problem is some devices dont have the magnetometer(I stumbled upon the samsung J7 and J5 but assuming there are more), all other devices i tested work like a charm. 问题是某些设备没有磁力计(我偶然发现了三星J7和J5,但假设还有更多的话),我测试过的所有其他设备都具有吸引力。 now i do know these devices dont have a magnetometer so i tried registering the deprecated "TYPE_ORIENTATION" event and the "TYPE_ROTATION_VECTOR" event but none work. 现在,我确实知道这些设备没有磁力计,因此我尝试注册不推荐使用的“ TYPE_ORIENTATION”事件和“ TYPE_ROTATION_VECTOR”事件,但均无用。

All i get on those devices is the event from accelerometer. 我在这些设备上得到的只是来自加速度计的事件。

I know it is possible because i have downloaded bubble level apps on these phones and they work(compass dosent) Thanks 我知道这是有可能的,因为我已经在这些手机上下载了气泡级应用程序,并且它们可以正常工作(包括剂量)谢谢

Edit: I need to scroll views by tilting the phone, so i need to calibrate once and than know if the pitch is bigger or smaller then initial calibration 编辑:我需要通过倾斜手机来滚动视图,所以我需要校准一次,然后才知道音调是大还是小,然后进行初始校准

You need to low pass filter accelerometer to get the gravity vector. 您需要使用低通滤波器加速度计来获取重力矢量。

float[] gravity = low pass filter accelerometer

Calculate the norm of the gravity 计算引力的范数

float gravityNorm = calculate the norm of gravity.

Then pitch would be 那么音调将是

(float) Math.asin(-gravity[1] / gravityNorm))

For the formula above read the document for TYPE_PITCH in the class DSensor in my project DSensor at https://github.com/hoananguyen/dsensor 对于上面的公式,请阅读https://github.com/hoananguyen/dsensor我的项目DSensor中DSensor类中TYPE_PITCH的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM