测量非固定Android设备的垂直移动 [英] Measuring vertical movement of non-fixed Android device

查看:107
本文介绍了测量非固定Android设备的垂直移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是制作一个可在骑自行车时测量道路质量的Android移动应用(SDK16 +).

My goal is to make an Android mobile app (SDK16+) that measures road quality while riding a bike.

我找到了一个适用于Android的传感器融合演示,对我来说所有的测量.

I have found a Sensor fusion demo for Android that I assume will do all the measurements for me.

当手机未固定在特定方向上时,如何仅获得垂直移动?

How can I get only the vertical movement when the phone is not fixed in a certain orientation?

推荐答案

问题

这里的问题是,您有两个坐标系统,设备的dx,dy,dz和周围世界的wX,wY,wZ.当您移动设备时,两者之间的关系会发生变化.

The problem here is that you have two systems of coordinates, the dx, dy, dz, of your device and the wX, wY, wZ of the world around you. The relationship between the two changes as you move your device around.

表达问题的另一种方式是说:

Another way to formulate your question would be to say:

给出传感器读数[dx,dy,dz],如何找到与wZ平行的读数分量?

Given a sensor reading [dx, dy, dz], how do I find the component of the reading which is parallel to wZ?

解决方案

幸运的是,方向传感器(例如Android自己的ROTATION_VECTOR传感器)提供了在这两个坐标系之间进行转换的工具.

Luckily, the orientation sensors (such as Android's own ROTATION_VECTOR sensor) provide the tools for transformation between these two coordinate systems.

例如,ROTATION_VECTOR传感器的输出采用轴角度表示设备在世界框架中固定的某些基本"旋转的旋转角度(另请参见:四元数).

For example, the output of the ROTATION_VECTORsensor comes in the form of an axis-angle representation of the rotation your device has from some certain "base" rotation fixed in the world frame (see also: Quaternions).

Android提供了方法SensorManager#getRotationMatrixFromVector(float[] R, float[] rotationVector),该方法从您的传感器获取轴角表示并将其转换为旋转矩阵.旋转矩阵用于将参照系中给定的向量转换为另一参照系(在本例中为[World-> Device]).

Android the provides the method SensorManager#getRotationMatrixFromVector(float[] R, float[] rotationVector), which takes axis-angle representation from your sensor and translates it into a rotation matrix. A rotation matrix is used to transform a vector given in one frame of reference to another (in this case [ World -> Device ]).

现在,您要将设备框架中的度量转换为世界框架吗?没问题.旋转矩阵的一个漂亮特征是旋转矩阵的逆是相反变换的旋转矩阵(在我们的例子中是[Device-> World]).另一个甚至更巧妙的事情是旋转矩阵的逆只是它的转置.

Now, you want to transform a measurement in the device frame into the world frame? No problem. One nifty characteristic of rotation matrices is that the inverse of the rotation matrix is the rotation matrix of the opposite transformation ([Device -> World] in our case). Another, even niftier thing is that the inverse of a rotation matrix simply is it's transpose.

因此,您的代码可以遵循以下代码:

So, your code could follow the lines of:

public void findVerticalComponentOfSensorValue() {
    float[] rotationVectorOutput = ... // Get latest value from ROTATION_VECTOR sensor
    float[] accelerometerValue = ... // Get latest value from ACCELEROMETER sensor

    float[] rotationMatrix = new float[9]; // Both 9 and 16 works, depending on what you're doing with it
    SensorManager.getRotationMatrixFromVector(rotationMatrix, rotationVectorOutput);

    float[] accelerationInWorldFrame = matrixMult(
            matrixTranspose(rotationMatrix), 
            accelerometerValue); 
    // Make your own methods for the matrix operations or find an existing library

    accelerationInWorldFrame[2] // This is your vertical acceleration
}

现在,我并不是说这是最好的解决方案,但它应该可以满足您的要求.

Now, I'm not saying this is the best possible solution, but it should do what you're after.

免责声明

将使用传感器融合的设备(包括磁力计)捆绑到金属框架上可能会产生不一致的结果.由于此处的指南针方向无关紧要,因此建议您使用不涉及磁力计的传感器融合方法.

Strapping a device that uses sensor fusion including a magnetometer to a metal frame may produce inconsistent results. Since your compass heading doesn't matter here, I'd suggest using a sensor fusion method that doesn't involve the magnetometer.

这篇关于测量非固定Android设备的垂直移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