admin管理员组文章数量:1131535
I try to develop Android app where I need get watch orientation with max possible frequency. I discover issue with getting TYPE_ROTATION_VECTOR sensor data on Galaxy Watch 7. if I register sensor listener with SensorManager.SENSOR_DELAY_FASTEST, looks like on that watch sensor repeat/skip approximately 4-6 sensors reading. Example bellow:
Data on items 1-6 is the same:
0 = {quaternion@28060} "x:-0.862837 y:-0.214272 z:0.447439 w:0.096935"
1 = {quaternion@28061} "x:-0.894187 y:-0.162952 z:0.385226 w:0.159612"
2 = {quaternion@28062} "x:-0.894187 y:-0.162952 z:0.385226 w:0.159612"
3 = {quaternion@28063} "x:-0.894187 y:-0.162952 z:0.385226 w:0.159612"
4 = {quaternion@28064} "x:-0.894187 y:-0.162952 z:0.385226 w:0.159612"
5 = {quaternion@28065} "x:-0.894187 y:-0.162952 z:0.385226 w:0.159612"
6 = {quaternion@28066} "x:-0.894187 y:-0.162952 z:0.385226 w:0.159612"
7 = {quaternion@28067} "x:-0.920170 y:-0.108727 z:0.282975 w:0.247769"
8 = {quaternion@28068} "x:-0.920170 y:-0.108727 z:0.282975 w:0.247769"
...
Looks like Galaxy Watch 4 work just fine. Same Wear OS version, same System version, same code running.
Below is simple app Activity that can produce logs that will show difference between Watch 4 and Watch 7.
package com.example.orientationtest;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private Sensor rotationSensor;
private int lastAccuracy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sensorManager = (SensorManager) this.getSystemService(Activity.SENSOR_SERVICE);
rotationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
}
@Override
protected void onStart() {
super.onStart();
sensorManager.registerListener(this, rotationSensor, SensorManager.SENSOR_DELAY_FASTEST);
}
@Override
protected void onStop() {
super.onStop();
sensorManager.unregisterListener(this);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (lastAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
return;
}
if (event.sensor == rotationSensor) {
float[] quaternion = new float[4];
SensorManager.getQuaternionFromVector(quaternion, event.values);
Log.i("SensorData", "quaternion: x = " + quaternion[1] + " y = " + quaternion[2] + " z = " + quaternion[3] + " w = " + quaternion[0]);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d("SensorData", "Accuracy: " + accuracy);
if (lastAccuracy != accuracy) {
lastAccuracy = accuracy;
}
}
}
Watch 7 logs:
- quaternion: x = 0.16676 y = 0.225229 z = 0.697442 w = 0.659572
- quaternion: x = 0.16676 y = 0.225229 z = 0.697442 w = 0.659572
- quaternion: x = 0.16676 y = 0.225229 z = 0.697442 w = 0.659572
- quaternion: x = 0.16676 y = 0.225229 z = 0.697442 w = 0.659572
- quaternion: x = 0.16676 y = 0.225229 z = 0.697442 w = 0.659572
- quaternion: x = 0.16676 y = 0.225229 z = 0.697442 w = 0.659572
- quaternion: x = 0.166636 y = 0.225591 z = 0.697355 w = 0.659573
- quaternion: x = 0.166636 y = 0.225591 z = 0.697355 w = 0.659573
- quaternion: x = 0.166636 y = 0.225591 z = 0.697355 w = 0.659573
- quaternion: x = 0.166636 y = 0.225591 z = 0.697355 w = 0.659573
- quaternion: x = 0.166636 y = 0.225591 z = 0.697355 w = 0.659573
- quaternion: x = 0.166636 y = 0.225591 z = 0.697355 w = 0.659573
- quaternion: x = 0.166474 y = 0.22601 z = 0.697112 w = 0.659726
- quaternion: x = 0.166474 y = 0.22601 z = 0.697112 w = 0.659726
- quaternion: x = 0.166474 y = 0.22601 z = 0.697112 w = 0.659726
- quaternion: x = 0.166474 y = 0.22601 z = 0.697112 w = 0.659726
- quaternion: x = 0.166032 y = 0.225805 z = 0.697044 w = 0.65998
- quaternion: x = 0.166032 y = 0.225805 z = 0.697044 w = 0.65998
- quaternion: x = 0.166032 y = 0.225805 z = 0.697044 w = 0.65998
- quaternion: x = 0.166032 y = 0.225805 z = 0.697044 w = 0.65998
Watch 4 logs
quaternion: x = -0.016336 y = -0.015928 z = 0.10495 w = 0.994215
quaternion: x = -0.016307 y = -0.015926 z = 0.104955 w = 0.994215
quaternion: x = -0.016336 y = -0.01596 z = 0.104954 w = 0.994214
quaternion: x = -0.016512 y = -0.016046 z = 0.104955 w = 0.99421
quaternion: x = -0.016515 y = -0.016074 z = 0.104961 w = 0.994209
quaternion: x = -0.0166 y = -0.016146 z = 0.104967 w = 0.994206
quaternion: x = -0.016616 y = -0.016161 z = 0.104973 w = 0.994204
quaternion: x = -0.01681 y = -0.016191 z = 0.104975 w = 0.9942
quaternion: x = -0.016833 y = -0.016199 z = 0.104975 w = 0.9942
quaternion: x = -0.016939 y = -0.016223 z = 0.10497 w = 0.994198
quaternion: x = -0.017149 y = -0.016287 z = 0.104972 w = 0.994193
quaternion: x = -0.017249 y = -0.016333 z = 0.104972 w = 0.994191
quaternion: x = -0.01729 y = -0.016378 z = 0.104972 w = 0.994189
quaternion: x = -0.017333 y = -0.016451 z = 0.104971 w = 0.994188
Since API 26 SensorDirectChannel is available to use for possible faster sample rates. It can be used with MemoryFile or HardwareBuffer as Buffer. I get IOExceptions with both while trying to create the Channel. I wounder if anyone can share info about success of using SensorDirectChannel.
Thank you for any help.
本文标签: androidHow to get TYPEROTATIONVECTOR sensor data on Galaxy Watch7Stack Overflow
版权声明:本文标题:android - How to get TYPE_ROTATION_VECTOR sensor data on Galaxy Watch7 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736771212a1952097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论