Take the lifting angle?

Can an elevation angle be obtained from an accelerometer? For those of you who don't know, elevation angle:
angle of elevation
Is this possible with accelerometer measurements?

+2
java android math accelerometer
Mar 12 '11 at 18:23
source share
2 answers

It’s actually not possible to get this “elevation angle” to the line of sight, since you don’t know where the user is ...

What you can do is assume that the user is orienting the device’s screen right in front of his eyes.

Under this assumption, you can use http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix (float [], float [], float [], float []) to get the device orientation and get the angle between the y axis and the plane (x, z).

What he does is that he uses an accelerometer on the 3rd axis to see what the direction of gravity is.

This will only work when the device is stationary. If you need to better cope with the movement, you should use a gyroscope if it exists on the device.

Another thing is that, depending on your application, you can take a look at some frameworks of augmented reality if this is the application in which you are looking.

Edit: Here is the code I compiled. The main function in my code:

public void onSensorChanged(SensorEvent event) { int sensor = event.type; float[] values = event.values; int i; StringBuffer str=new StringBuffer(); // do something with the sensor data TextView text = (TextView) findViewById(R.id.my_text); float[] R = new float[9]; // rotation matrix float[] magnetic = new float[3]; float[] orientation = new float[3]; magnetic[0]=0; magnetic[1]=1; magnetic[2]=0; str.append("From Sensor :\n"); for(i=0;i<values.length; i++) { str.append(values[i]); str.append(", "); } SensorManager.getRotationMatrix(R, null, values, magnetic); SensorManager.getOrientation(R, orientation); str.append("\n\nGives :\n"); for(i=0;i<orientation.length; i++) { str.append(orientation[i]); str.append(", "); } text.setText(str); } 

I did not try to use a real device, only on the emulator and SensorSimulator .

If you want the whole source package with several tools that you need for a touch device, write to me, I have everything packed.

Instead of compiling magnetic data, you can actually get it from a compass. What you are looking for is a step that in orientation[1] ranges from -pi / 2 to pi / 2.

Hope this helps.

+1
Mar 12 '11 at 18:55
source share

When measuring motion, there is usually no concept of orientation. To calculate the angle relative to the Earth, you can use a multi-axis accelerometer that measures static acceleration (acceleration due to gravity).

Most android phones come with a number of sensors, such as a gyroscope, etc. that can interact. See Javadocs for SensorManager and various types of SensorEvents .

+2
Mar 12 '11 at 18:36
source share



All Articles