不可能改变加速度计的速度
我必须从我的Android手机收集加速度计数据,所以我已经做了一个小程序来做到这一点。不可能改变加速度计的速度
一些测试后,我发现我的Nexus S的加速度计的速率为每秒总是 50值当手机处于活动状态,以及每秒6个值时,它是睡着了(有PARTIAL_WAKE_LOCK
),无论速度我要求(NORMAL
,UI
,GAME
或FASTEST
)。
所以我决定安装在互联网上发现了一个应用程序,它测试的加速度计的速度:http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code
但我得到了同样的“错误”:凡是我要求的速度,它始终是每50个值第二次在手机处于活动状态时。
我不明白为什么我的手机的行为如此。它是一个问题:
- 有关的Nexus S?
- 特定于我的手机?
- 与Android 4相关吗?
EDIT:我已测试了另一个的Nexus S(的Android 4)的程序,我有同样的问题。 所以它似乎消除了上面列出的可能性之一:它不仅仅与我的手机有关。
我在不同的智能手机上进行了一些测试。下面是结果:
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
检查这个程序 我们有固定的取样频率在14-15无论设备模型https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd 的任何援助邮寄我们在[email protected]
不要通过手机连接到PC USB,因为在收集数据时,数据仅记录在SD卡中。当手机通过USB连接到PC时,没有文件可以保存在SD卡中。
因此,尝试在收集数据时断开USB连接。
我已测试过您的应用程序,实际频率约为16-17赫兹。 你是怎么做到的?是通过检查onSensorChanged()方法中的值吗?如果是这样,它不能解决我的问题。 – 2012-03-09 09:46:05
顺便说一句,回答我的意见,而不是答案;) – 2012-03-09 09:47:27
我们没有使用SensorChanged()方法。相反,我们通过代码获取最大样本数(通过使用最快),并且我们通过对应于每秒15个样本的算法执行了降采样。希望这也适用于你。 – aps109 2012-03-10 18:08:46
不幸的是通过其他的答案,延迟(或采样率)为提示你设置是只然而,对于你的应用程序所要求的最低限度的建议(对于系统),这可以根据运行的其他应用程序或进入省电模式的设备(关闭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();
.....}
上面的代码防止OS转关闭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);
与普通服务不同,上述代码使服务成为操作系统的优先级。例如,前台服务的例子是音乐播放器。
使用此代码,即使在手表自动关闭屏幕后,我也能够获得所需的采样率。
我已经尝试了华硕变压器平板电脑上的代码,我有同样的问题。所有传感器延迟使用50赫兹的频率。我也会寻找答案。 – vgonisanz 2012-02-20 10:02:54
您可以尝试使用仿真器的各种配置,以确定它是依赖于操作系统还是依赖于设备。我敢打赌,价值取决于你的硬件,不能改变...另外,阅读此:http://stackoverflow.com/questions/4224223/android-how-to-increase-accelerometer-sampling-rate – 2012-02-28 12:32:19
谢谢,我会尝试与模拟器! – 2012-02-28 14:37:38