Acceleration from device’s coordinate system into absolute coordinate system

I finally managed to solve it! So to get acceleration vector in Earth’s coordinate system you need to: get rotation matrix (float[16] so it could be used later by android.opengl.Matrix class) from SensorManager.getRotationMatrix() (using SENSOR.TYPE_GRAVITY and SENSOR.TYPE_MAGNETIC_FIELD sensors values as parameters), use android.opengl.Matrix.invertM() on the rotation matrix to invert it (not transpose!), use Sensor.TYPE_LINEAR_ACCELERATION sensor … Read more

Is there a way to retrieve multiple sensor data in Android

Can you try something like this: private SensorManager mSensorManager; private SensorEventListener mSensorListener; //// mSensorManager = (SensorManager) this .getSystemService(Context.SENSOR_SERVICE); mSensorListener = new SensorEventListener() { @Override public void onAccuracyChanged(Sensor arg0, int arg1) { } @Override public void onSensorChanged(SensorEvent event) { Sensor sensor = event.sensor; if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { //TODO: get values }else if (sensor.getType() == Sensor.TYPE_ORIENTATION) … Read more

Transforming accelerometer’s data from device’s coordinates to real world coordinates

Oki, I have worked this out mathematically myself so please bear with me. If you want to translate an acceleration vector accelerationvalues into an acceleration vector trueacceleration expressed in real world’s coordinates, once you have azimuth,pitch and roll stored in a orientationvalues vector, just do the following: trueacceleration[0] =(float) (accelerometervalues[0]*(Math.cos(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.sin(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[1]*(Math.cos(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[2]*(-Math.sin(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.cos(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0]))); trueacceleration[1] … Read more

Why is accelerometer:didAccelerate: deprecated in IOS5?

I did not yet use iOS 5, but already in 4.x UIAccelerometer and UIAccelerometerDelegate were replaced by the CoreMotion framework. It is more sophisticated, takes gyroscope signals into account and performs a sensor fusion i.e. does calibrating stuff like bias calculation for you. Basically the CMDeviceMotionHandler block callback is now the equivalent. It is called … Read more

Moving an image using Accelerometer of android

Use this code. You were never setting the location of the drawable after you intialized that class. You’ll have to do some calculations to set the balls location properly. The way you were doing it was getting values over 10000 which was drawing the oval off screen. import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; … Read more