-2

I'm writing an Android game that uses a gyroscope and I need to take the largest possible gyroscope value.


I know how to get the gyroscope value. I need to take the largest possible gyroscope Z value because each telephone has a different gyroscope and a different maximum value of the gyroscope.

elixenide
  • 44,308
  • 16
  • 74
  • 100
anonym756
  • 1
  • 1

2 Answers2

0

You can implement a SensorEventListener in your activity or in a specific class.

Then you can get values from gyroscope instantiating a SensorManager

SensorManager sensorManager;
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

Then set a SensorSensor.TYPE_GYROSCOPE

Sensor gyroscope;
gyroscope = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

And override these 2 methods

@Override
public void onSensorChanged(SensorEvent event) {
    // Here you get values from the gyroscope
    if (event.sensor == gyroscope) {
        double accX = event.values[0];
        double accY = event.values[1];
        double accZ = event.values[2];
    }
}

@Override
public void onAccuracyChanged(Sensor sensor, int i) {

}

For more specific references: Android motion Sensors

P.S. Don't forget to check if the sensor is != null

Roberto Manfreda
  • 2,345
  • 3
  • 25
  • 39
0

There are no methods in libgdx that will allow you to get the max value for accelerometers as they are hardware based and no API exists AFIAK.

From this answer it appears to be that typical values are +/- 2G

dfour
  • 1,376
  • 1
  • 12
  • 16