Skip to content

Commit

Permalink
changed rate of sensor readings to TYPE_GAME. Increased averaging win…
Browse files Browse the repository at this point in the history
…dow of compass readings
  • Loading branch information
nikcain committed Jul 13, 2012
1 parent 74f56a0 commit 6dc0bd5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ShowMe/ShowMeX/src/com/showmehills/HillDatabase.java
Expand Up @@ -152,7 +152,7 @@ public void SetDirections(Location curLocation)
}
} while (cursor.moveToNext());
}

Log.d("showmehills", "Added " + localhills.size() + " markers");
/*
localhills.add(new Hills(0,"London Eye", -0.119700, 51.5033, 135));
localhills.add(new Hills(0,"Shard", -0.086667, 51.504444, 308));
Expand Down
3 changes: 2 additions & 1 deletion ShowMe/ShowMeX/src/com/showmehills/LocationResolver.java
Expand Up @@ -18,7 +18,8 @@ public LocationResolver(LocationManager lm, String provider, RapidGPSLock locati
this.locationMgrImpl = locationMgrImpl;
}
public void onLocationChanged(Location location) {
Log.d("showmehills", "new location " + location.getAccuracy() + " " + location.getLatitude() + "," + location.getLongitude());

Log.d("showmehills", "new location (" + provider + ") " + location.getAccuracy() + " " + location.getLatitude() + "," + location.getLongitude());
lm.removeUpdates(this);
locationMgrImpl.locationCallback(provider);
}
Expand Down
12 changes: 6 additions & 6 deletions ShowMe/ShowMeX/src/com/showmehills/MapOverlay.java
Expand Up @@ -79,8 +79,8 @@ public void onCreate(Bundle savedInstanceState) {
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME);

myDbHelper = new HillDatabase(this);
try {
Expand All @@ -106,8 +106,8 @@ protected void onResume() {
Log.d("showmehills", "onResume");
super.onResume();

mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME);

try {
myDbHelper.openDataBase();
Expand Down Expand Up @@ -240,9 +240,9 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {

}
public void onSensorChanged(SensorEvent event) {
if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
/*if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
return;
}
}*/

if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic = event.values;
Expand Down
1 change: 1 addition & 0 deletions ShowMe/ShowMeX/src/com/showmehills/RapidGPSLock.java
Expand Up @@ -71,6 +71,7 @@ public void locationCallback(String provider)
bestLocationProvider = provider;
}
setLocationAtLastDownload(curLoc);
mixContext.UpdateMarkers();
}

private void requestBestLocationUpdates()
Expand Down
39 changes: 24 additions & 15 deletions ShowMe/ShowMeX/src/com/showmehills/ShowMeHillsActivity.java
Expand Up @@ -71,6 +71,8 @@ public class ShowMeHillsActivity extends Activity implements SensorEventListener
float[] mGeomagnetic;

Timer timer = new Timer();
private int GPSretryTime = 15;
private int CompassSmoothingWindow = 50;

//private Location curLocation;
private String acc = "";
Expand Down Expand Up @@ -139,8 +141,8 @@ protected void onResume() {
Log.d("showmehills", "onResume");
super.onResume();

mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME);
mGPS.switchOn();
getPrefs();
wl.acquire();
Expand Down Expand Up @@ -189,7 +191,7 @@ public void onCreate(Bundle savedInstanceState) {
mGPS = new RapidGPSLock(this);
mGPS.switchOn();
mGPS.findLocation();
timer.scheduleAtFixedRate(new LocationTimerTask(),20* 1000,20* 1000); //wait 20 seconds for the location updates to find the location
timer.scheduleAtFixedRate(new LocationTimerTask(),GPSretryTime* 1000,GPSretryTime* 1000);

mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);

Expand Down Expand Up @@ -266,27 +268,34 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

public void UpdateMarkers()
{
Location curLocation = mGPS.getCurrentLocation();
myDbHelper.SetDirections(curLocation);
}

class filteredDirection
{
int AVERAGINGWINDOW = 10;
double dir;
double sinevalues[] = new double[AVERAGINGWINDOW];
double cosvalues[] = new double[AVERAGINGWINDOW];
double sinevalues[] = new double[CompassSmoothingWindow];
double cosvalues[] = new double[CompassSmoothingWindow];
int index = 0;
int outlierCount = 0;

void AddLatest( double d )
{
sinevalues[index] = Math.sin(d);
cosvalues[index] = Math.cos(d);
index++;
if (index > AVERAGINGWINDOW - 1) index = 0;
if (index > CompassSmoothingWindow - 1) index = 0;
double sumc = 0;
double sums = 0;
for (int a = 0; a < AVERAGINGWINDOW; a++)
for (int a = 0; a < CompassSmoothingWindow; a++)
{
sumc += cosvalues[a];
sums += sinevalues[a];
}
dir = Math.atan2(sums/AVERAGINGWINDOW,sumc/AVERAGINGWINDOW);
dir = Math.atan2(sums/CompassSmoothingWindow,sumc/CompassSmoothingWindow);
}

double getDirection()
Expand All @@ -303,24 +312,24 @@ int GetVariation()
double Q = 0;
double sumc = 0;
double sums = 0;
for (int a = 0; a < AVERAGINGWINDOW; a++)
for (int a = 0; a < CompassSmoothingWindow; a++)
{
sumc += cosvalues[a];
sums += sinevalues[a];
}
double avgc = sumc/AVERAGINGWINDOW;
double avgs = sums/AVERAGINGWINDOW;
double avgc = sumc/CompassSmoothingWindow;
double avgs = sums/CompassSmoothingWindow;

sumc = 0;
sums = 0;
for (int a = 0; a < AVERAGINGWINDOW; a++)
for (int a = 0; a < CompassSmoothingWindow; a++)
{
sumc += Math.pow(cosvalues[a] - avgc, 2);
sums += Math.pow(sinevalues[a] - avgs, 2);
}
Q = (sumc/(AVERAGINGWINDOW-1)) + (sums/(AVERAGINGWINDOW-1));
Q = (sumc/(CompassSmoothingWindow-1)) + (sums/(CompassSmoothingWindow-1));

return (int)(Q*10000);
return (int)(Q*1000);
}
}

Expand Down

0 comments on commit 6dc0bd5

Please sign in to comment.