Android Java:如何平滑通过计算加速度计和磁力计读数获得的方位角?

问题描述

我正在实现一个应用,主要用于捕获走廊尽头的用户旋转,其中用户将在已知距离的走廊中来回旋转,并计算每次旋转所覆盖的距离。

>

目前,该应用通过加速度计和磁力计传感器的传感器融合构建,以度数计算方位角,并进行其他计算以捕获用户旋转。该应用还旨在计算用户完成的步数。

 public void rotateUsingOrientationAPI(SensorEvent event) {

    // Checking the source of the data
    // copies an array from the specified source array,beginning at the specified position,// to the specified position of the destination array.
    if (event.sensor == mAccelerometerSensor) {
        System.arraycopy(event.values,mLastAccelerometer,event.values.length);
        mLastAccelerometerSet = true;
    } else if (event.sensor == mMagnetometerSensor) {
        System.arraycopy(event.values,mLastMagnetometer,event.values.length);
        mLastMagnetometerSet = true;
    } else if (event.sensor == mStepCounter){
        // This flag is true every time the timer is running.
        if(counterIsActive){
            updateUIFlag = true;
            startFlag = true;

            // Passing the values to the step counter function.
            stepCounter(event);
        }
    }

    // Computing the azimuth angle from both sensor readings.
    if (mLastAccelerometerSet && mLastMagnetometerSet) {

        SensorManager.getRotationMatrix(mRotationMatrix,null,mLastMagnetometer);
        // "mRotationMatrix" Now has up-to-date @R_191_4045@ion.

        SensorManager.getorientation(mRotationMatrix,mOrientation);
        // "mOrientationAngles" Now has up-to-date @R_191_4045@ion.

        // Getting the azimuth angle in radian
        float azimuthInradians = mOrientation[0];

        // converting the azimuth angle to degree
        azimuthInDegress = (float) (Math.todegrees(azimuthInradians) + 360) % 360;
        // Log.d("this is my azimuthIndegrees First","Value: " + String.valueOf(azimuthInDegress));

        // Setting up an azimuth array that will store the real-time angle and delayed angle
        azimuthArray = new float[]{azimuthInDegress,delayedAzimuth};
        Log.d("this is my azimuthArray Array","Value: " + Arrays.toString(azimuthArray));

        // Calling this function to calculate delay 3000ms to the real-time azimuth angle
        delayedAzimuthDegree(azimuthInDegress);
        // Log.d("this is my delayedAzimuth","Value: " + String.valueOf(delayedAzimuth));

        if(counterIsActive){
            // Calling this function for rotation detection once the counter is active
            rotationCounterFunction();
        }
    }
}

问题是,这个应用不是很准确,因为没有对方位角信号进行预处理,导致它波动很大,并且缺少旋转,因为这个应用是为医疗目的而构建的,它应该有很高的准确度。

我如何计算旋转? Ans:通过在一定的延迟时间内对来自传感器的每两个值进行逻辑区分,如果角度差大于 120 度(假设),则旋转增加

我的问题: 1- 我可以对预处理算法/方法提出建议,以平滑信号以获得更准确的结果,因为方位角应该清楚地区分旋转变化与正常身体行走。

2- 假设我的逻辑是错误的(两个方位角值之间的差异),您将如何检测旋转,我还应该说这部分可能会得到改进,所以如果您愿意分享您对此处理的意见和方法,它可能对项目的准确性有很大帮助。

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)