Android传感器之一

原文地址:
https://developer.android.com/guide/topics/sensors/sensors_motion.html
可参考的翻译地址:
http://blog.sina.com.cn/s/blog_48d4913001010w0h.html

The Android platform provides severalsensors that let you monitor the motion of a device.
The sensors’ possible architecturesvary by sensor type:
The gravity, linear acceleration, rotation vector, significant motion, step counter, and step detector sensors are either hardware-based or software-based.
The accelerometer and gyroscope sensors are always hardware-based.

安卓平台提供多种传感器,可以让你监控一个设备的运动。
传感器根据类型分为以下结构:
重力,线性加速器,翻转矢量,重要运动,计步器,和步速探测传感器,是基于硬件或者基于软件。
加速计和陀螺仪传感器是基于硬件的。

Most Android-powered devices have anaccelerometer, and many now include a gyroscope. The availability of thesoftware-based sensors is more variable because they often rely on one or morehardware sensors to derive their data. Depending on the device, thesesoftware-based sensors can derive their data either from the accelerometer andmagnetometer or from the gyroscope.

大多数安卓设备有一个加速计,有一些会有陀螺仪。基于软件的传感器可用性更多样化,因为他们经常依赖一个或者多个硬件传感器去获得它们的数据。依赖设备,这些基于软件的传感器可以从加速计和磁力计或者从陀螺仪获取它们的数据。

Motion sensors are useful formonitoring device movement, such as tilt, shake, rotation, or swing. Themovement is usually a reflection of direct user input (for example, a usersteering a car in a game or a user controlling a ball in a game), but it canalso be a reflection of the physical environment in which the device is sitting(for example, moving with you while you drive your car). In the first case, youare monitoring motion relative to the device’s frame of reference or yourapplication’s frame of reference; in the second case you are monitoring motionrelative to the world’s frame of reference. Motion sensors by themselves arenot typically used to monitor device position, but they can be used with othersensors, such as the geomagnetic field sensor, to determine a device’s positionrelative to the world’s frame of reference (see Position Sensors for more information).

运动传感器对于监控设备活动是很有用的,例如倾斜,翻转,或者摇动。这些运动通常是直接用户的输入的一个反射(例如,一个用户在一个游戏中控制一台汽车或者用户在游戏中控制一个球),但是它也可能是物理环境(设备是“坐着的”)的反射(例如,当你驾车时跟着你一起移动)。在第一中情况下,你监控运动相对于设备的参照系,或者你的应用的参照系;在第二个情况下,你监控运动相对于世界的参照系。运动传感器自身并不是专门用于监控设备位置的,但是它们可以被和其他传感器一起使用,例如地理磁力领域的传感器,去确定一个设备相对于世界参照系(参考Position Sensors 来获得更多信息)。

All of the motion sensors returnmulti-dimensional arrays of sensor values for each SensorEvent. For example, during a single sensorevent the accelerometer returns acceleration force data for the threecoordinate axes, and the gyroscope returns rate of rotation data for the threecoordinate axes. These data values are returned in a float array (values) along with other SensorEvent parameters. Table 1 summarizesthe motion sensors that are available on the Android platform.
所有传感器为每一个SensorEvent返回传感器信息的多维数组。举例来说,在一个传感器事件中,加速机返回的加速力数据是三个坐标轴,陀螺仪返回三个坐标轴的旋转数据率。这些数据都是以一个float数组(values)伴随着其他SensorEvent 参数返回。表1概述了安卓平台可用的运动传感器。

Sensor Sensor event data Description Units of measure
TYPE_ACCELEROMETER SensorEvent.values[0] Acceleration force along the x axis (including gravity). m/s2

SensorEvent.values[1] Acceleration force along the y axis (including gravity).

SensorEvent.values[2] Acceleration force along the z axis (including gravity).
TYPE_GRAVITY SensorEvent.values[0] Force of gravity along the x axis. m/s2
SensorEvent.values[1] Force of gravity along the y axis.
SensorEvent.values[2] Force of gravity along the z axis.
TYPE_GYROSCOPE SensorEvent.values[0] Rate of rotation around the x axis. rad/s
SensorEvent.values[1] Rate of rotation around the y axis.
SensorEvent.values[2] Rate of rotation around the z axis.
TYPE_GYROSCOPE_UNCALIBRATED SensorEvent.values[0] Rate of rotation (without drift compensation) around the x axis. rad/s
SensorEvent.values[1] Rate of rotation (without drift compensation) around the y axis.
SensorEvent.values[2] Rate of rotation (without drift compensation) around the z axis.
SensorEvent.values[3] Estimated drift around the x axis.
SensorEvent.values[4] Estimated drift around the y axis.
SensorEvent.values[5] Estimated drift around the z axis.
TYPE_LINEAR_ACCELERATION SensorEvent.values[0] Acceleration force along the x axis (excluding gravity). m/s2
SensorEvent.values[1] Acceleration force along the y axis (excluding gravity).
SensorEvent.values[2] Acceleration force along the z axis (excluding gravity).
TYPE_ROTATION_VECTOR SensorEvent.values[0] Rotation vector component along the x axis (x * sin(θ/2)). Unitless
SensorEvent.values[1] Rotation vector component along the y axis (y * sin(θ/2)).
SensorEvent.values[2] Rotation vector component along the z axis (z * sin(θ/2)).
SensorEvent.values[3] Scalar component of the rotation vector ((cos(θ/2))
TYPE_SIGNIFICANT_MOTION N/A N/A N/A
TYPE_STEP_COUNTER SensorEvent.values[0] Number of steps taken by the user since the last reboot while the sensor was activated. Steps
TYPE_STEP_DETECTOR N/A N/A N/A

1 The scalar component is anoptional value.
The rotation vector sensor and thegravity sensor are the most frequently used sensors for motion detection andmonitoring. The rotational vector sensor is particularly versatile and can beused for a wide range of motion-related tasks, such as detecting gestures,monitoring angular change, and monitoring relative orientation changes. Forexample, the rotational vector sensor is ideal if you are developing a game, anaugmented reality application, a 2-dimensional or 3-dimensional compass, or acamera stabilization app. In most cases, using these sensors is a better choicethan using the accelerometer and geomagnetic field sensor or the orientationsensor.

旋转矢量传感器和重力传感器对于运动探测和监控是最常用的。旋转矢量传感器用处很多,可以用于很大范围的运动相关任务,例如探测姿势,监控角度变化,监控相对方向变化。举例,如果你开发一个游戏,一个增强的现实应用,一个2D或者3D的罗盘,或者一个相机稳定应用程序,旋转矢量传感器是理想的。在大多数情况下,使用这些传感器是比加速计和地理磁力计领域传感器或者方向传感器更好的选择。

猜你喜欢

转载自blog.csdn.net/chaiyu2002/article/details/71404754