Vertical movement sensor

后端 未结 2 1555
梦谈多话
梦谈多话 2021-01-18 10:02

I am working on an android app that requires the detection of vertical motion. When moving the tablet upward, the Gyroscope, Accelerometer, and Linear Acceleration sensors g

2条回答
  •  庸人自扰
    2021-01-18 10:06

    OK, I suspect it is only a partial answer.

    If you want to detect vertical movement, you only need linear acceleration, the device orientation doesn't matter. See

    iOS - How to tell if device is raised/dropped (CoreMotion)

    or

    how to calculate phone's movement in the vertical direction from rest?

    For some reason you are concerned with the device orientation as well, and I have no idea why. I suspect that you want to detect something else. So please tell us more and then I will improve my answer.


    UPDATE

    I read the post on coremotion, and you mentioned that higher z lower x and y means vertical motion, can you elaborate?

    I will write in pseudo code. You measured the (x, y, z) linear acceleration vector. Compute

    rel_z = z/sqrt(x^2+y^2+z^2+1.0e-6)
    

    If rel_z > 0.9 then the acceleration towards the z direction dominates (vertical motion). Note that the constant 0.9 is arbitrary and may require tweaking (should be a positive number less than 1). The 1.0e-6 is there to avoid accidental division by zero.

    You may have to add another constraint that z is sufficiently large. I don't know your device, whether it measures gravity as 1 or 9.81. I assume it measures it as 1.

    So all in all:

    if (rel_z > 0.9 && abs(z) > 0.1) { // we have vertical movement
    

    Again, the constant 0.1 is arbitrary and may require tweaking. It should be positive.


    UPDATE 2

    I do not want this because rotating it towards me is not moving it upwards

    It is moving upwards: The center of mass is moving upwards. My code has the correct behavior.

    Please come up with a mathematically sound definition of what you consider "moving upwards."

提交回复
热议问题