Android 上加速度计读数的最大值
我正在使用 Android 传感器管理器来获取加速度计读数。我得到的读数是 m/s2,基本没问题。但我在任何方向的任何轴上获得的最大读数是 |19.xx| ,大约为 2 G。这是智能手机特有的问题还是我需要更改某些设置才能获得更大的值?
这是我用来获取加速度计传感器的代码:
sensorManager = (SensorManager) context
.getSystemService(Context.SENSOR_SERVICE);
List<Sensor> sensors = sensorManager
.getSensorList(Sensor.TYPE_ACCELEROMETER);
if (sensors.size() > 0) {
sensor = sensors.get(0);
float max = sensor.getMaximumRange();
boolean running = sensorManager.registerListener(sensorEventListener,
sensor, SensorManager.SENSOR_DELAY_GAME);
}
这就是 onSensorChanged() 的样子,就像
public void onSensorChanged(SensorEvent event) {
now = event.timestamp;
x = event.values[0];
y = event.values[1];
z = event.values[2];
}
我使用 Android API Level 7
一样。我已经在两部手机上进行了测试: HTC HD 2(安卓 2.3.5) 三星Spica(Android 2.1)
I am using androids sensor manager to get accelerometer readings. The readings I am getting are m/s2 and are just about fine. But the maximum reading that I get,on any axis in any direction is |19.xx| , which is approximately 2 Gs. Is this a smartphone specific issue or is there some setting that I need to change to get greater values?
this is the code that I am using to get the sensor for accelerometer:
sensorManager = (SensorManager) context
.getSystemService(Context.SENSOR_SERVICE);
List<Sensor> sensors = sensorManager
.getSensorList(Sensor.TYPE_ACCELEROMETER);
if (sensors.size() > 0) {
sensor = sensors.get(0);
float max = sensor.getMaximumRange();
boolean running = sensorManager.registerListener(sensorEventListener,
sensor, SensorManager.SENSOR_DELAY_GAME);
}
and this is how the onSensorChanged() looks like
public void onSensorChanged(SensorEvent event) {
now = event.timestamp;
x = event.values[0];
y = event.values[1];
z = event.values[2];
}
I am using Android API Level 7.
And I have tested on two phones :
HTC HD 2 (Android 2.3.5)
Samsung Spica (Android 2.1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不存在“精确值”。它会因设备而异。加速度可以是正数或负数 - getMaximumRange() ,我假设您可以安全地将该值乘以 -1 以获得最小值。
"Exact Values" are not there. It will vary by device. Acceleration can be positive or negative - getMaximumRange() , I would assume you can safely multiply that value by -1 to get the minimum value.
你可以让 G 这样做:
Gs = sqrt (Xg^2 + Yg^2 + Zg^2) 其中 ^2 表示 sqr 或平方 (X^2 = X*X)
这将为您提供应用的 G。
You can get the G's doing this:
Gs = sqrt (Xg^2 + Yg^2 + Zg^2) where ^2 means sqr or square (X^2 = X*X)
That will give you the Gs applied.