Home Development for Android HTC Desire sensor data

HTC Desire sensor data

by admin

Introduction

Hi HubraSociety! I’ve been wanting to write an article fora longtime, as I once had to work with data from the HTC Desire sensors running Android.
HTC Desire sensor data
The goal was : to determine the displacement of the object. That is, from the data from the sensors it was possible to get the values of the accelerations and the time moments of these measurements. Then by processing the data to calculate the velocity and then the displacement.

Data handling

To begin with I had to tinker with the development environment for android. I had no experience with Eclipse programming in Java before and I had to learn the basics. In the end I created an application which was able to save data in a SQLite database on a microSD card. Here was the first data I was able to get:
HTC Desire sensor data
This is a graph of the acceleration (Y-axis) vs. time (X-axis), in thisexperiment the phone was just pushed on the table so it slid. Then all sorts of tests went on, I wanted to check for example the saturation value of the sensors (the maximum measurable value of acceleration). The phone moved alonga circular path with a gradual acceleration. The graph of the data below:
HTC Desire sensor data
Sensor saturation occurred at a value of about 18.35 m/c^2.
Next I wanted to try to process the data obtained :
HTC Desire sensor data
Here is an example also of the phone sliding on the table : the blue line is acceleration, the red line is speed and the green line is displacement. This one is not very good, one of the first examples. The displacement could not be detected here.
Here, a more perfect example of a similar experience :
HTC Desire sensor data
Here, after processing the data, a plausible value for moving the phone across the table was obtained.
Next, I wanted to see what the data would look like when walking with the phone :
HTC Desire sensor data
And also when running with the phone :
With the walking and running examples it is already clearly seen how the various errors from the sensors accumulate, a detailed study of the processes of acquiring all this data is needed to further eliminate them. In particular, here the data is only from one X-axis, there is no consideration of the effect of gravity on the acceleration sensors (does not take into account the rotation in space of the phone). Here is an example in which this rotation, hence the effect of gravity was excluded from one of the axes :
HTC Desire sensor data
in this experiment, the phone was lying on the table, and one of its sides was raised to the ghost of the phone’s perpendicular position to the table. Here the red line is the angle (obtained from the compass), the green is the value on the acceleration sensor (essentially the value = acceleration +gravity), and the purple is the acceleration value (corrected for the angle values). That is, in this example it was possible to exclude the effect of gravity.

Conclusion

This question is very interesting, and the examples given are just a small manifestation of my curiosity. As it turns out, the frequency of measurements from these sensors is not enough to get really good data, but I think when I have time I will study this issue in more detail.
UPD: I dug out source code of a variant of this program. Please don’t be too hard on me, it’s just an introduction to Java for android:

package com.dimond.acc;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.database.sqlite.SQLiteDatabase;
public class acc extends Activity implements SensorListener {
public class AXYZTdata
{
float ax;
float ay;
float az;
long time;
public AXYZTdata( float in_ax, float in_ay, float in_az, long in_time)
{
ax = in_ax;
ay = in_ay;
az = in_az;
time = in_time;
}
}
SensorManager sm = null ;
final String tag = "logging" ;
private EditText MassivN;
TextView DataText;
String TimeNowtmp;
int N, sec, stroka=0;
AXYZTdata[] mass = new AXYZTdata[10000];
float acc_x, acc_y, acc_z, acc_time = 0;
SQLiteDatabase mDatabase = SQLiteDatabase.openOrCreateDatabase( "/mnt/sdcard/DB/" +String.valueOf(System.currentTimeMillis())+ ".db" , null );
int onoff=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
Button start = (Button) findViewById(R.id.Start);
Button stop = (Button) findViewById(R.id.Stop);
Button write = (Button) findViewById(R.id.Write);
DataText = (TextView) findViewById(R.id.data);
//data database creation string
String DATABASE_CREATE =
"create table accdb" +
"(_id integer primary key autoincrement, " +
"acc_x text not null, " +
"acc_y text not null, " +
"acc_z text not null, " +
"time_h_m_s text not null);" ;
mDatabase.execSQL(DATABASE_CREATE);
//signature for the event of pressing the Start
start.setOnClickListener( new OnClickListener() {
public void onClick(View arg0)
{
startwrite();
}
});
//signature for the event of pressing the Stop
stop.setOnClickListener( new OnClickListener() {
public void onClick(View arg0)
{
stopwrite();
}
});
//signature for the event of clicking on the Record
write.setOnClickListener( new OnClickListener() {
public void onClick(View arg0)
{
masstosql();
DataText.setText( "Writed!!!" );
}
});
}
public void startwrite()
{
onoff=1;
return ;
}
public void stopwrite()
{
onoff=0;
DataText.setText(String.valueOf(stroka));
return ;
}
public void masstosql()
{
long StartTime = mass[0].time;
for ( int i=0;i<stroka; i++)
{
mDatabase.execSQL(String.format( "INSERT INTO accdb (acc_x, acc_y, acc_z, time_h_m_s) VALUES ('%s', '%s', '%s', '%s');" ,
mass[i].ax, mass[i].ay, mass[i].az, mass[i].time-StartTime));
}
return ;
}
public void onSensorChanged( int sensor, float [] values) {
synchronized ( this ) {
Log.d(tag, onSensorChanged: " + sensor + ", x: " + values[0] + ", y: " + values[1] + ", z: " + values[2]);
if (sensor == SensorManager.SENSOR_ACCELEROMETER onoff==1) {
AXYZTdata tmp;
tmp = new AXYZTdata(values[0], values[1], values[2], System.currentTimeMillis());
mass[stroka] = tmp;
stroka++;
}
}
}
public void onAccuracyChanged( int sensor, int accuracy) {
Log.d(tag, "onAccuracyChanged: " + sensor + ", accuracy: " + accuracy);
}
@Override
protected void onResume() {
super.onResume();
sm.registerListener( this , SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_FASTEST);
}
@Override
protected void onStop() {
sm.unregisterListener( this );
super.onStop();
}
}
* This source code was highlighted with Source Code Highlighter

Who cares here is the draft application

You may also like