无法改变加速度计的速率

发布于 2025-01-07 09:52:50 字数 752 浏览 2 评论 0 原文

我必须从 Android 手机收集加速度计数据,因此我编写了一个小程序来做到这一点。

经过一些测试,我发现我的 Nexus S 加速计的速率在手机处于活动状态时始终每秒 50 个值,在睡眠状态时每秒始终 6 个值(使用 PARTIAL_WAKE_LOCK code>),无论我要求什么速率(NORMALUIGAMEFASTEST)。

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

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

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

  • 与 Nexus S 有关吗?
  • 具体到我的手机?
  • 与Android 4有关?

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

I have to collect accelerometer data from my Android phone, so I have made a little program to do that.

After some tests, I have found that my Nexus S accelerometer's rate is always 50 values per second when the phone is active, and 6 values per second when it is asleep (with a PARTIAL_WAKE_LOCK), whatever the rate I ask for (NORMAL, UI, GAME or FASTEST).

So I decided to install an application found on the Internet which tests the rate of the accelerometer : http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code

But I got the same "error" : whatever the rate I ask for, it is always 50 values per second when the phone is active.

I don't understand why my phone behaves this way. Is it a problem :

  • related to the Nexus S ?
  • specific to my phone ?
  • related to Android 4 ?

EDIT : I have tested the program on another Nexus S (Android 4), and I have the same problem.
So it seems to eliminate one of the possibilities listed above: it is not related only to my phone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

始终不够爱げ你 2025-01-14 09:52:50

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

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

I have performed some tests on different smartphones. Here are the results:

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

Note that the tests have been performed using a partial wake lock. Without it, the Nexus S provides no data at all when it is asleep.

There is also a useful list of smartphones which accelerometers send (or not) compatible data when asleep: http://www.saltwebsites.com/2012/android-accelerometers-screen-off

安静被遗忘 2025-01-14 09:52:50

采集数据时请勿通过 USB 将手机连接到 PC,因为在采集过程中数据仅记录在 SD 卡中。当手机通过 USB 连接到 PC 时,SD 卡中无法保存文件。

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

Don't connect your phone to a PC via USB while taking data because during collection data is logged in the SD card only. When the phone is connected to PC via USB no file can be saved in SD card.

So try disconnecting the USB while collecting the data.

偷得浮生 2025-01-14 09:52:50

不幸的是,正如其他答案所建议的,您设置的延迟(或采样率)只是应用程序所需的最小值的建议(对于系统),但是,这可能会根据其他应用程序运行或您的设备进入省电模式而发生巨大变化模式(关闭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);

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

通过这段代码,即使手表自动关闭屏幕后,我也能够获得所需的采样率。

Unfortunately as suggested by other answers, the delay (or sampling rate) that you set is only a suggestion (for the system) of the minimum your application requires however, this can change drastically depending on other applications running or your device entering on power saving modes (turning off cpu etc). One way I was able to get a somewhat good sampling rate was by recording my data from a service, making the service a foreground service and having a power lock with the flag PARTIAL_WAKE_LOCK.

I put the code in this gist
https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530

That gist has way more code than you need but just pay attention to the next two methods

@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();
.....}

The above code prevents the OS to turn off the CPU

Now to make this service a foreground service

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);

The above code makes the service a priority for the OS unlike a normal service. Examples of a foreground service are music players for instance.

With this code I have been able to get the sampling rate I need even after the watch turn's off the screen automatically.

秋心╮凉 2025-01-14 09:52:50

检查这个应用程序
无论设备型号如何,我们都将采样频率固定为 14-15 https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd
如需任何帮助,请发送电子邮件至 [电子邮件受保护]

check this app
we have fixed sampling frequency at 14-15 irrespective of device model https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd
for any assistance mail us at [email protected]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文