Get Device Moving Direction without GPS
Asked Answered
L

2

1

With Which Sensor I Can Detect when device is moving to a direction In Absolute Coordinate(for example moving to +x or -x).

I need accurate data,so i cannot use GPS.

the Complete Task is to plot in paint(in computer) with android device sensors and this part of task in unknown for me.

Lorileelorilyn answered 25/11, 2014 at 21:40 Comment(5)
I suggest the gyro mouse for this. All other solutions that I can think of would be worse and more complicated to implement.Cappuccino
@Cappuccino thanks but thats in iphone,do you suggest the first part of explanations of Edward Falk for my choice(in Android) too?Lorileelorilyn
The gyro mouse is 3 lines of code and it is device independent. Please forgive me for not looking up the corresponding Android API. The gyro mouse is what I suggest, assuming I understood your real goal correctly ("the Complete Task is to plot in paint(in computer) with android device").Cappuccino
So where is that "3 lines of code"?Lorileelorilyn
Read the answer I linked; watch the video I mention in my answer. If you still have questions, post a new and more specific question.Cappuccino
L
3

I'm a little confused about what you're asking. Do you want to put a device in your pocket and walk around, and make a plot of everywhere you walked? Or do you want to wave the device around in your hand like a 3-d mouse, for painting?

For the latter, see Ali's suggestion above. If you want to do motion tracking, here is what I can tell you:

You can easily use accelerometer (or gravity if available) plus magnetometer combined with SensorManager.getRotationMatrix() to know which direction the device is facing.

In fact, the ROTATION sensor does all this for you. You just need enough math to convert a quaternion into a transformation matrix; it's pretty easy.

(If you're trying to implement a gyro mouse, you can stop reading here.)

Then you can use the linear acceleration sensor to determine the direction the device is moving. This would be a sort of poor man's inertial navigation system. But that assumes the device is sitting still when you start the app, and that the sensors are really precise enough to do what you want.

The acceleration will give you a vector in device coordinates. Multiply that vector by the matrix you got from the ROTATION sensor or SensorManager.getRotationMatrix() to get an acceleration vector in world coordinates. Then integrate that vector over time to get a velocity vector and then integrate that vector over time to get distance and direction moved since you started the app.

Errors will accumulate rapidly. This algorithm is probably good for a few minutes at best before it starts returning complete nonsense. You could tune the application to detect when the device is no longer moving, and use that opportunity to reset the velocity vector to zero.

Frankly, this is a very very hard problem to solve. There's probably a PhD or at least a couple of papers in it for you if you solve it. Search for the term "indoor navigation" for more references.

But bear in mind that without some sort of location service (network or gps), there's really no way to be sure which direction the device is moving or where it is.

My understanding is that all the existing indoor navigation algorithms depend on getting occasional GPS fixes, or by knowing the layout of the indoor space being navigated and using it for clues, or by knowing the locations of nearby WiFi transmitters and using their signal strengths to generate fixes.


Seriously, unless you're talking very small distances here, GPS is your best bet.

Lorient answered 26/11, 2014 at 17:17 Comment(4)
Oh, one more point: There's a difference between true north and magnetic north. You'll need geomagnetic coordinates to know how much to adjust heading to compensate for magnetic deviation. I believe there's an Android class available just to do that.Lorient
In that case, you probably want to receive the ROTATION sensor and convert the quaternion into a transformation matrix. This is pretty easy to do; just google it.Lorient
do you mean ORIENTATION sensor?i will google and hope to find,if you have know any tutorial or source please give the link,thanksLorileelorilyn
ORIENTATOION sensor is deprecated for good reasons. It falls apart (degenerate states) when held close to vertical. Your best approach is to use the ROTATION sensor, which returns a quaternion. It's fairly easy to convert a quaternion to a 3x3 transformation matrix.Lorient
C
0

Since Android API level 24, there is a sensor called TYPE_POSE_6DOF. On phones that support this, it will use the sensors and camera tracking to provide both relative and absolute rotation and position in 3D space. https://developer.android.com/reference/android/hardware/Sensor#TYPE_POSE_6DOF https://developer.android.com/reference/android/hardware/SensorEvent#values

Another option might be to use ARCore, which will provide similar values for the camera pose. https://developers.google.com/ar/reference/java/arcore/reference/com/google/ar/core/Pose

Finally, this video gives a great overview of the Android sensors (pre-ARCore). Specifically, the section around 23:23 explains why doing a double-integral of the accelerometer force will not provide a useful representation of position. https://www.youtube.com/watch?v=C7JQ7Rpwn2k

(In case anyone was wondering, I just tried doing a double-integral of the accelerometers for a project I was working on, but I kept getting non-zero velocity when the device returned to rest, which caused significant drift in the position value, even over the course of 1 second.)

Cowled answered 29/1, 2019 at 5:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.