改变的Andr​​oid NDK陀螺仪的更新速率 [英] Changing Android gyroscope update rate in NDK

查看:222
本文介绍了改变的Andr​​oid NDK陀螺仪的更新速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用三星Galaxy SII手机里面有一个陀螺仪,magnometer,和加速度工作。一切都使用NDK。

I'm working with a Samsung Galaxy sii phone which has a gyroscope, magnometer, and accelerometer. Everything is using NDK.

我使用toadlet库抽象出了很多电话接口,但库中有函数来设置它调用的预期NDK功能的采样率:

I am using the toadlet library to abstract out a lot of the phone interface, but within that library there is function to set the sampling rate which calls the expected NDK function:

void AndroidSensorDevice::setSampleTime(int dt){
    if(mSensor!=NULL){
        ASensorEventQueue_setEventRate(mEventQueue,mSensor,dt*1000);
    }
} 

当我改变加速度计和magnometer我看到的采样率,大致在实际采样率的预期变​​化。对于陀螺仪,虽然,它始终只在最快的速度,即更新不管我设置采样率,我得到类似这样的时间差:

When I change the sampling rates of the accelerometer and magnometer I see, roughly, the expected change in actual sampling rates. For the gyroscope, though, it always updates at only the fastest rate, i.e. no matter what I set the sample rate to I get time differences similar to this:

I/toadlet (10266): dt= 0.619000
I/toadlet (10266): dt= 4.423000
I/toadlet (10266): dt= 0.511000
I/toadlet (10266): dt= 4.335000
I/toadlet (10266): dt= 0.586000
I/toadlet (10266): dt= 4.371000
I/toadlet (10266): dt= 0.586000
I/toadlet (10266): dt= 4.559000
I/toadlet (10266): dt= 0.340000
I/toadlet (10266): dt= 3.827000
I/toadlet (10266): dt= 0.617000
I/toadlet (10266): dt= 5.337000
I/toadlet (10266): dt= 0.154000
I/toadlet (10266): dt= 3.538000
I/toadlet (10266): dt= 0.556000
I/toadlet (10266): dt= 4.547000

即使试图大的离谱的采样率没有影响。有其他人看到这一点?

Even trying ridiculously large sample rates has no effect. Has anyone else seen this?

这款手机运行的是Android 2.3.5,我已经同时使用的android-9和android-14的目标,没有明显的差别尝试。

The phone is running Android 2.3.5 and I've tried using both android-9 and android-14 targets with no noticeable difference.

推荐答案

根据对 setEventRate()函数的文档上,您可以设置采样率真的只有一个暗示,而不是明确的规范。当你看到的行为是不必要的,这是没有错的。
由于大多数应用程序需要陀螺仪输出反正整合,这种行为也不是完全不合理的。如果你真的需要一个更低的价格,我建议的基础上的时间戳一起平均样本和读出结果。

Based on the documentation for the setEventRate() function, the sample rate you set is really only a hint, not a definite specification. While the behavior you're seeing is unwanted, it's not wrong. Since most applications need to integrate the gyro output anyway, this behavior is not entirely unreasonable. If you really need a lower rate, I would suggest averaging samples together and reading out the results based on the timestamps.

/*
 * Sets the delivery rate of events in microseconds for the given sensor.
 * Note that this is a hint only, generally event will arrive at a higher
 * rate. It is an error to set a rate inferior to the value returned by
 * ASensor_getMinDelay().
 * Returns a negative error code on failure.
 */
int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);

这篇关于改变的Andr​​oid NDK陀螺仪的更新速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