Not only the sampling rate is off, but also the data are very
unreliable.
See my thread for our findings:
http://groups.google.com/group/android-developers/browse_thread/thread/f92f0d648a1c274f

If someone from google could comment, I am sure it would become clear
that cell phone is just that.
It will never match a real device at the cell phone's price, unless
poorly manufactured.


On Jul 9, 8:52 am, "House n @ MIT" <to...@mit.edu> wrote:
> Hello,
>
> Has anyone been able to get theaccelerometeron the G1 to sample
> consistently for long periods of time?
>
> We’ve been doing some testing of the G1accelerometeron Android, and
> wanted to see if others have gotten the same result.  Our test uses a
> partial wake lock to keep the CPU alive.  It stores the xyz values and
> time to local storage and then writes them to a file on the SD card
> once a second.  The code below produces a csv file.
>
> The xyz values we’re getting are within the expected range, but the
> sample rate of theaccelerometervaries greatly.  To determine that
> using the file produced, for each sample, we found the difference
> between the sample’s timestamp (taken from the SensorEvent) and the
> timestamp from the previous sample.  The test results showed the time
> between samples ranging from 30 milliseconds up to 4.6 second
> spikes.
>
> We’re interested to know if other people are seeing similar behavior
> from their phones.  If you have the time and means, please run the
> code below and post your results.
>
> Thanks
>
> package edu.acceltest;
>
> import java.io.File;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.PrintWriter;
> import java.util.Arrays;
> import java.util.List;
> import java.util.Timer;
> import java.util.TimerTask;
>
> import android.app.Activity;
> import android.content.Context;
> import android.hardware.Sensor;
> import android.hardware.SensorEvent;
> import android.hardware.SensorEventListener;
> import android.hardware.SensorManager;
> import android.os.Bundle;
> import android.os.PowerManager;
>
> public class AccelTest extends Activity {
>
>         private SensorManager mSensorManager;
>         private PowerManager.WakeLock mWakelock;
>     private PowerManager mPowerMgr;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>                 // Set up theaccelerometerreading
>       mSensorManager = (SensorManager)getSystemService
> (Context.SENSOR_SERVICE);
>       // Get the list of all sensors, and find theaccelerometer
> within
>       List<Sensor> sensorList = mSensorManager.getSensorList
> (Sensor.TYPE_ACCELEROMETER);
>
>       mSensorManager.registerListener(mSensorListener,
>                   sensorList.get(0),
>                   SensorManager.SENSOR_DELAY_GAME);
>
>       mPowerMgr = (PowerManager)getSystemService(POWER_SERVICE);
>                 if (mWakelock == null)
>                 {
>                         mWakelock = 
> mPowerMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
>                                                                           , 
> "Test");
>                         mWakelock.acquire();
>                 }
>
>     }
>
>     @Override
>     public void onDestroy() {
>         if (mWakelock.isHeld())
>                 mWakelock.release();
>
>     }
>
>   //Accelerometer
>         private final SensorEventListener mSensorListener = new
> SensorEventListener() {
>
>                 private PrintWriter mCurrentFile;
>             private Timer second = null;
>                 boolean never = true;
>                 String comma = new String(",");
>                 volatile int index = 0;
>                 float zam[] = new float[2000];
>
>                 public void runOnce()
>                 {
>
>                         //Creating a file to print the data into
>
>                 String nameStr = new String("/sdcard/Activity - game
> cached.csv");
>                         File outputFile = new File(nameStr);
>                         mCurrentFile = null;
>                         try {
>                                 mCurrentFile = new PrintWriter(new 
> FileOutputStream(outputFile));
>                         } catch (FileNotFoundException e) {
>                                 // TODO Auto-generated catch block
>                                 e.printStackTrace();
>                         }
>
>                         // Create a 1-second timer to check the sample rate
>                         second = new Timer();
>                 second.scheduleAtFixedRate(new TimerTask() {
>
>                                 @Override
>                                 public void run() {
>
>                                                 // dump to file and reset 
> index, eventually overwriting all the
> data
>                                                 System.out.println("Sending");
>                                                 int a = 0;
>                                                 while(true)
>                                                 {
>                                                         if (zam[a*4] == 0)
>                                                                 break;
>                                                         StringBuffer buff = 
> new StringBuffer();
>                                                         
> buff.append(String.valueOf(zam[a * 4]));
>                                                         buff.append(comma);
>                                                         
> buff.append(String.valueOf(zam[a * 4 + 1]));
>                                                         buff.append(comma);
>                                                         
> buff.append(String.valueOf(zam[a * 4 + 2]));
>                                                         buff.append(comma);
>                                                         
> buff.append(String.valueOf(zam[a * 4 + 3]));
>                                                         
> mCurrentFile.println(buff.toString());
>                                                         a++;
>                                                 }
>                                                 mCurrentFile.flush();
>                                                 index = 0;
>                                                 Arrays.fill(zam, 0, 1999, 0);
>                                 }
>
>                   }, 1000, 1000);
>
>                 }
>
>                         @Override
>                         public void onAccuracyChanged(Sensor sensor, 
> intaccuracy) {
>                                 // TODO Auto-generated method stub
>
>                         }
>
>                         @Override
>                         public void onSensorChanged(SensorEvent event) {
>
>                                 if (never)
>                         {
>                                 never = false;
>                                 runOnce();
>                         }
>
>                                 zam[index] = event.timestamp;
>                                 zam[index + 1] = event.values[0];
>                                 zam[index + 2] = event.values[1];
>                                 zam[index + 3] = event.values[2];
>
>                                 index += 4;
>
>                         }
>           };
>
>
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to