Problems with Accelerometer - random values

Put your problem here if it does not fit any of the other categories.

Problems with Accelerometer - random values

Postby kikoso » Tue Dec 08, 2009 2:13 pm

Hello all,

I'm using a HTC Magic in order to develop an application which makes
use of the accelerometer. Following the indications from tutorials and
the docs, this is a snapshot of the code I'm using:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /* Next code register the ACCELEROMETER SENSOR*/
  2.  
  3.   SensorManager mSensorManager = (SensorManager) getSystemService
  4.  
  5. (Context.SENSOR_SERVICE);
  6.  
  7.  
  8.  
  9.   List<Sensor> listSensors = mSensorManager.getSensorList
  10.  
  11. (Sensor.TYPE_ACCELEROMETER);
  12.  
  13.   Sensor acelerometerSensor = listSensors.get(0);
  14.  
  15.   mSensorManager.registerListener(this, acelerometerSensor,
  16.  
  17. SensorManager.SENSOR_DELAY_UI);
  18.  
  19.  
  20.  
  21. /*OnSensorChanged Method, here I receive the wrong values*/
  22.  
  23. public void onSensorChanged(SensorEvent event) {
  24.  
  25.                 // TODO Auto-generated method stub
  26.  
  27.                 synchronized (this) {
  28.  
  29.                           switch(event.sensor.getType()) {
  30.  
  31.                                     case Sensor.TYPE_ACCELEROMETER:
  32.  
  33.                                            for (int i=0 ; i<3 ; i++) {
  34.  
  35.                                                   mAccelerometerValues[i] = event.values[i];
  36.  
  37.                                            }
  38.  
  39.                          if ( mAccelerometerValues[0]  >= 1)
  40.  
  41.                                   //selectAndChange() send some HTTP Petitions and updates the screen
  42.  
  43.                                  selectAndChange(0, null,"",3);
  44.  
  45.                          else if ( mAccelerometerValues[0]  <= -1)
  46.  
  47.  
  48.  
  49.                                      [...]
  50.  
  51.  
  52.  
  53.                                 default:
  54.  
  55.                      }
  56.  
  57.  
  58.  
  59.              }
  60.  
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
I'm nevermind getting values that don't match with the accelerometer.
With the phone standing over my table, with no movement, I get values
like:

[0,0,15]
[0,6,8]
[0,0,0]

And sometimes the expected value:
[0,9.8,0]

I guess my SensorManager is kind of mixing all the other sensors, but
I do not guess where the problem could be. I have been checking other
codes, and in all of them the estructure is aproximately the same.

Any clues of what could I try?

Update: On same forums seems to be a problem with external electromagnetic influences:

https://groups.google.com/group/android ... 18e26683ab

I'm not using any music on my application, but video. Still don't have any clue on why this is happening
kikoso
Freshman
Freshman
 
Posts: 6
Joined: Thu Nov 12, 2009 11:41 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 10 guests