I am trying to measure angle at which my phone is using accelerometer. I refer to the method demonstrated here. But the problem is that when I rotate my phone at a high speed, it skips readings. For example, if I rotate my phone from 0 degrees to 90 degrees within a second, I get readings in logcat as : 0, 50, 90. What I really want is to obtain all the values through which the phone has rotated, like 0,1,2,...,90. Is it possible? If yes, what am I missing? Do I need to use gyroscope/magnetometer as well?
Basically it was the sensor delay which was causing the issue. I resolved it by setting the delay to SensorManager.SENSOR_DELAY_FASTEST.
Related
I want take photo and try to do it on the inclination of 180 degrees +/- 5 degrees, in other degrees camera should be blocked.
In brief I want force take photo horizontally to floor (or close to it).
What is the easiest way? I should use gyroscope? The problem is that angle must be checked all the time that degree is good.
Use orientation sensor. Framework reports to you when value of sensor is changed, so as long as you keep sensor registered for usage, you will have actual device orientation.
Retrieve SensorManager by calling context.getSystemService(Context.SENSOR_SERVICE). Also look at Android Orientation sensor for rotation the 3D cube
I'm trying to move a game object when i raise/lower (Shake) my phone but I don't know how get the device's movement. I already know about Input.acceleration but that just gives me the devices rotation and I want it's actual movement.
Is this possible and how would I go about doing it?
Accelerometer reads the sum of: changes in movement (acceleration) + constant force of gravity. You can use it for directional movement in two ways:
Detect changes of gravity angle - when the device is not moving (or is moving at a constant speed) and is parallel to the ground, the accelerometer will read Earth's gravity, ie: new Vector3(0,-9.81,0). When the device is tilted (so not parallel to the ground), the vector's length will still be 9.81, but it will be rotated a bit like. new Vector3(3.03, -9.32, 0) (this example is rotation in one axis by 56 degrees (pi/10)). Using this will yield this kind of controlls: https://www.youtube.com/watch?v=3EU3ip4k0uE
Detect peaks of acceleration. When the device is still or moving with constant speed, the length of acceleration vector will be equal 9.81, when it changes/starts movement, this number will change. You can detect these changes and interpret this as one time momentary movement (like pressing an arrow).
There are alternatives not using an accelometer, for example you can detect some printed marker with Vuforia: https://www.youtube.com/watch?v=8RnlBEU5tkI - interpret the relative position to the marker as and action in a simmilar fashion as you'd detect acceleration change in #1.
Nexus 4.
I specially use System.out.println to print out the rotation on LogCat, to observe the value when I rotate my device.
int orientation_photo = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
System.out.println("For Debug: orientation_photo: " + orientation_photo);
The rotation (0, 1, 2 or 4) is not prcise at all. Sometimes I have rotated 90 degrees, but the rotation value does not change.
However, believe Nexus 4 device can detect it correctly, from the orientation performance of its default camera, which always record a correct orientation, so that we can view pictures in a correct way.
I need a correct rotation value, so that I could put in ExifInterface of the photo .jpg file.
Any help?
You are fetching the orientation of the UI, not the orientation of the phone itself. For various reasons they do not always match. In particular, many devices will never rotate their UI 180 degrees.
You probably want to look at the SensorManager class: http://developer.android.com/reference/android/hardware/SensorManager.html
I think I find the answer, that is: Yes, it is not precise, from the basic physical principle, because the orientation is subjective.
I would like to develop a personal app for this i need to detect my car's rotation.
In a previous thread i got an answert to which sensors are good for that it's okay.
Now i would like to ask you to please summerize the essential/needed mathematical relationship.
What i would like to see in my app:
- The car rotation in degrees
- The car actual speed (in general this app will be used in slow speed situation like 3-5km/h)
I think the harder part of this is the rotation detect in real time. It will be good to the app could work when i place the phone in a car holder in landscape or portrait mode.
So please summerize me which equations,formulas,realtionships are needed to calculate the car rotation. And please tell me your recomendation to which motion/position sensor are best for this purpuse (gravity,accelerometer,gyro,..)
First i thought that i will use Android 2.2 for better compatibility with my phones but for me 2.3.3 is okay too. In this case i can use TYPE_ROTATION_VECTOR which looks like a good thing but i don't really know that it can be a useful for me or not?
I don't want full source codes i would like to develop it myself but i need to know where can i start, what deep math knowlegde needed and what part of math are needed. And for sensor question: i'am a bit confused there are many sensors which are possible ok for me.
Thanks,
There is no deep math that you need. You should use TYPE_MAGNETIC_FIELD and TYPE_GRAVITY if it is available. Otherwise use TYPE_ACCELEROMETER but you need to filter the accelerometer values using Kalman filter or low pass filter. You should use the direction of the back camera as the reference. This direction is the azimuth returned by calling getOrientation, but before calling getOrientation you need to call remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR) to get the correct azimuth. Then along as the device is not laying flat, it does not matter what the device orientation is (landscape or portrait). Just make sure that the phone screen is facing the opposite direction of the car direction.
Now declare two class members startDirection and endDirection. In the beginning, startDirection and endDirection have the same values, now if the azimuth change by more than say 3 degrees, there is always a little fluctuation, then change the endDirection to this value and continue to change until say 20 returned azimuth have the same values (you have to experiment with this number). This mean that the car stop turning and then you calculate the difference between startDirection and endDirection, this gives you the degree of rotation. Now set startDirection and endDirection to this new azimuth and wait for next turn.
I want to know about the values of X,Y and Z axis for any position/movement of device so I can use these values for my further work. As I searched there are two methods, Orientation Sensor(gives value in degree,as azimuth,pitch and roll) and Accelerometer(gives values between 1 to 10 for x,y and z).
As per my understanding both are same for my requirement. I can't find difference between them. Please can any one clear me about them in detail w.r.t my aim. which sensor should I use?
There are differences between both:
Accelerometer detects acceleration in space. The reason why it will always detect an acceleration of 9.8m/s^2 downwards is because gravity is equivalent to acceleration in space.
Orientation detects if your device's axis are rotated from the real-world; it detects tilts and and degrees from the magnetic North. Please note that this sensor is deprecated and Google recommends you use the accelerometer and magnetometer to calculate orientation.
You'll need the accelerometer to detect movement. So you should use this one, since your aim is to know this movement.
The orientation sensor gives information about its position compared to a reference plane. So you could use this to see of the device is tilted, upside down or something like that.