无法改变加速度计的速率

时间:2012-02-20 09:34:12

标签: android accelerometer android-sensors nexus-s rate

我必须从我的Android手机上收集加速度计数据,所以我做了一个小程序来做到这一点。

经过一些测试,我发现当手机处于活动状态时,我的Nexus S加速度计的速率始终每秒50个值,并且当它处于睡眠状态时每秒6个值(具有{{1无论我要求的费率是多少(PARTIAL_WAKE_LOCKNORMALUIGAME)。

所以我决定在Internet上安装一个测试加速度计速率的应用程序:http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code

但是我得到了相同的“错误”:无论我要求的速率如何,当手机处于活动状态时,它总是每秒50个值。

我不明白为什么我的手机会这样。这是一个问题:

  • 与Nexus S有关?
  • 特定于我的手机?
  • 与Android 4有关吗?

编辑:我在另一台Nexus S(Android 4)上测试了该程序,我遇到了同样的问题。 所以它似乎消除了上面列出的一种可能性:它与我的手机无关。

4 个答案:

答案 0 :(得分:6)

我在不同的智能手机上进行了一些测试。结果如下:

Samsung Galaxy Teos
-------------------
* When awake
    Normal: 4.17 Hz
    UI: 8.43 hz
    Game: 16.93 Hz
    Fastest: 109.42 Hz

* When asleep
    The phone sends null values (0), whatever the mode I chose


Samsung Nexus S
---------------
* When awake
    Normal: 49.51 Hz
    UI: 49.51 hz
    Game: 49.51 Hz
    Fastest: 49.51 Hz

* When asleep
    6.06 Hz, whatever the mode I chose

LG Nexus 5
----------
* When awake
    Normal: 15.39 Hz
    UI: 15.4 Hz
    Game: 50.05 Hz
    Fastest: 196.74 Hz

* When asleep
    Normal: 4.96 Hz
    UI: 15.41 Hz
    Game: 50.12 Hz
    Fastest: 198.53 Hz

LG Nexus 4
----------
* When awake
    Normal: 15.75 Hz
    UI: 15.74 Hz
    Game: 48.86 Hz
    Fastest: 195.85 Hz

* When asleep
    Normal: 5.5 Hz
    UI: 15.74 Hz
    Game: 49.16 Hz
    Fastest: 196.75 Hz


Samsung Galaxy Nexus
--------------------
* When awake
    Fastest: 125 Hz

* When asleep
    It sends data


Samsung Galaxy Note 2
---------------------
* When awake
    Fastest: 100 Hz

* When asleep
    The phone does not send anything


Samsung Galaxy S3 and S3 Mini
-----------------------------
* When awake
    Fastest: 100 Hz

* When asleep
    Fastest: 100 Hz


HTC Wildfire
------------
* When awake
    Normal: 4 Hz
    UI: 12 hz
    Game: 22.2 Hz
    Fastest: 38.40 Hz

* When asleep
    The phone does not send anything, whatever the mode I chose


HTC Desire
----------
* When awake
    Normal: 4.36 Hz
    UI: 11.9 hz
    Game: 23.3 Hz
    Fastest: 47.27 Hz

* When asleep
    The phone does not send anything, whatever the mode I chose

请注意,测试是使用部分唤醒锁执行的。没有它,Nexus S在睡着时根本不提供任何数据。

还有一个有用的智能手机列表,加速度计在睡着时发送(或不发送)兼容数据:http://www.saltwebsites.com/2012/android-accelerometers-screen-off

答案 1 :(得分:3)

在拍摄数据时,请勿通过USB将手机连接到PC,因为收集数据只会记录在SD卡中。当手机通过USB连接到PC时,没有文件可以保存在SD卡中。

因此,请在收集数据时尝试断开USB连接。

答案 2 :(得分:1)

不幸的是,正如其他答案所建议的那样,您设置的延迟(或采样率)仅是应用程序所需最小值的建议(对于系统而言),但这可能会根据运行的其他应用程序或您的设备输入而发生巨大变化节电模式(关闭CPU等)。我能够获得一个好的采样率的一种方法是从服务中记录我的数据,使服务成为前台服务并使用标志PARTIAL_WAKE_LOCK进行电源锁定。

我把代码放在这个要点中 https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530

这个要点比你需要的更多代码,但只要注意接下来的两个方法

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
//        //Power management
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
        wl.acquire();
.....}

以上代码可防止操作系统关闭CPU

现在将此服务作为前台服务

NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("Title")
                        .setContentText("hola")
                        .setContentIntent(viewPendingIntent);



        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

        not=notificationBuilder.build();
        notificationManager.notify(notificationId,not );
        startForeground(notificationId, not);

与普通服务不同,上述代码使服务成为操作系统的优先级。前景服务的示例是例如音乐播放器。

使用此代码,即使手表自动关闭屏幕,我也能获得所需的采样率。

答案 3 :(得分:0)

检查此应用 无论设备型号https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd如何,我们都将采样频率固定在14-15 如有任何帮助,请发送电子邮件至developer.virtuoid@gmail.com