什么地方错了我的传感器监测技术?我的、错了、什么地方、传感器

2023-09-04 12:54:43 作者:志在四方

(请阅读更新3月末)我正在开发一个应用程序,不断与设备的传感器的工作原理,用加速度作品和传感器来获取设备的(定向的目的是提here).换句话说,我的应用程序需要知道设备的实时定位(然而,这是根本做不到的,所以尽可能地快,而不是,但真的快可能!)中提到由雷托•迈耶专业的Andr​​oid 4.0应用程序开发的:

  

加速计可更新数百次,第二次......

我不能失去这个传感器报告的所有数据,我也想做这些数据耗时的操作(检索的方向,然后做计算...)。我决定用的LinkedBlockingQueue 来解决我的问题:

 公共无效startSensors(){
            的LinkedBlockingQueue<浮动[] []>阵列=新的LinkedBlockingQueue();
    sensorListenerForOrientation =新SensorEventListener(){

        @覆盖
        公共无效onSensorChanged(SensorEvent事件){
            如果(event.sensor.getType()== Sensor.TYPE_ACCELEROMETER)
                aValues​​ =(event.values​​.clone());
            否则,如果(event.sensor.getType()== Sensor.TYPE_MAGNETIC_FIELD)
                mValues​​ =(event.values​​.clone());
            如果(aValues​​ = NULL和放大器;!&安培;!mValues​​ = NULL){
                尝试 {
                    array.put(新浮法[] [] {aValues​​,mValues​​});
                }赶上(InterruptedException异常E){
                }
            }
        }

        @覆盖
        公共无效onAccuracyChanged(传感器传感器,诠释精度){
        }
    };
    传感器aSensor = sm.getSensorList(Sensor.TYPE_ACCELEROMETER)获得(
            sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size() -  1);
    传感器mSensor = sm.getSensorList(Sensor.TYPE_MAGNETIC_FIELD)获得(
            sm.getSensorList(Sensor.TYPE_MAGNETIC_FIELD).size() -  1);
    sm.registerListener(sensorListenerForOrientation,aSensor,
            SensorManager.SENSOR_DELAY_FASTEST);
    sm.registerListener(sensorListenerForOrientation,mSensor,
            SensorManager.SENSOR_DELAY_FASTEST);
    executor.execute(新的Runnable(){
        @覆盖
        公共无效的run(){
            doCalculations();
        }
    });
}
 

 公共无效doCalculations(){
    对于 (;;) {
        浮动[] []结果= NULL;
        尝试 {
            结果= array.take();
        }赶上(InterruptedException异常E){
        }
        浮动[] aValues​​,mValues​​;
        aValues​​ =结果[0];
        mValues​​ =结果[1];

                    INT [] =度getOrientation(aValues​​,mValues​​);
                    Log.e(,将String.valueOf(度[0]));

                 //其它计算...
                     }
                                }
 

现在我拿起​​我的设备并将其旋转大约90度到右侧,然后将其返回到第一位置快速(例如在1.5秒),但是当我看到我看到的例子,登记在设备的方位: 0,1,2,3,4,5 ......,40,39,38,37,...,0

我只想说的我看不到的程度大域在我的结果。 根据我做了什么什么,我已经研究的我可以肯定,我不会丢失任何数据,报经传感器的任何新数据记录

任何想法,解决办法?!

商祺!

更新1:我做了另外一个实验,我的设备,得到了令人震惊的结果!如果我转我的设备通过一个轴旋转90度快(不到一秒钟),我可以看到所有的度在我的结果是:0,1,2,3,...,89,90(举例来说),但如果我旋转90度,然后旋转回其第一位置,其结果必然是0,1,2,...,36,37,36,...... 2,1,0(例如)...真的混乱!

更新2:我更新doCalculations()方法来更清楚我做了什么

  

更新3:我想,也许我们可以解决这个问题的另一种方式!我有明确的目的,这code。请看看this.一世   提到有什么事情发生,我需要检测的具体   运动姿态。所以也许我所选择的整套方法(在   技术以上)不用于解决该问题的好方法。有可能   这是更好地利用其他传感器或使用来检测手势   同样的传感器在其他的方式。你怎么看?

解决方案 胎压监测传感器维修攻略

您code看起来合理。一个很大的未知数是传感器和传感器融合的有多好您的设备。快速角度变化读数依靠整合角加速度或者与混合,使结果完全与地球磁场对齐数据的物理陀螺仪。磁性数据受到周围环境。如果您的设备具有低质量的传感器或有环境中的磁干扰,这是完全有可能看到各种错误您所看到的。大金属结构和磁性设备(如电机,甚至荧光灯镇流器)即可空白领域或将任意错误。对于正常使用,一个设备仅需要一个加速度计来准确地判断哪种方式关闭,因此屏幕翻转是准确的。此仅需要在设备不动的,其中一个陀螺没有角色工作。如果你有一个手机或平板电脑的传感器只是为了达到这个目的 - 因此,没有陀螺仪或不准确的一 - 你看到一个设备的限制。飘忽不定的值是其他证据,你的设备是低质量和/或您是在地球的磁场被扭曲的位置。尝试在程序上的另一个(preferably昂贵的)设备外,并在打开,看看你会得到什么。

