如何计算手机从静止状态到垂直方向的移动量?
我正在使用 android 操作系统开发一个应用程序,我需要知道如何计算设备在垂直方向上的移动。
例如,设备处于静止状态(A点),用户将其拿在手中(B点),现在A点和B点之间存在高度变化,我将如何计算?
我已经阅读了有关传感器和加速度计的文章,但我找不到任何可以帮助我的内容。有人有什么想法吗?
I am developing an app using android OS for which I need to know how can I calculate the movement of the device up in the vertical direction.
For example, the device is at rest (point A), the user picks it up in his hand (point B), now there is a height change between point A and point B, how would i calculate that?
I have already gone through the articles about sensors and accelerometers, but I couldn't really find anything to help me with that. Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你对加速度进行两次积分,你就可以得到位置,但误差是可怕的。在实践中是没有用的。以下是 23:20 的原因说明(Google 技术讲座)。我强烈推荐这个视频。
现在,您不需要任何准确的东西,那是另一回事了。如视频中所述,传感器融合后即可获得线性加速度。请参阅 SensorEvent 处的
Sensor.TYPE_LINEAR_ACCELERATION
。我首先尝试使用高通滤波器来检测线性的突然增加沿垂直轴的加速度。我不知道这是否适合你的申请。
If you integrate the acceleration twice you get position but the error is horrible. It is useless in practice. Here is an explanation why (Google Tech Talk) at 23:20. I highly recommend this video.
Now, you do not need anything accurate and that is a different story. The linear acceleration is available after sensor fusion, as described in the video. See
Sensor.TYPE_LINEAR_ACCELERATION
at SensorEvent. I would first try a high-pass filter to detect sudden increase in the linear acceleration along the vertical axis.I have no idea whether it is good for your application.
您实际上可以(仅)确定垂直位置,而无需测量随时间变化的加速度。这是通过测量地心方向和磁北极方向之间的角度来实现的。
仅当手机的海拔(高度)发生变化时,该值才会发生(显着)变化。您要做的就是使用加速度计和磁力计获取两个 float[3] 数组,将它们视为向量,将它们设为单位向量,然后计算任意两个单位之间的角度向量是 arccos(AxM)。
请注意,这是点积,即。
math.acos(A[0]*B[0]+A[1]*B[1]+A[2]*B[2])
这个角度的任何变化都对应着一个变化在高度上。另请注意,这必须校准为实际单位,并且角度与高度的变化比率在不同的经度上会有所不同;但这是一种获取高度绝对值的方法;当然,当经历加速或附近有磁铁时,角度也会变得倾斜:)You can actually establish (only) the vertical position without measuring acceleration over time. This is accomplished by measuring the angle between the direction to the center of the earth, and the direction to the magnetic north pole.
This only changes (significantly) when the altitude (height) of the phone changes. What you do is use the
accelerometer
andmagnetometer
to get two float[3] arrays, treat these as vectors, make them unit vectors, and then the angle between any two unit vectors is arccos(AxM).Note that's dot product ie.
math.acos(A[0]*B[0]+A[1]*B[1]+A[2]*B[2])
Any change in this angle corresponds to a change in height. Also note that this will have to be calibrated to real units and the ratio of change in angle to height will be different at various longitudes; But this is a method of getting an absolute value for height; though of course the angle also becomes skewed when undergoing acceleration, or when there are nearby magnets :)您可以将其与 microTesla 中的磁场传感器相关联
您可以使用 dist= 加速度积分 ~ sigma ~ 求和的积分
= 速度积分+常数
you can correlate it to magnetic field sensor in microTesla
You can use dist= integral of integral of acceleration ~ sigma ~ summation
= integral of speed+constant