android 方向传感器中有哪些传感器的数据是可以分享的

安卓-csdn(87)
01#defineSENSOR_TYPE_ACCELEROMETER&1 //加速度
02#defineSENSOR_TYPE_MAGNETIC_FIELD&2 //磁力
03#defineSENSOR_TYPE_ORIENTATION&3 //方向
04#defineSENSOR_TYPE_GYROSCOPE&4 //陀螺仪
05#defineSENSOR_TYPE_LIGHT&5 //光线感应
06#defineSENSOR_TYPE_PRESSURE&6 //压力
07#defineSENSOR_TYPE_TEMPERATURE&7 //温度
08#defineSENSOR_TYPE_PROXIMITY&8 //接近
09#defineSENSOR_TYPE_GRAVITY&9 //重力
10#defineSENSOR_TYPE_LINEAR_ACCELERATION 10//线性加速度
11#defineSENSOR_TYPE_ROTATION_VECTOR&11//旋转矢量
我们依次看看这十一种传感器
1&加速度传感器
加速度传感器又叫G-sensor,返回x、y、z三轴的加速度数值。
该数值包含地心引力的影响,单位是m/s^2。
将手机平放在桌面上,x轴默认为0,y轴默认0,z轴默认9.81。
将手机朝下放在桌面上,z轴为-9.81。
将手机向左倾斜,x轴为正值。
将手机向右倾斜,x轴为负值。
将手机向上倾斜,y轴为负值。
将手机向下倾斜,y轴为正值。
加速度传感器可能是最为成熟的一种mems产品,市场上的加速度传感器种类很多。
手机中常用的加速度传感器有BOSCH(博世)的BMA系列,AMK的897X系列,ST的LIS3X系列等。
这些传感器一般提供±2G至±16G的加速度测量范围,采用I2C或SPI接口和MCU相连,数据精度小于16bit。
2&磁力传感器
磁力传感器简称为M-sensor,返回x、y、z三轴的环境磁场数据。
该数值的单位是微特斯拉(micro-Tesla),用uT表示。
单位也可以是高斯(Gauss),1Tesla=10000Gauss。
硬件上一般没有独立的磁力传感器,磁力数据由电子罗盘传感器提供(E-compass)。
电子罗盘传感器同时提供下文的方向传感器数据。
3&方向传感器
方向传感器简称为O-sensor,返回三轴的角度数据,方向数据的单位是角度。
为了得到精确的角度数据,E-compass需要获取G-sensor的数据,
经过计算生产O-sensor数据,否则只能获取水平方向的角度。
方向传感器提供三个数据,分别为azimuth、pitch和roll。
azimuth:方位,返回水平时磁北极和Y轴的夹角,范围为0°至360°。
0°=北,90°=东,180°=南,270°=西。
pitch:x轴和水平面的夹角,范围为-180°至180°。
当z轴向y轴转动时,角度为正值。
roll:y轴和水平面的夹角,由于历史原因,范围为-90°至90°。
当x轴向z轴移动时,角度为正值。
电子罗盘在获取正确的数据前需要进行校准,通常可用8字校准法。
8字校准法要求用户使用需要校准的设备在空中做8字晃动,
原则上尽量多的让设备法线方向指向空间的所有8个象限。
手机中使用的电子罗盘芯片有AKM公司的897X系列,ST公司的LSM系列以及雅马哈公司等等。
由于需要读取G-sensor数据并计算出M-sensor和O-sensor数据,
因此厂商一般会提供一个后台daemon来完成工作,电子罗盘算法一般是公司私有产权。
4&陀螺仪传感器
陀螺仪传感器叫做Gyro-sensor,返回x、y、z三轴的角加速度数据。
角加速度的单位是radians/second。
根据Nexus S手机实测:
水平逆时针旋转,Z轴为正。
水平逆时针旋转,z轴为负。
向左旋转,y轴为负。
向右旋转,y轴为正。
向上旋转,x轴为负。
向下旋转,x轴为正。
ST的L3G系列的陀螺仪传感器比较流行,iphone4和google的nexuss中使用该种传感器。
5&光线感应传感器
光线感应传感器检测实时的光线强度,光强单位是lux,其物理意义是照射到单位面积上的光通量。
光线感应传感器主要用于Android系统的LCD自动亮度功能。
可以根据采样到的光强数值实时调整LCD的亮度。
6&压力传感器
压力传感器返回当前的压强,单位是百帕斯卡hectopascal(hPa)。
7&温度传感器
温度传感器返回当前的温度。
8&接近传感器
接近传感器检测物体与手机的距离,单位是厘米。
一些接近传感器只能返回远和近两个状态,
因此,接近传感器将最大距离返回远状态,小于最大距离返回近状态。
接近传感器可用于接听电话时自动关闭LCD屏幕以节省电量。
一些芯片集成了接近传感器和光线传感器两者功能。
下面三个传感器是Android2新提出的传感器类型,目前还不太清楚有哪些应用程序使用。
9&重力传感器
重力传感器简称GV-sensor,输出重力数据。
在地球上,重力数值为9.8,单位是m/s^2。
坐标系统与加速度传感器相同。
当设备复位时,重力传感器的输出与加速度传感器相同。
10&线性加速度传感器
线性加速度传感器简称LA-sensor。
线性加速度传感器是加速度传感器减去重力影响获取的数据。
单位是m/s^2,坐标系统与加速度传感器相同。
加速度传感器、重力传感器和线性加速度传感器的计算公式如下:
加速度 =&重力 + 线性加速度
11&旋转矢量传感器
旋转矢量传感器简称RV-sensor。
旋转矢量代表设备的方向,是一个将坐标轴和角度混合计算得到的数据。
RV-sensor输出三个数据:
x*sin(theta/2)
y*sin(theta/2)
z*sin(theta/2)
sin(theta/2)是RV的数量级。
RV的方向与轴旋转的方向相同。
RV的三个数值,与cos(theta/2)组成一个四元组。
RV的数据没有单位,使用的坐标系与加速度相同。
1sensors_event_t.data[0]= x*sin(theta/2)
2sensors_event_t.data[1] =y*sin(theta/2)
3sensors_event_t.data[2] =z*sin(theta/2)
4sensors_event_t.data[3]=cos(theta/2)
GV、LA和RV的数值没有物理传感器可以直接给出,
需要G-sensor、O-sensor和Gyro-sensor经过算法计算后得出。
算法一般是传感器公司的私有产权。
1.&android source codehardware\libhardware\include\hardwaresensor.h
2.&/data/html//87454.html
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:47883次
积分:1173
积分:1173
排名:千里之外
原创:62篇
转载:48篇
评论:27条
(1)(1)(5)(4)(5)(7)(5)(12)(12)(2)(15)(15)(26)(1)android&获取所有传感器数据
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
android:text="@string/hello"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="加速度"
android:id="@+id/edt1"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="磁场"
android:id="@+id/edt2"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="定位"
android:id="@+id/edt3"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="陀螺仪"
android:id="@+id/edt4"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="光线"
android:id="@+id/edt5"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="压力"
android:id="@+id/edt6"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="温度"
android:id="@+id/edt7"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="距离"
android:id="@+id/edt8"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
& & android:text="重力"
android:id="@+id/edt9"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
android:text="线性加速度"
android:id="@+id/edt10"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
android:text="旋转矢量"
android:id="@+id/edt11"
android:layout_width="fill_parent"&
android:layout_height="wrap_content"&
android:text="defalut"
android:id="@+id/edt12"
&main.java
package&com.msi.ibm.
import&android.app.A
import&android.os.B
import&android.util.L
import&android.widget.TextV
import&android.hardware.S
import&android.hardware.SensorM
import&android.hardware.SensorL
public&class&IBMEyes&extends&Activity&implements&SensorListener&{
&&&&final&String&tag&=&"IBMEyes";
&&&&SensorManager&sm&=&null;
&&&&TextView&View1&=&null;
&&&&TextView&View2&=&null;
&&&&TextView&View3&=&null;
&&&&TextView&View4&=&null;
&&&&TextView&View5&=&null;
&&&&TextView&View6&=&null;
&&&&TextView&View7&=&null;
&&&&TextView&View8&=&null;
&&&&TextView&View9&=&null;
&&&&TextView&View10&=&null;
&&&&TextView&View11&=&null;
&&&&TextView&View12&=&null;
&&&&@Override
&&&&public&void&onCreate(Bundle&savedInstanceState)&{
&&&&&&&&super.onCreate(savedInstanceState);
&&&&&&&&sm&=&(SensorManager)&getSystemService(SENSOR_SERVICE);
&&&&&&&&setContentView(R.layout.main);
&&&&&&&&View1&=&(TextView)&findViewById(R.id.edt1);
&&&&&&&&View2&=&(TextView)&findViewById(R.id.edt2);
&&&&&&&&View3&=&(TextView)&findViewById(R.id.edt3);
&&&&&&&&View4&=&(TextView)&findViewById(R.id.edt4);
&&&&&&&&View5&=&(TextView)&findViewById(R.id.edt5);
&&&&&&&&View6&=&(TextView)&findViewById(R.id.edt6);
&&&&&&&&View7&=&(TextView)&findViewById(R.id.edt7);
&&&&&&&&View8&=&(TextView)&findViewById(R.id.edt8);
&&&&&&&&View9&=&(TextView)&findViewById(R.id.edt9);
&&&&&&&&View10&=&(TextView)&findViewById(R.id.edt10);
&&&&&&&&View11&=&(TextView)&findViewById(R.id.edt11);
&&&&&&&&View12&=&(TextView)&findViewById(R.id.edt12);&&&&&&&&
&&&&public&void&onSensorChanged(int&sensor,&float[]&values)&{
&&&&&&&&synchronized&(this)&{
&&&&&&&&&&&&String&str&=&&"X:"&+&values[0]&+&",Y:"&+&values[1]&+&",Z:"&+&values[2];
&&&&&&&&&&&&switch&(sensor){
&&&&&&&&&&&&case&Sensor.TYPE_ACCELEROMETER:
&&&&&&&&&&&&&&&&View1.setText("加速度:"&+&str);
&&&&&&&&&&&&&&&&break;&&&&
&&&&&&&&&&&&case&Sensor.TYPE_MAGNETIC_FIELD:
&&&&&&&&&&&&&&&&View2.setText("磁场:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_ORIENTATION:
&&&&&&&&&&&&&&&&View3.setText("定位:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_GYROSCOPE:
&&&&&&&&&&&&&&&&View4.setText("陀螺仪:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_LIGHT:
&&&&&&&&&&&&&&&&View5.setText("光线:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_PRESSURE:
&&&&&&&&&&&&&&&&View6.setText("压力:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_TEMPERATURE:
&&&&&&&&&&&&&&&&View7.setText("温度:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_PROXIMITY:
&&&&&&&&&&&&&&&&View8.setText("距离:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_GRAVITY:
&&&&&&&&&&&&&&&&View9.setText("重力:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_LINEAR_ACCELERATION:
&&&&&&&&&&&&&&&&View10.setText("线性加速度:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&case&Sensor.TYPE_ROTATION_VECTOR:
&&&&&&&&&&&&&&&&View11.setText("旋转矢量:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&default:
&&&&&&&&&&&&&&&&View12.setText("NORMAL:"&+&str);
&&&&&&&&&&&&&&&&break;&
&&&&&&&&&&&&}&&&
&&&&public&void&onAccuracyChanged(int&sensor,&int&accuracy)&{
&&&&&&&&Log.d(tag,"onAccuracyChanged:&"&+&sensor&+&",&accuracy:&"&+&accuracy);
&&&&@Override
&&&&protected&void&onResume()&{
&&&&&&&&super.onResume();
&&&&&&&&sm.registerListener(this,&
&&&&&&&&&&&&&&&&Sensor.TYPE_ACCELEROMETER&|
&&&&&&&&&&&&&&&&Sensor.TYPE_MAGNETIC_FIELD&|
&&&&&&&&&&&&&&&&Sensor.TYPE_ORIENTATION&|
&&&&&&&&&&&&&&&&Sensor.TYPE_GYROSCOPE&|
&&&&&&&&&&&&&&&&Sensor.TYPE_LIGHT&|
&&&&&&&&&&&&&&&&Sensor.TYPE_PRESSURE&|
&&&&&&&&&&&&&&&&Sensor.TYPE_TEMPERATURE&|
&&&&&&&&&&&&&&&&Sensor.TYPE_PROXIMITY&|
&&&&&&&&&&&&&&&&Sensor.TYPE_GRAVITY&|
&&&&&&&&&&&&&&&&Sensor.TYPE_LINEAR_ACCELERATION&|
&&&&&&&&&&&&&&&&Sensor.TYPE_ROTATION_VECTOR,
&&&&&&&&&&&&&&&&SensorManager.SENSOR_DELAY_NORMAL);
&&&&@Override
&&&&protected&void&onStop()&{
&&&&&&&&sm.unregisterListener(this);
&&&&&&&&super.onStop();
&&&&}&&&&&
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 android 方向传感器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信