(please read UPDATE 3 at the end)I'm developing an app that continually works with the sensors of device, works with Accelerometer and Magnetic sensors to retrieve the orientation of device(the purpose is mentioned here). in other words, my app needs to know the orientation of device in Real-time(however this is never possible, so as fast as possible instead, but really as fast as possible !). as mentioned in professional Android 4 Application Development by Reto Meier:

The accelerometers can update hundreds of times a second...

I must not lose any data that sensors report and I also want to do time-consuming operations on these data(retrieve the orientation and then do calculations... ). I decided to solve my problem by using LinkedBlockingQueue:

    public void startSensors() {
            LinkedBlockingQueue<float[][]> array=new LinkedBlockingQueue();
    sensorListenerForOrientation = new SensorEventListener() {

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
                aValues = (event.values.clone());
            else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
                mValues = (event.values.clone());
            if (aValues != null && mValues != null) {
                try {
                    array.put(new float[][] { aValues, mValues });
                } catch (InterruptedException e) {
                }
            }
        }

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {
        }
    };
    Sensor aSensor = sm.getSensorList(Sensor.TYPE_ACCELEROMETER).get(
            sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size() - 1);
    Sensor mSensor = sm.getSensorList(Sensor.TYPE_MAGNETIC_FIELD).get(
            sm.getSensorList(Sensor.TYPE_MAGNETIC_FIELD).size() - 1);
    sm.registerListener(sensorListenerForOrientation, aSensor,
            SensorManager.SENSOR_DELAY_FASTEST);
    sm.registerListener(sensorListenerForOrientation, mSensor,
            SensorManager.SENSOR_DELAY_FASTEST);
    executor.execute(new Runnable() {
        @Override
        public void run() {
            doCalculations();
        }
    });
}

and

    public void doCalculations() {
    for (;;) {
        float[][] result = null;
        try {
            result = array.take();
        } catch (InterruptedException e) {
        }
        float[] aValues, mValues;
        aValues = result[0];
        mValues = result[1];

                    int[] degrees=getOrientation(aValues,mValues);
                    Log.e("",String.valueOf(degrees[0]));

                 //other calculations...
                     }
                                }

now I pick up my device and rotate it about 90 degrees to right and then return it to the first position fast(for example in 1.5 seconds) but as I look at the orientations that are registered in device I see for example: 0,1,2,3,4,5.......,40,39,38,37,....,0

I just want to say that I can't see a large domain of degrees in my result . based on what I have done and what I have researched I just can be sure that I am NOT losing any data, any new data reported by sensors are recorded.

any Idea, solution?!

Regards!

UPDATE 1: I did another experiment with my device and got shocking results! if I rotate my device over an axis 90 degrees fast (less than a second), I can see all degrees in my result: 0,1,2,3,....,89,90 (for example) but if I rotate it 90 degrees and then rotate it back to its first position, the result would be 0,1,2,...,36,37,36,...2,1,0(for example)...really confusing !

UPDATE 2: I updated doCalculations() method to be more clear what I have done

UPDATE 3: I think maybe we can solve the problem in another way! I have clear purposes for this code. please have a look at this. I have mentioned what is going to happen, I need to detect an specific movement gesture. so maybe the whole way that I have chosen(the technique above) is not a good way for solving this problem. maybe it's better to detect that gesture by using other sensors or using the same sensors in other way. what do you think?

解决方案

Your code looks reasonable. A big unknown is how good the sensors and sensor fusion are in your device. Quick angle change readings rely on integration of angular acceleration or else a physical gyroscope with magnetic data mixed in to make the result absolutely align with the earth. Magnetic data are subject to surroundings. If your device has low quality sensors or there are magnetic disturbances in your environment, it's entirely possible to see the kinds of error you are seeing. Big metal structures and magnetic equipment (like motors or even fluorescent light ballasts) can blank the field or introduce arbitrary errors. For normal uses, a device only needs an accelerometer to accurately determine which way is down so screen flips are accurate. This only needs to work when the device is not moving, where a gyro has no role. If you have a phone or tablet with sensors meant only to serve this purpose - therefore with no gyro or an inaccurate one - you are seeing a device limitation. The erratic values are other evidence that your device is low quality and/or that you are in a location where the earth's magnetic field is being distorted. Try the program on another (preferably expensive) device outside and in the open, and see what you get.