Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for GPS disabling after service is stopped.

fix for gravity correction, using gravity sensor.
  • Loading branch information...
commit 466ffcdd7ea9681f33472dbb729ab18d6c0d1c7f 1 parent f3883f0
Marije Baalman authored
View
7 app/res/layout/guesstimator.xml
@@ -68,10 +68,13 @@
<TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ThresholdLabelTextView" android:text="Thresholds" android:layout_span="2"></TextView>
</TableRow>
<TableRow>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Gravity"></TextView>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Gravity Thresh."></TextView>
<EditText android:id="@+id/threshold_gravity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.1">
</EditText>
- </TableRow>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Gravity MA"></TextView>
+ <EditText android:id="@+id/ma_gravity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.95">
+ </EditText>
+ </TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Still forward"></TextView>
<EditText android:id="@+id/still_forward" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.04">
View
3  app/src/com/steim/nescivi/android/gvb/GPSListener.java
@@ -55,7 +55,8 @@ public void startListening() {
public void stopListening() {
// Unregisterlistener moved to thread
mRunning = false;
-
+ unregister_GPS();
+ mLocationManager.removeUpdates(this);
// End recording thread
mThread.interrupt();
mThread = null;
View
21 app/src/com/steim/nescivi/android/gvb/GuesstimateVelocityBetter.java
@@ -681,6 +681,14 @@ public void send_estimate_settings(){
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
+ ed = (EditText) findViewById(R.id.ma_gravity);
+ float ma_gravity = 0.95f;
+
+ try {
+ ma_gravity = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
ed = (EditText) findViewById(R.id.acceleration_mean);
float acc_mean = 0.1f;
@@ -832,6 +840,7 @@ public void send_estimate_settings(){
b.putInt("updateTime", updateTime );
b.putFloat("threshold_gravity", thr_gravity );
+ b.putFloat("ma_gravity", ma_gravity );
b.putFloat("acceleration_forward", acc_forward );
b.putFloat("acceleration_mean", acc_mean );
b.putFloat("deceleration_forward", dec_forward );
@@ -1039,6 +1048,7 @@ public void readPreferences(){
int updateTime = mPrefs.getInt("updateTime", 10 );
float thr_gravity = mPrefs.getFloat("threshold_gravity", 0.1f );
+ float ma_gravity = mPrefs.getFloat("ma_gravity", 0.95f );
float acc_forward = mPrefs.getFloat("acceleration_forward", 0.2f );
float acc_mean = mPrefs.getFloat("acceleration_mean", 0.1f );
float dec_forward = mPrefs.getFloat("deceleration_forward", 0.3f );
@@ -1126,6 +1136,8 @@ public void readPreferences(){
ed = (EditText) findViewById(R.id.threshold_gravity);
ed.setText( Float.toString( thr_gravity ) );
+ ed = (EditText) findViewById(R.id.ma_gravity);
+ ed.setText( Float.toString( ma_gravity ) );
ed = (EditText) findViewById(R.id.acceleration_forward);
ed.setText( Float.toString( acc_forward ) );
ed = (EditText) findViewById(R.id.acceleration_mean);
@@ -1259,6 +1271,14 @@ public void storePreferences(){
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
+ ed = (EditText) findViewById(R.id.ma_gravity);
+ float ma_gravity = 0.95f;
+
+ try {
+ ma_gravity = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
ed = (EditText) findViewById(R.id.acceleration_mean);
float acc_mean = 0.1f;
@@ -1445,6 +1465,7 @@ public void storePreferences(){
mPrefsEdit.putInt("updateTime", updateTime );
mPrefsEdit.putFloat("threshold_gravity", thr_gravity );
+ mPrefsEdit.putFloat("ma_gravity", ma_gravity );
mPrefsEdit.putFloat("acceleration_forward", acc_forward );
mPrefsEdit.putFloat("acceleration_mean", acc_mean );
mPrefsEdit.putFloat("deceleration_forward", dec_forward );
View
24 app/src/com/steim/nescivi/android/gvb/SensorListener.java
@@ -36,6 +36,7 @@
private int mLastElementStats;
private float [] currentValues = {(float) 0.0, (float) 0.0, (float) 0.0};
+ private float [] currentGravityValues = {(float) 0.0, (float) 0.0, (float) 0.0};
private float [][] currentStats = { {(float) 0.0, (float) 0.0, (float) 0.0}, {(float) 0.0, (float) 0.0, (float) 0.0} };
// private SensorOutputWriter mAccelerometerLog, mLinearAccelerometerLog, mOrientationLog, mMagneticLog, mGyroLog, mLightLog;
@@ -138,6 +139,18 @@ public void storeValues(float readings[]) {
}
}
+ public void storeGravityValues(float readings[]) {
+ // long newtime = System.currentTimeMillis();
+ // this.mTimeInterval = newtime - mLastTime;
+ // this.mLastTime = newtime;
+ synchronized ( this ){
+ this.currentGravityValues[ 0 ] = readings[ this.mForward ];
+ this.currentGravityValues[ 1 ] = readings[ this.mSideways ];
+ this.currentGravityValues[ 2 ] = readings[ this.mGravity ];
+ //mBuffer.add( currentGravityValues );
+ }
+ }
+
float [][] getCurrentStats(){
float [][] curStats;
int lastEle;
@@ -160,6 +173,13 @@ public void storeValues(float readings[]) {
return vals;
}
+ float [] getCurrentGravityValues(){
+ float [] vals;
+ synchronized (this){
+ vals = this.currentGravityValues;
+ }
+ return vals;
+ }
//@Override
public void onSensorChanged(SensorEvent event) {
@@ -174,6 +194,10 @@ public void onSensorChanged(SensorEvent event) {
this.storeValues(event.values);
// mLinearAccelerometerLog.writeReadings(event.values);
break;
+ case Sensor.TYPE_GRAVITY:
+ this.storeGravityValues(event.values);
+ // mLinearAccelerometerLog.writeReadings(event.values);
+ break;
}
//}
// catch (StorageErrorException e) {
View
28 app/src/com/steim/nescivi/android/gvb/VelocityEstimator.java
@@ -137,6 +137,8 @@
private float[] mamean = { (float) 0.0, (float) 0.0, (float) 0.0 };
private float[] mameanOff = { (float) 0.0, (float) 0.0, (float) 0.0 };
private float mameanCoef = 0.99f;
+
+ private float[] maGrav = { (float) 0.0, (float) 0.0, (float) 0.0 };
private int mForward = 1;
private int mSideways = 0;
@@ -146,6 +148,7 @@
//private float mStillTime = 0.0f;
private float threshold_gravity = 0.1f;
+ private float maGravCoef = 0.95f;
private float threshold_still_side = 0.04f;
private float threshold_still_forward = 0.04f;
@@ -206,6 +209,7 @@ public void handleMessage(Message msg)
mWindowSize = msg.getData().getInt("window");
mUpdateTime = msg.getData().getInt("updateTime");
threshold_gravity = msg.getData().getFloat("threshold_gravity");
+ maGravCoef = msg.getData().getFloat("ma_gravity");
threshold_acceleration_forward = msg.getData().getFloat("acceleration_forward");
threshold_acceleration_mean = msg.getData().getFloat("acceleration_mean");
threshold_deceleration_forward = msg.getData().getFloat("deceleration_forward");
@@ -500,6 +504,7 @@ private void readPreferences(){
mUpdateTime = mPrefs.getInt("updateTime", 10 );
threshold_gravity = mPrefs.getFloat("threshold_gravity", 0.1f );
+ maGravCoef = mPrefs.getFloat("ma_gravity", 0.95f );
threshold_acceleration_forward = mPrefs.getFloat("acceleration_forward", 0.2f );
threshold_acceleration_mean = mPrefs.getFloat("acceleration_mean", 0.1f );
@@ -831,15 +836,30 @@ public void updateVelocityMeasurement(){
// put readings in circular buffer
//mBuffer.add( currentReadings );
+ // get readings
+ float [] currentGravityReadings = this.mListener.getCurrentGravityValues();
+
+
// calculate mean and standard deviation of buffers
//float [][] curStats = mBuffer.getStats();
//mCurrentStats = mBuffer.getStats();
float [][] curStats = this.mListener.getCurrentStats();
for ( int axis = 0; axis < 3; axis++ ){
+ maGrav[axis] = maGrav[axis] * maGravCoef + currentGravityReadings[axis]*(1.0f - maGravCoef);
+ }
+
+ if ( Math.abs( mamean[2] - maGrav[2] ) > threshold_gravity ){
+ // sensor is tilted
+ // float correctionFactor = Math.abs( mamean[2] / this.mOffsets[2] );
+ // mamean[0] = correctionFactor * mamean[0] - this.mOffsets[0];
+ curStats[0][0] = curStats[0][0] - maGrav[0];
+ }
+
+ for ( int axis = 0; axis < 3; axis++ ){
mamean[axis] = mamean[axis] * mameanCoef + curStats[0][axis]*(1.0f-mameanCoef);
}
-
+
// reset offsets when we are in still:
if ( this.mState == 0 ) {
for ( int axis = 0; axis < 3; axis++ ){
@@ -854,12 +874,6 @@ public void updateVelocityMeasurement(){
mameanOff[axis] = mamean[axis] - this.mOffsets[axis];
}
- if ( Math.abs( mameanOff[2] ) > threshold_gravity ){
- // sensor is tilted
- float correctionFactor = mamean[2] / this.mOffsets[2];
- mameanOff[0] = correctionFactor * mamean[0] - this.mOffsets[0];
- }
-
// correct sign for forward axis
mameanOff[0] = mameanOff[0] * forwardsign;
currentReadings[0] = (currentReadings[0] - this.mOffsets[0]) * forwardsign;
Please sign in to comment.
Something went wrong with that request. Please try again.