栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

My Algorithm to Calculate Position of Smartphone - GPS and Sensors

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

My Algorithm to Calculate Position of Smartphone - GPS and Sensors

As some of you mentioned you got the equations wrong but that is just a part
of the error.

  1. Newton - D’Alembert physics for non relativistic speeds dictates this:

    // init values

    double ax=0.0,ay=0.0,az=0.0; // acceleration [m/s^2]
    double vx=0.0,vy=0.0,vz=0.0; // velocity [m/s]
    double x=0.0, y=0.0, z=0.0; // position [m]

    // iteration inside some timer (dt [seconds] period) …
    ax,ay,az = accelerometer values
    vx+=axdt; // update speed via integration of acceleration
    vy+=ay
    dt;
    vz+=azdt;
    x+=vx
    dt; // update position via integration of velocity
    y+=vydt;
    z+=vz
    dt;

  2. the sensor can rotate so the direction must be applied:

    // init values

    double gx=0.0,gy=-9.81,gz=0.0; // [edit1] background gravity in map coordinate system [m/s^2]
    double ax=0.0,ay=0.0,az=0.0; // acceleration [m/s^2]
    double vx=0.0,vy=0.0,vz=0.0; // velocity [m/s]
    double x=0.0, y=0.0, z=0.0; // position [m]
    double dev[9]; // actual device transform matrix … local coordinate system
    (x,y,z) <- GPS position;

    // iteration inside some timer (dt [seconds] period) …
    dev <- compass direction
    ax,ay,az = accelerometer values (measured in device space)
    (ax,ay,az) = dev(ax,ay,az); // transform acceleration from device space to global map space without any translation to preserve vector magnitude
    ax-=gx; // [edit1] remove background gravity (in map coordinate system)
    ay-=gy;
    az-=gz;
    vx+=ax
    dt; // update speed (in map coordinate system)
    vy+=aydt;
    vz+=az
    dt;
    x+=vxdt; // update position (in map coordinate system)
    y+=vy
    dt;
    z+=vz*dt;

    • gx,gy,gz
      is the global gravity vector (
      ~9.81 m/s^2
      on Earth)
    • in pre my global
      Y
      axis points up so the
      gy=-9.81
      and the rest are
      0.0
    • measure timings are critical

Accelerometer must be checked as often as possible (second is a very long
time). I recommend not to use timer period bigger than 10 ms to preserve
accuracy also time to time you should override calculated position with GPS
value. Compass direction can be checked less often but with proper filtration

  1. compass is not correct all the time

Compass values should be filtered for some peak values. Sometimes it read bad
values and also can be off by electro-magnetic polution or metal enviroment.
In that case the direction can be checked by GPS during movement and some
corrections can be made. For example chech GPS every minute and compare GPS
direction with compass and if it is constantly of by some angle then add it or
substract it.

  1. why do simple computations on server ???

Hate on-line waste of traffic. Yes you can log data on server (but still i
think file on device will be better) but why to heck limit position
functionality by internet connection ??? not to mention the delays …

[Edit 1] additional notes

Edited the pre above a little. The orientation must be as precise as it can
be to minimize cumulative errors.

Gyros would be better than compass (or even better use them both).
Acceleration should be filtered. Some low pass filtering should be OK. After
gravity removal I would limit ax,ay,az to usable values and throw away too
small values. If near low speed also do full stop (if it is not a train or
motion in vacuum). That should lower the drift but increase other errors so an
compromise has to be found between them.

Add calibration on the fly. When filtered

acceleration = 9.81
or very close
to it then the device is probably stand still (unless its a flying machine).
Orientation/direction can be corrected by actual gravity direction.



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442752.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号