从磁传感器获取信息

发布于 2024-10-05 12:32:28 字数 358 浏览 7 评论 0原文

我正在监听传感器值,并在我的处理程序中让它们正常,

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
       for (i=0;i<3; i++) mag[i] = event.values[i];

开发人员文档说对于 Sensor.TYPE_MAGNETIC_FIELD 你会得到: “所有值均以微特斯拉 (uT) 为单位,并测量 X、Y 和 Z 轴上的环境磁场。”

如何将这些信息转换为方位角、俯仰角和横滚角?如何将其转换为指南针磁航向?

完成矩阵变换后,是否只提供从方向传感器和加速度传感器获得的相同信息?

I'm listening for sensor values, and getting them OK in my handler with

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
       for (i=0;i<3; i++) mag[i] = event.values[i];

The developer docs say for Sensor.TYPE_MAGNETIC_FIELD you get:
"All values are in micro-Tesla (uT) and measure the ambient magnetic field in the X, Y and Z axis."

How can I turn that info into azimuth, pitch, and roll? How do I turn it into compass magnetic heading?

Does just provide the same info you can get from the ORIENTATION sensor, and from the ACCELEROMETER sensor once you have done the matrix transforms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2024-10-12 12:32:28

如果您有权访问加速度计,则可以使用 getOrientation()
方法,返回由两个传感器确定的方位角、俯仰角和横滚角,并通过 getRotationMatrix 计算() 方法。

编辑

对评论的回复...我现在看到你的问题了。对不起。仅使用 3 轴磁力计,除非设备平行于地球表面,否则无法准确获取方位角、俯仰角和横滚角。还记得使用针罗盘并将其a)放在主轴上,这样您就可以看到并手动补偿倾斜,或者b)密封在液体中,这样您就可以将气泡水平仪置于中心?获取方位角:

azimuth = arctan(y/x)

现在,如果倾斜手机,x/y 平面感应的误差可能会变大。现在你需要算出倾斜度(用加速度计),然后测量Z轴磁场强度,然后用三者来补偿。这本质上就是您所知道的 getRotationMatrix() 和 getOrientation()。

我认为 Sensor.TYPE_ORIENTATION 在 API 8 中被弃用的部分原因是因为没有单独的方向传感器本身。它是磁场和加速度传感的组合。

我发现的一篇很好的论文涵盖了所有内容:

http://www .ssec.honeywell.com/position-sensors/datasheets/sae.pdf

If you have access to the accelerometer, you can use the getOrientation()
method, which returns azimuth, pitch, and roll as determined from the two sensors, and calculated via the getRotationMatrix() method.

EDITS

Response to comments... I see your question now. Sorry. With just the 3-axis magnetometer, you can't accurately get azimuth, pitch, and roll except when the device is parallel to the surface of the earth. Remember using a needle compass and having it either a) on a spindle so you can see and manually compensate for tilt, or b) sealed in liquid so you can get the bubble level to the center? To get azimuth:

azimuth = arctan(y/x)

Now, if you tilt the phone, the errors in the x/y plane sensing can get big. Now you need to figure out the tilt (with the accelerometer), then measure the Z-axis magnetic strength, and then use the three to compensate. This is essentially what you know as getRotationMatrix() and getOrientation().

Part of the reason I think Sensor.TYPE_ORIENTATION was deprecated in API 8 was because there isn't a separate orientation sensor per se. It is a combination of magnetic field and acceleration sensing.

A good paper that I dug up that covers it all:

http://www.ssec.honeywell.com/position-sensors/datasheets/sae.pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文