Android手机的方向概述,包括指南针指南针、方向、手机、Android

由网友(心稳路正)分享简介:我一直在试图让我的头围绕Android的方向传感器一段时间。我想我明白了。然后我意识到我没有。现在我认为(希望)我有一个更好的感觉了一遍,但我仍然不是100%。我会尽量解释它在我的片状的理解,希望人们将能够纠正我,如果我错了,在零件或填写任何空白。I've been trying to get my head ar...

我一直在试图让我的头围绕Android的方向传感器一段时间。 我想我明白了。然后我意识到我没有。现在我认为(希望)我有一个更好的感觉了一遍,但我仍然不是100%。我会尽量解释它在我的片状的理解,希望人们将能够纠正我,如果我错了,在零件或填写任何空白。

I've been trying to get my head around the Android orientation sensors for a while. I thought I understood it. Then I realised I didn't. Now I think (hope) I have a better feeling for it again but I am still not 100%. I will try and explain my patchy understanding of it and hopefully people will be able to correct me if I am wrong in parts or fill in any blanks.

我想我站在0度经线(本初子午线)和0度纬度(赤道)。这个位置实际上是在外海非洲海岸,但多多包涵。我认为我的手机在我的面前,使手机指向我的脚的底部;我对着北(朝看格林尼治)手机点向东部非洲等于是右侧。在该取向(参照下图)予有X轴指向东方,Z轴指​​向南方,Y轴指向天空。

I imagine I am standing at 0 degrees longitude (prime meridian) and 0 degrees latitude (equator). This location is actually in the sea off the coast of Africa but bear with me. I hold my phone in front of my face so that the bottom of the phone points to my feet; I am facing North (looking toward Greenwich) so therefore the right hand side of the phone points East towards Africa. In this orientation (with reference to the diagram below) I have the X-axis pointing East, the Z-axis is pointing South and Y-axis point to the sky.

现在手机上的传感器,让您的工作出了设备的方向(不是位置)在这种情况下。这部分一直困惑我,可能是因为我想了解的东西的工作之前,我接受了,它并只是工作。看来,手机的工作原理采用了两种不同技术的组合它的方向。

Now the sensors on the phone allow you to work out the orientation (not location) of the device in this situation. This part has always confused me, probably because I wanted to understand how something worked before I accepted that it did just work. It seems that the phone works out its orientation using a combination of two different techniques.

在我得到的是,想象回来站在土地虚片在0度经度和纬度站在上面提到的方向。也想像你正蒙住眼睛和你的鞋子固定在操场迂回。如果有人塞到你在后面你会爱上向前(朝向北),把双手出来,打破你的坠落。同样,如果有人塞到你的左肩,你会跌倒在你的右手。你的内耳有重力感应(YouTube视频),让你可以,如果你发现落前进/后退,或下降左/右或跌倒(或向上!)。因此,人类可以探测定位和左右旋转的相同的X和Z轴的手机。

Before I get to that, imagine being back standing on that imaginary piece of land at 0 degrees latitude and longitude standing in the direction mentioned above. Imagine also that you are blindfolded and your shoes are fixed to a playground roundabout. If someone shoves you in the back you will fall forward (toward North) and put both hands out to break your fall. Similarly if someone shoves you left shoulder you will fall over on your right hand. Your inner ear has "gravitational sensors" (youtube clip) which allow you to detect if you are falling forward/back, or falling left/right or falling down (or up!!). Therefore humans can detect alignment and rotation around the the same X and Z axes as the phone.

现在想象现在的人,你旋转在旋转木马上90度,让你现在面临的地区。你正在旋转的绕Y轴。该轴是不同的,因为我们无法检测到它的生物。我们知道我们是有一定角度的,但我们不知道有关地球磁北极的方向。 相反,我们需要使用外部工具...磁罗盘。这使我们能够确定的方向,我们正面临着。与我们的电话也是如此。

Now imagine someone now rotates you 90 degrees on the roundabout so that you are now facing East. You are being rotated around the Y axis. This axis is different because we can't detect it biologically. We know we are angled by a certain amount but we don't know the direction in relation to the planet's magnetic North pole. Instead we need to use a external tool... a magnetic compass. This allows us to ascertain which direction we are facing. The same is true with our phone.

现在该款手机还拥有一个3轴加速度计。我有否的想法,他们实际上是如何工作的,但我想象它的方式就是想象重力恒定均匀的雨水从空中落下,并想象图中的轴上面管,它可以检测雨水的量流过。当手机保持直立所有的雨水会流过Y'管'。如果手机正在逐步旋转,使得它的屏幕朝向天空的雨水流过的Y量将减少到零而到Z的体积将稳步增加,直到有雨的最大量被流过。同样,如果我们现在小费手机倒向一侧在X管最终将收集雨水的最大金额。因此通过测量雨水流过管3就可以计算出取向的量取决于电话的取向。

Now the phone also has a 3-axes accelerometer. I have NO idea how they actually work but the way I visualise it is to imagine gravity as constant and uniform 'rain' falling from the sky and to imagine the axes in the figure above as tubes which can detect the amount of rain flowing through. When the phone held upright all the rain will flow through the Y 'tube'. If the phone is gradually rotated so its screen faces the sky the amount of rain flowing through Y will decrease to zero while the volume through Z will steadily increase until the maximum amount of rain is flowing through. Similarly if we now tip the phone onto its side the X tube will eventually collect the max amount of rain. Therefore depending on the orientation of the phone by measuring the amount of rain flowing through the 3 tubes you can calculate the orientation.

