Is it possible to measure the how far the phone travels vertically

前端 未结 3 1485
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 05:02

I\'m just wondering if it is possible / where would I get started in measuring the upwards and downwards movement of an Android device. I\'d need it to be as accurate as possibl

3条回答
  •  粉色の甜心
    2021-02-09 05:47

    Case 1: Using GPS

    GPS built in in almost all android devices can provide position with best possible accuracy of about 2-3 meters horizontally and 4-5 meters vertically. If that vertical accuracy is ok for your case, you can get altitude before the movement starts, and when it ends, compare them and get vertical movement.

    If you need better accuracy, no android customer level device GPS can provide it. There are special professional GPS devices (used by land surveyors, costing 1000s of dollars, and very rarely running android os) that can provide cm-level accuracy, but this is not what we are talking about here.

    Ofcource, you need to be outdoors in order to have good GPS reception.

    Case 2: Using motion sensors

    If one knows initial speed, acceleration, and time can calculate distance moved. Have a look at this http://www.dummies.com/education/science/physics/finding-distance-using-initial-velocity-time-and-acceleration/

    We have

    distance=start speed+ (1/2) * acceleration * time^2

    In our case we know time (actually time-span) from the devices inbuilt clock, and we can get acceleration using the device's sensors. Note that TYPE_ACCELEROMETER sensor gives us acceleration force along each axis including gravity, so we have to subtract the gravitational force (we get it from TYPE_GRAVITY sensor). Keep in mind that when someone picks up a device, his hand doesn't necessarily moves in steady speed or acceleration. Therefore, changes in speed and acceleration must be taken into consideration.

    Concerning start speed there are several cases.

    In case it is zero (user is standing in a building, picks phone from a table and moves it to his ear) you just omit it from the formulas.

    In case it not zero so that

    speed=device speed+user's "vehicle" speed

    , we have to use GPS to calculate it. If the user is in a lifting helicopter we can do this. In case he is in a elevator or going up the stairs of a building we cannot because there is no GPS reception there. Things get more complicated in case the helicopter or the elevator accelerates too because there is no way to automatically separate helicopter/elevator acceleration from "user moving the device" acceleration. Same when the user is walking. In that case continuous changes of speed, acceleration and direction take place as he does his steps and the body moves up and down.

    I confess that I have no idea on the actual accuracy one can get in calculated distance by using the motion sensors method. And as you see from what I am writing there is no way I think to find a solution that works under every circumstances. But in the special case that the user is still and just moves the device vertically you can do something I believe.

    P.S. I am not getting into details on how to get GPS data or Motion sensor data from the device sensors because you can easily google it and find help on that. I believe what is more important is to understand the maths and physics that get involved in the devices vertical movement.

提交回复
热议问题