java 如何在android中校准方向传感器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3174309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:41:27  来源:igfitidea点击:

how to calibrate the orientation sensor in android?

javaandroidandroid-sensors

提问by xenonite

I'm writing an app in Google Android 2.1 that needs to know which direction (n/w/s/e) the device (HTC Hero) is facing. The sensor and its listener are working great, but the values I get from the sensor are totally crappy. e.g. it tells me I'd be facing north when the device is facing SW or so...

我正在 Google Android 2.1 中编写一个应用程序,它需要知道设备 (HTC Hero) 面向哪个方向 (n/w/s/e)。传感器及其侦听器运行良好,但我从传感器获得的值非常糟糕。例如,它告诉我当设备面向 SW 左右时我将面向北......

This seems to be a known problem with android devices. The "solutions" I found on the web look like this:

这似乎是 android 设备的一个已知问题。我在网上找到的“解决方案”如下所示:

  • shake the device around
  • move the device like an eight
  • tap on the devices back
  • 摇晃设备
  • 移动设备像八
  • 点按设备返回

This is thought to trigger the sensors recalibration. And: the thing with the "moving around" works for me... but that's not very professional I guess...

这被认为会触发传感器重新校准。并且:“四处走动”的东西对我有用......但我想这不是很专业......

so - how do I trigger the recalibration of the orientation sensor from the SDK? I need the sensor to be properly calibrated without any fancy stuff that would make users of this app look like complete idiots while they are "manually" recalibrating their phones...

那么 - 如何从 SDK 触发方向传感器的重新校准?我需要正确校准传感器,没有任何花哨的东西会让这个应用程序的用户在“手动”重新校准手机时看起来像个白痴......

Is there any way to do this "right"?

有没有办法做到这一点“正确”?

EDIT:

编辑:

Or: is there any way to determine PROGRAMMATICALLY, if the device is correctly calibrated or not? As a fallback-option so to speak... then I could warn the user that the device needs "manual" recalibration.

或者:有没有办法以编程方式确定设备是否正确校准?作为后备选项,可以这么说......然后我可以警告用户该设备需要“手动”重新校准。

回答by Morrison Chang

I don't believe there is a way to know programatically if you compass sensor is calibrated correctly unless you use a secondary data source like GPS. If you can use GPS then when the user is moving you can compare the GPS movement with the compass heading and correct. Remember that local magnetic fields can screw up the compass readings and the devices has no idea if you are out in the middle of a forest or next to a transformer.

我不相信有一种方法可以通过编程方式知道罗盘传感器是否正确校准,除非您使用 GPS 等辅助数据源。如果您可以使用 GPS,那么当用户移动时,您可以将 GPS 移动与罗盘航向进行比较并进行校正。请记住,本地磁场可能会破坏罗盘读数,并且设备不知道您是在森林中间​​还是在变压器旁边。

With these micro devices there is always a bit of skew you'll have to deal with. If you check the values for the accelerometer as well you'll see that at rest they aren't always returning 9.8 m/s^2 (or at least consistently between devices).

对于这些微型设备,您总是需要处理一些偏差。如果您还检查加速度计的值,您会发现在静止状态下它们并不总是返回 9.8 m/s^2(或至少在设备之间保持一致)。

In your help you may just need to tell the user to rotate/twist their phone in a figure eight to reset the compass.

在您的帮助下,您可能只需要告诉用户以 8 字形旋转/扭转他们的手机以重置指南针。

回答by Johannes Rudolph

I assume you are referring to the Magnetometer inside the Hero.

我假设您指的是 Hero 内部的磁力计。

Callibrating it is a tough one and will/should always require user interaction for a realiable callibration. There are seperate strategies to deal with that. You could ask users to hold there device in north direction and then recallibrate. If the users don't know where north is, you can ask them to direct zhe device towards the sun and based on location and time you can calculate where that is.

校准它是一项艰巨的任务,并且将/应该始终需要用户交互才能实现真正的校准。有单独的策略来解决这个问题。您可以要求用户将设备朝北方向握住,然后重新调整。如果用户不知道北方在哪里,您可以让他们将设备对准太阳,并根据位置和时间计算出该设备的位置。

Leaving callibration aside, I would guess that your problem is that the readings you get from the sensor are inaccurate. Of course callibration is a prerequisite for accurate readings, but there are also other factors in play.

撇开校准不谈,我猜您的问题是您从传感器获得的读数不准确。当然,校准是准确读数的先决条件,但还有其他因素在起作用。

It is common practice to complement sensor data from one sensor with the data a different sensor to increase accuracy. You could use the GPS to determine a heading when the user is moving. If he's moving slowly however, this is inaccurate as well. You could integrate the data reported by the Accelerometer to guess about orientation changes (not the absolute orientation). But honestly a Gyrometer would be more ideal in this case.

通常的做法是将来自一个传感器的传感器数据与来自不同传感器的数据进行补充以提高准确性。您可以使用 GPS 来确定用户移动时的航向。然而,如果他移动缓慢,这也是不准确的。您可以整合加速度计报告的数据来猜测方向变化(而不是绝对方向)。但老实说,在这种情况下,陀螺仪会更理想。

Systems that work like this are sometimes called Inertial Navigation Systems(INS) because they can, given a fixed point in space, determine their subsequent relative position and orientation accurately without further external data. Using a Kalman filter is common practice to recallibrate the system from time to time when an absolute position (e.g. retrieved via GPS) is available.

像这样工作的系统有时被称为惯性导航系统(INS),因为它们可以在给定空间中的一个固定点的情况下,准确地确定其随后的相对位置和方向,而无需进一步的外部数据。当绝对位置(例如通过 GPS 检索)可用时,使用卡尔曼滤波器是经常重新调整系统的常见做法。

Although it is unrealistic to implement a full-fledged INS, you can certainly draw a few ideas from how they work to make your orientation readings more accurate.

尽管实施成熟的 INS 是不现实的,但您当然可以从它们的工作原理中汲取一些想法,以使您的方向读数更加准确。