这款手机还拥有电子罗盘其行为像一个正常的指南针 - 它的虚拟针指向磁北。 Android的合并这两个传感器的信息,这样每当 SensorEvent TYPE_ORIENTATION 的生成值[3] 阵列有 值[0]:方位 - (罗盘方位东磁北) 值[1]:节距,绕x轴的旋转(在电话前倾或后) 值[2]:轧辊,绕Y轴旋转(在手机上的左侧或右侧俯身)

The phone also has an electronic compass which behaves like a normal compass - its "virtual needle" points to magnetic north. Android merges the information from these two sensors so that whenever a SensorEvent of TYPE_ORIENTATION is generated the values[3] array has values[0]: Azimuth - (the compass bearing east of magnetic north) values[1]: Pitch, rotation around x-axis (is the phone leaning forward or back) values[2]: Roll, rotation around y-axis (is the phone leaning over on its left or right side)

所以我觉得(即我不知道)的Andr​​oid的原因给出了方位(罗盘方位),而不是第三加速计的读数是,指南针方位只是更加有用。我不知道他们为什么去precated这种类型的传感器作为现在看来,你需要注册与系统之间的侦听器 SensorEvent S型 TYPE_MAGNETIC_FIELD 。本次活动的值[] 数组需要bepassed到 SensorManger.getRotationMatrix(..)方法得到一个旋转矩阵(见下文),然后传递到 SensorManager.getOrientation(..)方法。 有谁知道为什么Android团队去precated Sensor.TYPE_ORIENTATION ?它是一个高效的事情吗?这就是隐含在评论中一个类似的question但你仍然需要注册的development/samples/Compass/src/com/example/android/compass/CompassActivity.java例如,

So I think (ie I don't know) the reason Android gives the azimuth (compass bearing) rather than the reading of the third accelerometer is that the compass bearing is just more useful. I'm not sure why they deprecated this type of sensor as now it seems you need to register a listener with the system for SensorEvents of type TYPE_MAGNETIC_FIELD. The event's value[] array needs to bepassed into SensorManger.getRotationMatrix(..) method to get a rotation matrix (see below) which is then passed into the SensorManager.getOrientation(..) method. Does anyone know why the Android team deprecated Sensor.TYPE_ORIENTATION? Is it an efficiency thing? That is what is implied in one of the comments to a similar question but you still need to register a different type of listener in the development/samples/Compass/src/com/example/android/compass/CompassActivity.java example.

我现在想谈谈旋转矩阵。 (这是我最不确定) 所以,上面我们已经从Android文档中的三个数字,我们会打电话给他们的A,B和C。

I'd now like to talk about the rotation matrix. (This is where I am most unsure) So above we have the three figures from the Android documentation, we'll call them A, B and C.

A = SensorManger.getRotationMatrix(..)方法的身材和再presents世界坐标系

A = SensorManger.getRotationMatrix(..) method figure and represents the World's coordinate system

B = 坐标使用的SensorEvent API系统。

C = SensorManager.getOrientation(..)方法图

C= SensorManager.getOrientation(..) method figure

所以我的理解是,一个再presents世界坐标系,我presume指的是路的位​​置在这个星球上给出一个(纬度,经度)夫妇与一个可选的(海拔) 。 X是是东进坐标,Y是的北向统筹。 ž指向天空,再presents高度。

So my understanding is that A represents the "world's coordinate system" which I presume refers to the way locations on the planet are given as a (latitude, longitude) couple with an optional (altitude). X is the "easting" co-ordinate, Y is the "northing" co-ordinate. Z points to the sky and represents altitude.

的电话坐标系示于图B是固定的。 Y轴始终指出的顶部。旋转矩阵正在不断受到电话计算,并允许两者之间的映射。所以,我是正确的思维是,旋转矩阵变换坐标B系统到C?所以,当你调用 SensorManager.getOrientation(..)方法,你使用值[] 数组值对应于图C. 当手机指向天空旋转矩阵为单位矩阵(1矩阵数学等价物),这意味着没有映射是必要的,因为该设备与世界坐标系一致。

The phones co-ordinate system is shown in figure B is fixed. Its Y axis always points out the top. The rotation matrix is being constantly calculated by the phone and allows mapping between the two. So am I right in thinking that the rotation matrix transforms the coordinate system of B to C? So when you call SensorManager.getOrientation(..) method you use the values[] array with values that correspond to figure C. When the phone is pointed to the sky the rotation matrix is identity matrix (the matrix mathematical equivalent of 1) which means no mapping is necessary as the device is aligned with the world's coordinate system.

确定。我想我现在最好停止。就像我之前说的,我希望人们会告诉我在哪里,我已经搞砸或帮助的人(​​或迷惑人甚至更多!)

Ok. I think I better stop now. Like I said before I hope people will tell me where I've messed up or helped people (or confused people even further!)

推荐答案

为您更好地了解机器人如何处理这些问题的最佳方式是通过分析该 Android的加速度和方向为例。它帮了我很多,了解Android的传感器,以及如何使用它们。

The best way for you to understand better how Android handles these aspects is by analysing this Android Accelerometer and Orientation Example. It helped me a lot to understand Android's sensors and how to use them.

阅读全文

相关推荐

最新文章