Determining roll angle (up/down) when Android phone is horizontal? - android

When the Android phone is on its side (horizontal orientation), the Roll represents the tilt, so to speak. When the phone is perpendicular to the ground (looking directly at the screen), the roll says 90. However, when you start tilting it forward or backward, as if you wanted to look down or up, the angle just decreases either way.
This means looking up or down 45 degrees gives the same roll or 45 degrees.
How is it possible to know if you are rolling it forward or backward?
I have been looking around for an answer to this, and can't find anyone else with this problem. Judging from different apps, it seems to be possible, so I think I am just missing some relationship to something, and was hoping someone might be able to nudge me in the right direction. Thanks!

The way I fixed this was with the accelerometer data. Watch to see if the Z axis is positive or negative, and then adjust the roll value accordingly.

Related

How to calculate angle of a device keeping device parallel to the ground

I am trying to find the compass type angle, ie. when device is kept parallel to the ground and then if you rotate it along the line passing through the table. eg. the one mentioned in How to detect android device rotation parallel to the ground?
But the problem with above question which is already answered is that one of the link isn't working and other shows ORIENTATION_TYPE which is deprecated.
Currently I am using TYPE_ROTATION_VECTOR, which gives Roll(holding device with your face watching forward and device facing you and then tilting it to left and right) and pitch(again holding device with straight face forward and try to keep it on table). These are calculated accurately. But the azimuth angle which this TYPE_ROTATION_VECTOR provides, is (again keep the device with your face forward and then device faces you and then rotate it along the line going from floor to ceiling).
So, how to actually calculate accurately the angle when device is kept on table and you rotate it along the line passing from floor to ceiling?
Apologies if I am unclear as its difficult to explain in words. If I am not clear, will try to explain with images.

Unity C# device movement direction capture

Good day.
I want to make an app which is somewhat very close to the device movement.
In example: If the device moves backward, the unity 3D object should move backward, if forward then the object goes forward in 3D environment, then same and for left and right.
Anyway the workaround i have googled only brought me to accelerometer, which I don't need, as accelerometer is used to detect the tilt and not actual movement. So i wanted to ask, is that even possible to detect the movement of device in unity? If yes, what classes should i look for to achieve what i want.
Thank you beforehand.
Jow Blow's comment is correct: The accelerometer gives the acceleration (you don't say). Tilt can be found from the amount of acceleration, but other movements will be seen as well. If you are standing still and start moving forward, your accelerometer value will show it (since you accelerated).
There is no device that will measure if you are moving forward at constant speed on your phone. If you know a bit of physics you find more obvious why the accelerometer doesn't work: because constant speed means that the resultant of forces is null. So there is no force to detect.
If you need to detect constant speed and plan to move for a rather big distance, however, you could try using the GPS position but if you need a high precision, you won't be able to do it with a standard device.
Forget about detecting moving at constant speed on a short distance easily. A solution could be to detect an acceleration and estimate the direction and speed resulting from it (speed = time*acceleration). This method won't be really precise as any error will add up but it could be sufficiant

How to use accelerometer on Android Wear to record rowing stroke

My goal is to have a simple stroke rate detector displayed on my Android Watch (Sony Smartwatch), for this I need to detect when the watch changes from moving forwards to moving backwards.
I have code working that will get the event values (x,y,z) as detected in the onSensorChanged event (and display them on the watch), but I am struggling to make sense of these.
I understand the values report acceleration in the given axis, and I understand that z reports gravity. But if these values are reporting just acceleration, I am not clear how to know when there is a change of direction. I presume a positive number indicates acceleration, a number of 0 is a constant speed and a negative number is deceleration...is that correct? And if so, how can I detect when the Watch has changed direction from going forwards to going backwards?
Thanks in advance.
Android Wear is no different than "conventional" Android when it comes to detecting motion. Basically, you need to consider exactly what the accelerometers are recording: raw acceleration (with a lot of noise). To determine motion from that, you need to look at trends over time, and probably integrate the smoothed accelerometer data. It's not trivial.
You'll probably want to use the TYPE_LINEAR_ACCELERATION sensor, because it filters out gravity (which isn't relevant to your use case). And because the watch will probably experience some rotation during a rowing stroke (which you want to factor out), you may need to combine TYPE_ROTATION_VECTOR with the acceleration vector to accurately determine direction changes.
A couple of other SO questions which may help point you in the right direction:
how to calculate phone's movement in the vertical direction from rest?
How can I get the direction of movement using an accelerometer?
I've not attempted this specific problem, of course, but I've done enough other work with Android motion sensors to know that you have a good programming challenge ahead of you. Enjoy it!

How to use Android Accelerometer to control a character?

Say I have a character walking around in 2d space. Lets say my phone is flat on a table in landscape orientation.
If I tilt the phone away from me, the character should start moving up. If I tilt it towards me she should start moving down. Same goes for right and left.
The reason I ask here is because I found Google's explanation rather confusing.
http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix%28float%5b%5d,%20float%5b%5d,%20float%5b%5d,%20float%5b%5d%29
This link implies the x and y are relative to compass coordinates? I can't imagine that's how the accelerometer works. I just want to do this relative to the phone being tilted on a certain axis.
For example, should the phone tilt away from me, I feel it should be easy to say "the phone is tilting ___ radians positively on the y axis." Then I should just be able to use trig to calculate the acceleration on my character.
I guess my real question is how do I read from the accelerometer and determine to what angle the phone is tilting on a given axis. This image details how I currently think the axis are laid out on the phone.
I'm sure this has been asked before, so a link to a good source of question solving is awesome as well.

Determining heading in Inertial Navigation Systems

I have a question regarding inertial navigation with a mobile device.
I am using an android tablet for development but I think the question is related to
all types (even with better sensors) of hardware.
The most basic question when developing an inertial system is how to determine the
direction of the carrier's movement.
Even if we assume that the magnetometer readings are 100% accurate (which they are obviously not!) There is still the question of the device orientation relative to the user.
Simple example - if the user is walking north, but holds the device with the device's Y axis points north-east, (a link to a picture of the different axis: http://developer.android.com/reference/android/hardware/SensorEvent.html)
Then the magnetometer will point towards north-east.
How can we tell which way the user is actually heading?
(The same will be true if we use both magnetometer and Gyro for determining heading)
A possible solution will be to use the Accelerometer's Y-axis and X-axis readings.
Something in the direction of using arctan(a-Y/a-X)
(for example - if the user holds the device perfectly straight, then the X-Axis will show nothing...)
But since the Accelerometer's readings are not stable, it is not so easy...
Does anyone know of an algorithm that actually works? I am sure this is a well known problem, but I can't seem to find references to solutions...
Thanks in advance!
Ariel
See this answer for an idea: by obtaining the acceleration values in relation to the earth, you can then use the atan2 function to compute the actual direction.
You mention the user holds the tablet, and I assume fairly stable (unlike a case I am working on, where the user moves the phone constantly). Yet, for some reason, the user may change the orientation of the device, and this may influence the readings you obtain.
Thus, in the event of an orientation change, you should call remapCoordinates() accordingly to fix the readings you obtain.
NOTE: You can also use the getOrientation() method accordingly, and the first field represents the heading direction.
The really right answer is to leave the device sitting there for a while, detect the rotation of the earth, and then compute true north from that. Unfortunately, the gyros in a mobile phone aren't accurate enough for that....

Categories

Resources