Permalink
Browse files

update for new algorithm settings.

and only store values above 0 for speed.
  • Loading branch information...
1 parent 83772ca commit a1c5f82d82b5506a6bb6ebaca70bd04abd81070d Marije Baalman committed Feb 17, 2012
View
69 app/res/layout/guesstimator.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="10px">
+<LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="6dp">
<LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MotionStatusTextView" android:text="Still" android:gravity="center_vertical|center_horizontal"></TextView>
- <TableLayout android:id="@+id/LinearLayout04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1" android:padding="10px">
+ <TableLayout android:id="@+id/LinearLayout04" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1" android:padding="6dp">
<TableRow>
<TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/VelocityStatusLabelTextView" android:text="Velocity "></TextView>
<TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/VelocityStatusTextView" android:text="0.0 m/s"></TextView>
@@ -47,10 +47,10 @@
<LinearLayout android:id="@+id/LinearLayout05" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
- <TableLayout android:id="@+id/TableLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10px">
+ <TableLayout android:id="@+id/TableLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="6dp">
<TableRow>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/EstimatorStatusTextView" android:text="Not running" android:gravity="center_vertical|center_horizontal" android:padding="10px"></TextView>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TransmitterStatusTextView" android:text="Not running" android:gravity="center_vertical|center_horizontal" android:padding="10px"></TextView>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/EstimatorStatusTextView" android:text="Not running" android:gravity="center_vertical|center_horizontal" android:padding="6dp"></TextView>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TransmitterStatusTextView" android:text="Not running" android:gravity="center_vertical|center_horizontal" android:padding="6dp"></TextView>
</TableRow>
<TableRow>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Start estimating" android:id="@+id/StartButton"></Button>
@@ -108,48 +108,65 @@
<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/AccelLabelTextView" android:text="Acceleration"></TextView>
- <EditText android:id="@+id/acceleration" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.3">
+ <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">
</EditText>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/SteadyLabelTextView" android:text="Steady"></TextView>
- <EditText android:id="@+id/steady" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.2"></EditText>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still2LabelTextView" android:text="Still side"></TextView>
+ <EditText android:id="@+id/still_side" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.04">
+ </EditText>
+ </TableRow>
+ <TableRow>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Motion1LabelTextView" android:text="Motion forward"></TextView>
+ <EditText android:id="@+id/motion_forward" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.1">
+ </EditText>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Motion2LabelTextView" android:text="Motion side"></TextView>
+ <EditText android:id="@+id/motion_side" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.1">
+ </EditText>
+ </TableRow>
+ <TableRow>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/AccelLabelTextView" android:text="Accel std"></TextView>
+ <EditText android:id="@+id/acceleration_forward" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.2">
+ </EditText>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Accel2LabelTextView" android:text="Accel mean"></TextView>
+ <EditText android:id="@+id/acceleration_mean" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.3">
+ </EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Decel1LabelTextView" android:text="Decel std"></TextView>
- <EditText android:id="@+id/decelThresS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.25">
+ <EditText android:id="@+id/deceleration_forward" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.3">
</EditText>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Decel2LabelTextView" android:text="Decel mean"></TextView>
- <EditText android:id="@+id/decelThresM" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="-0.5">
+ <EditText android:id="@+id/deceleration_mean" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="-0.3">
</EditText>
</TableRow>
- <TableRow>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Still sid"></TextView>
- <EditText android:id="@+id/stillThres1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.1">
+ <TableRow>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MeanWLabelTextView" android:text="Mean weight"></TextView>
+ <EditText android:id="@+id/mean_weight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.65">
</EditText>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still2LabelTextView" android:text="Still for"></TextView>
- <EditText android:id="@+id/stillThres2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.1">
- </EditText>
- </TableRow>
- <TableRow>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Still time"></TextView>
- <EditText android:id="@+id/stillThresTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="3.0">
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RawWLabelTextView" android:text="Raw weight"></TextView>
+ <EditText android:id="@+id/raw_weight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.35">
+ </EditText>
+ </TableRow>
+ <TableRow>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/OMALabelTextView" android:text="Offset MA"></TextView>
+ <EditText android:id="@+id/offsetMA" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.99">
</EditText>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Still1LabelTextView" android:text="Offset MA"></TextView>
- <EditText android:id="@+id/offsetMA" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.95">
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/SPDLabelTextView" android:text="Speed decay"></TextView>
+ <EditText android:id="@+id/speed_decay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="0.99">
</EditText>
- </TableRow>
+ </TableRow>
</TableLayout>
<TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/SettingLabelTextView" android:text="SERVER" android:gravity="center_vertical|center_horizontal"></TextView>
- <TableLayout android:id="@+id/TableLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1">
+ <TableLayout android:id="@+id/TableLayout3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1">
<TableRow>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/HostLabelTextView" android:text="Host"></TextView>
<EditText android:id="@+id/editHost" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="text" android:layout_weight="1" android:text="192.168.1.23" ></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PortLabelTextView" android:text="Port"></TextView>
<EditText android:id="@+id/editPort" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="5858" ></EditText>
- <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PortLabelTextView" android:text="ClientID"></TextView>
+ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ClientLabelTextView" android:text="ClientID"></TextView>
<EditText android:id="@+id/editClient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="numberDecimal" android:text="1" ></EditText>
</TableRow>
View
299 app/src/com/steim/nescivi/android/gvb/GuesstimateVelocityBetter.java
@@ -644,73 +644,104 @@ public void send_estimate_settings(){
}
- EditText ed = (EditText) findViewById(R.id.acceleration);
+ EditText ed = (EditText) findViewById(R.id.acceleration_forward);
+ float acc_forward = 0.2f;
- float acc = 0.3f;
+ try {
+ acc_forward = 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;
try {
- acc = Float.parseFloat(ed.getText().toString());
+ acc_mean = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.steady);
- float steady = 0.5f;
+ ed = (EditText) findViewById(R.id.deceleration_forward);
+ float dec_forward = 0.3f;
try {
- steady = Float.parseFloat(ed.getText().toString());
+ dec_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
-
- ed = (EditText) findViewById(R.id.decelThresS);
- float dec1 = 0.3f;
+ ed = (EditText) findViewById(R.id.deceleration_mean);
+ float dec_mean = -0.1f;
+
try {
- dec1 = Float.parseFloat(ed.getText().toString());
+ dec_mean = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
+ ed = (EditText) findViewById(R.id.still_forward);
+ float still_forward = 0.04f;
+ try {
+ still_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.decelThresM);
- float dec2 = 0.3f;
+ ed = (EditText) findViewById(R.id.still_side);
+ float still_side = 0.04f;
try {
- dec2 = Float.parseFloat(ed.getText().toString());
+ still_side = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
- }
-
- ed = (EditText) findViewById(R.id.stillThres1);
- float still1 = 0.3f;
+ }
+
+ ed = (EditText) findViewById(R.id.motion_forward);
+ float motion_forward = 0.1f;
try {
- still1 = Float.parseFloat(ed.getText().toString());
+ motion_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.stillThres2);
- float still2 = 0.3f;
+ ed = (EditText) findViewById(R.id.motion_side);
+ float motion_side = 0.1f;
try {
- still2 = Float.parseFloat(ed.getText().toString());
+ motion_side = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.stillThresTime);
- float stilltime = 3.0f;
+ ed = (EditText) findViewById(R.id.speed_decay);
+ float speed_decay = 0.99f;
try {
- stilltime = Float.parseFloat(ed.getText().toString());
+ speed_decay = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
ed = (EditText) findViewById(R.id.offsetMA);
- float offsetma = 0.95f;
+ float offsetma = 0.99f;
try {
offsetma = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
+ ed = (EditText) findViewById(R.id.mean_weight);
+ float mean_weight = 0.65f;
+ try {
+ mean_weight = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
+ ed = (EditText) findViewById(R.id.raw_weight);
+ float raw_weight = 0.35f;
+ try {
+ raw_weight = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
ed = (EditText) findViewById(R.id.editWindow);
int window = 200;
@@ -754,13 +785,19 @@ public void send_estimate_settings(){
b.putInt("gravity", gravityid );
b.putInt("window", window );
b.putInt("updateTime", updateTime );
- b.putFloat("acc", acc );
- b.putFloat("steady", steady );
- b.putFloat("dec1", dec1 );
- b.putFloat("dec2", dec2 );
- b.putFloat("still1", still1 );
- b.putFloat("still2", still2 );
- b.putFloat("stilltime", stilltime );
+
+ b.putFloat("acceleration_forward", acc_forward );
+ b.putFloat("acceleration_mean", acc_mean );
+ b.putFloat("deceleration_forward", dec_forward );
+ b.putFloat("deceleration_mean", dec_mean );
+ b.putFloat("still_forward", still_forward );
+ b.putFloat("still_side", still_side );
+ b.putFloat("motion_forward", motion_forward );
+ b.putFloat("motion_side", motion_side );
+ b.putFloat("mean_weight", mean_weight );
+ b.putFloat("raw_weight", raw_weight );
+ b.putFloat("speed_decay", speed_decay );
+
b.putFloat("offsetma", offsetma );
b.putInt("signForward", signForward );
b.putBoolean( "makeLocalLog", cb.isChecked() );
@@ -883,16 +920,12 @@ public void onServiceConnected(ComponentName class_name, IBinder service) {
*/
Toast.makeText(GuesstimateVelocityBetter.this, "connected to VelocityEstimator", Toast.LENGTH_SHORT).show();
- TextView tv1 = (TextView) findViewById(R.id.EstimatorStatusTextView);
- tv1.setText(String.format("Estimation running"));
}
public void onServiceDisconnected(ComponentName class_name)
{
mVelService = null;
Toast.makeText(GuesstimateVelocityBetter.this, "disconnected from VelocityEstimator", Toast.LENGTH_SHORT).show();
- TextView tv1 = (TextView) findViewById(R.id.EstimatorStatusTextView);
- tv1.setText(String.format("Estimation not running"));
}
};
@@ -951,14 +984,22 @@ public void readPreferences(){
int gravityid = mPrefs.getInt("gravity", 2 );
int window = mPrefs.getInt("window", 200 );
int updateTime = mPrefs.getInt("updateTime", 10 );
- float acc = mPrefs.getFloat("acc", 0.3f );
- float steady = mPrefs.getFloat("steady", 0.2f );
- float dec1 = mPrefs.getFloat("dec1", 0.25f );
- float dec2 = mPrefs.getFloat("dec2", -0.5f );
- float still1 = mPrefs.getFloat("still1", 0.1f );
- float still2 = mPrefs.getFloat("still2", 0.1f );
- float stilltime = mPrefs.getFloat("stilltime", 3.0f );
- float offsetma = mPrefs.getFloat("offsetma", 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 );
+ float dec_mean = mPrefs.getFloat("deceleration_mean", -0.1f );
+ float still_forward = mPrefs.getFloat("still_forward", 0.04f );
+ float still_side = mPrefs.getFloat("still_side", 0.04f );
+ float motion_forward = mPrefs.getFloat("motion_forward", 0.1f );
+ float motion_side = mPrefs.getFloat("motion_side", 0.1f );
+
+ float mean_weight = mPrefs.getFloat("mean_weight", 0.65f );
+ float raw_weight = mPrefs.getFloat("raw_weight", 0.35f );
+
+ float speed_decay = mPrefs.getFloat("speed_decay", 0.99f );
+ float offsetma = mPrefs.getFloat("offsetma", 0.99f );
+
boolean localLog = mPrefs.getBoolean( "localLog", false );
boolean signForward = mPrefs.getBoolean( "signForward", false );
@@ -1017,22 +1058,32 @@ public void readPreferences(){
break;
}
- EditText ed = (EditText) findViewById(R.id.acceleration);
- ed.setText( Float.toString( acc ) );
-
- ed = (EditText) findViewById(R.id.steady);
- ed.setText( Float.toString( steady ) );
+ EditText ed = (EditText) findViewById(R.id.acceleration_forward);
+ ed.setText( Float.toString( acc_forward ) );
+ ed = (EditText) findViewById(R.id.acceleration_mean);
+ ed.setText( Float.toString( acc_mean ) );
+ ed = (EditText) findViewById(R.id.deceleration_forward);
+ ed.setText( Float.toString( dec_forward ) );
+ ed = (EditText) findViewById(R.id.deceleration_mean);
+ ed.setText( Float.toString( dec_mean ) );
- ed = (EditText) findViewById(R.id.decelThresS);
- ed.setText( Float.toString( dec1 ) );
- ed = (EditText) findViewById(R.id.decelThresM);
- ed.setText( Float.toString( dec2 ) );
- ed = (EditText) findViewById(R.id.stillThres1);
- ed.setText( Float.toString( still1 ) );
- ed = (EditText) findViewById(R.id.stillThres2);
- ed.setText( Float.toString( still2) );
- ed = (EditText) findViewById(R.id.stillThresTime);
- ed.setText( Float.toString( stilltime ) );
+ ed = (EditText) findViewById(R.id.still_forward);
+ ed.setText( Float.toString( still_forward ) );
+ ed = (EditText) findViewById(R.id.still_side);
+ ed.setText( Float.toString( still_side) );
+ ed = (EditText) findViewById(R.id.motion_forward);
+ ed.setText( Float.toString( motion_forward ) );
+ ed = (EditText) findViewById(R.id.motion_side);
+ ed.setText( Float.toString( motion_side ) );
+
+
+ ed = (EditText) findViewById(R.id.mean_weight );
+ ed.setText( Float.toString( mean_weight ) );
+ ed = (EditText) findViewById(R.id.raw_weight );
+ ed.setText( Float.toString( raw_weight ) );
+
+ ed = (EditText) findViewById(R.id.speed_decay );
+ ed.setText( Float.toString( speed_decay ) );
ed = (EditText) findViewById(R.id.offsetMA);
ed.setText( Float.toString( offsetma ) );
ed = (EditText) findViewById(R.id.editWindow);
@@ -1118,74 +1169,106 @@ public void storePreferences(){
sideid = 2;
break;
}
-
- EditText ed = (EditText) findViewById(R.id.acceleration);
- float acc = 0.3f;
+
+ EditText ed = (EditText) findViewById(R.id.acceleration_forward);
+ float acc_forward = 0.2f;
try {
- acc = Float.parseFloat(ed.getText().toString());
+ acc_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
-
- ed = (EditText) findViewById(R.id.steady);
- float steady = 0.5f;
+ ed = (EditText) findViewById(R.id.acceleration_mean);
+ float acc_mean = 0.1f;
try {
- steady = Float.parseFloat(ed.getText().toString());
+ acc_mean = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.decelThresS);
- float dec1 = 0.3f;
+ ed = (EditText) findViewById(R.id.deceleration_forward);
+ float dec_forward = 0.3f;
+
try {
- dec1 = Float.parseFloat(ed.getText().toString());
+ dec_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
-
- ed = (EditText) findViewById(R.id.decelThresM);
- float dec2 = 0.3f;
+ ed = (EditText) findViewById(R.id.deceleration_mean);
+ float dec_mean = -0.1f;
+
try {
- dec2 = Float.parseFloat(ed.getText().toString());
+ dec_mean = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
- }
+ }
- ed = (EditText) findViewById(R.id.stillThres1);
- float still1 = 0.3f;
+ ed = (EditText) findViewById(R.id.still_forward);
+ float still_forward = 0.04f;
try {
- still1 = Float.parseFloat(ed.getText().toString());
+ still_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.stillThres2);
- float still2 = 0.3f;
+ ed = (EditText) findViewById(R.id.still_side);
+ float still_side = 0.04f;
+ try {
+ still_side = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
+ ed = (EditText) findViewById(R.id.motion_forward);
+ float motion_forward = 0.1f;
try {
- still2 = Float.parseFloat(ed.getText().toString());
+ motion_forward = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
- ed = (EditText) findViewById(R.id.stillThresTime);
- float stilltime = 3.0f;
+ ed = (EditText) findViewById(R.id.motion_side);
+ float motion_side = 0.1f;
try {
- stilltime = Float.parseFloat(ed.getText().toString());
+ motion_side = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
+ ed = (EditText) findViewById(R.id.speed_decay);
+ float speed_decay = 0.99f;
+ try {
+ speed_decay = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
ed = (EditText) findViewById(R.id.offsetMA);
- float offsetma = 0.95f;
+ float offsetma = 0.99f;
try {
offsetma = Float.parseFloat(ed.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
+ ed = (EditText) findViewById(R.id.mean_weight);
+ float mean_weight = 0.65f;
+ try {
+ mean_weight = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
+ ed = (EditText) findViewById(R.id.raw_weight);
+ float raw_weight = 0.35f;
+ try {
+ raw_weight = Float.parseFloat(ed.getText().toString());
+ } catch(NumberFormatException nfe) {
+ System.out.println("Could not parse " + nfe);
+ }
+
ed = (EditText) findViewById(R.id.editWindow);
int window = 200;
@@ -1266,13 +1349,18 @@ public void storePreferences(){
mPrefsEdit.putInt("gravity", gravityid );
mPrefsEdit.putInt("window", window );
mPrefsEdit.putInt("updateTime", updateTime );
- mPrefsEdit.putFloat("acc", acc );
- mPrefsEdit.putFloat("steady", steady );
- mPrefsEdit.putFloat("dec1", dec1 );
- mPrefsEdit.putFloat("dec2", dec2 );
- mPrefsEdit.putFloat("still1", still1 );
- mPrefsEdit.putFloat("still2", still2 );
- mPrefsEdit.putFloat("stilltime", stilltime );
+
+ mPrefsEdit.putFloat("acceleration_forward", acc_forward );
+ mPrefsEdit.putFloat("acceleration_mean", acc_mean );
+ mPrefsEdit.putFloat("deceleration_forward", dec_forward );
+ mPrefsEdit.putFloat("deceleration_mean", dec_mean );
+ mPrefsEdit.putFloat("speed_decay", speed_decay );
+ mPrefsEdit.putFloat("still_forward", still_forward );
+ mPrefsEdit.putFloat("still_side", still_side );
+ mPrefsEdit.putFloat("motion_forward", motion_forward );
+ mPrefsEdit.putFloat("motion_side", motion_side );
+ mPrefsEdit.putFloat("mean_weight", mean_weight );
+ mPrefsEdit.putFloat("raw_weight", raw_weight );
mPrefsEdit.putFloat("offsetma", offsetma );
@@ -1304,7 +1392,10 @@ protected void onResume()
super.onResume();
if (register_with_VelocityService())
{
- Toast.makeText(GuesstimateVelocityBetter.this, "VelocityEstimator connected", Toast.LENGTH_SHORT).show();
+ Toast.makeText(GuesstimateVelocityBetter.this, "VelocityEstimator connected", Toast.LENGTH_SHORT).show();
+ toggleUIStatus(true);
+ } else {
+ toggleUIStatus(false);
}
/*
if (register_with_TransmitterService())
@@ -1319,7 +1410,7 @@ protected void onPause()
super.onPause();
if (unregister_from_VelocityService())
{
- Toast.makeText(GuesstimateVelocityBetter.this, "VelocityEstimator disconnected", Toast.LENGTH_SHORT).show();
+ Toast.makeText(GuesstimateVelocityBetter.this, "VelocityEstimator disconnected", Toast.LENGTH_SHORT).show();
}
/*
if (unregister_from_TransmitterService())
@@ -1339,6 +1430,7 @@ private void setButtonsListeners() {
@Override
public void onClick(View v) {
startEstimateService();
+ storePreferences();
// createLocalLog();
// startTransmitterService();
}
@@ -1399,18 +1491,13 @@ private void toggleUIStatus(boolean recording) {
findViewById(R.id.StartButton).setEnabled(!recording);
findViewById(R.id.StopButton).setEnabled(recording);
- // Enable or disable options
-
- // disable sensor select
- findViewById(R.id.radioAcc).setEnabled(!recording);
- findViewById(R.id.radioLinAcc).setEnabled(!recording);
- // disable window size setting
- findViewById(R.id.editWindow).setEnabled(!recording);
-
- // Change status text
-// TextView tv = ((TextView) findViewById(R.id.RecordingStatusTextView));
-// tv.setText((recording) ? R.string.status_recording_running : R.string.status_recording_stopped);
- }
+ TextView tv1 = (TextView) findViewById(R.id.EstimatorStatusTextView);
+ if ( recording ){
+ tv1.setText(String.format("Estimation running"));
+ } else {
+ tv1.setText(String.format("Estimation not running"));
+ }
+ }
/*
private boolean mWritingLocalLog;
View
294 app/src/com/steim/nescivi/android/gvb/VelocityEstimator.java
@@ -120,14 +120,22 @@
private int mState = 0;
private float mStillTime = 0.0f;
-
- private float threshold_acceleration = 0.3f;
- private float threshold_still_side = 0.1f;
- private float threshold_still_forward = 0.1f;
- private float threshold_still_time = 3.0f;
- private float threshold_decel_std = 0.25f;
- private float threshold_decel_mean = -0.5f;
- private float threshold_steady = 0.5f;
+
+ private float threshold_still_side = 0.04f;
+ private float threshold_still_forward = 0.04f;
+
+ private float threshold_motion_side = 0.1f;
+ private float threshold_motion_forward = 0.1f;
+
+ private float threshold_acceleration_forward = 0.2f;
+ private float threshold_acceleration_mean = 0.1f;
+
+ private float threshold_deceleration_forward = 0.3f;
+ private float threshold_deceleration_mean = -0.1f;
+
+ private float speed_decay = 0.99f;
+ private float mean_weight = 0.65f;
+ private float raw_weight = 0.65f;
// moving average for offset:
private float macoef = 0.99f;
@@ -168,14 +176,21 @@ public void handleMessage(Message msg)
set_forward_axis( msg.getData().getInt("forward") );
set_sideways_axis( msg.getData().getInt("side"));
set_gravity_axis( msg.getData().getInt("gravity") );
- set_window( msg.getData().getInt("window") );
- set_update_time(msg.getData().getInt("updateTime"));
- set_threshold_acceleration( msg.getData().getFloat("acc") );
- set_threshold_steady( msg.getData().getFloat("steady") );
- set_threshold_deceleration( msg.getData().getFloat("dec1"),msg.getData().getFloat("dec2") );
- set_threshold_still( msg.getData().getFloat("still1"), msg.getData().getFloat("still2"), msg.getData().getFloat( "stilltime") );
- set_offset_macoef( msg.getData().getFloat("offsetma") );
- set_sign_forward( msg.getData().getInt("signForward") );
+ mWindowSize = msg.getData().getInt("window");
+ mUpdateTime = msg.getData().getInt("updateTime");
+ threshold_acceleration_forward = msg.getData().getFloat("acceleration_forward");
+ threshold_acceleration_mean = msg.getData().getFloat("acceleration_mean");
+ threshold_deceleration_forward = msg.getData().getFloat("deceleration_forward");
+ threshold_deceleration_mean = msg.getData().getFloat("deceleration_mean");
+ threshold_still_forward = msg.getData().getFloat("still_forward");
+ threshold_still_side = msg.getData().getFloat("still_side");
+ threshold_motion_forward = msg.getData().getFloat("motion_forward");
+ threshold_motion_side = msg.getData().getFloat("motion_side");
+ mean_weight = msg.getData().getFloat("mean_weight");
+ raw_weight = msg.getData().getFloat("raw_weight");
+ speed_decay = msg.getData().getFloat("speed_decay");
+ macoef = msg.getData().getFloat("offsetma");
+ forwardsign = msg.getData().getInt("signForward");
mMakeLocalLog = msg.getData().getBoolean("makeLocalLog");
mLogUpdateTime = msg.getData().getInt("updateLogTime");
startEstimation();
@@ -196,58 +211,7 @@ public void handleMessage(Message msg)
case MSG_UNREGISTER_GUI_CLIENT:
mGuiClient = null;
break;
- /*
- case MSG_REGISTER_TX_CLIENT:
- mTransmitService = msg.replyTo;
- break;
- case MSG_UNREGISTER_TX_CLIENT:
- mTransmitService = null;
- break;
- */
- /*
- case MSG_SET_SENSOR:
- set_sensor(msg.arg1);
- break;
- case MSG_SET_FORWARD:
- set_forward_axis(msg.arg1);
- break;
- case MSG_SET_SIDEWAYS:
- set_sideways_axis(msg.arg1);
- break;
- case MSG_SET_GRAVITY:
- set_gravity_axis(msg.arg1);
- break;
- case MSG_SET_WINDOW:
- set_window(msg.arg1);
- break;
- case MSG_SET_UPDATETIME:
- set_update_time(msg.arg1);
- break;
- case MSG_SET_THRESH_ACC:
- set_threshold_acceleration(msg.arg1);
- break;
- case MSG_SET_THRESH_STEADY:
- set_threshold_steady(msg.arg1);
- break;
- case MSG_SET_THRESH_DECEL:
- set_threshold_deceleration(msg.arg1, msg.arg2);
- break;
- case MSG_SET_THRESH_STILL:
- set_threshold_still(msg.arg1, msg.arg2);
- break;
- case MSG_SET_IP:
- set_ip( msg.getData().getString("host") );
- break;
- case MSG_SET_PORT:
- set_port(msg.arg1);
- break;
- case MSG_SET_BUFFER_SIZE:
- set_buffer_size(msg.arg1);
- break;
- case MSG_SET_UPDATE_INTERVAL:
- set_update_interval(msg.arg1);
- break;
- */
+
default:
super.handleMessage(msg);
}
@@ -259,15 +223,7 @@ public void handleMessage(Message msg)
@Override
public void onCreate()
{
- //super.onCreate();
- //HandlerThread thread = new HandlerThread("ServiceVelocityEstimator", Process.THREAD_PRIORITY_BACKGROUND);
- //thread.start();
-
- // Get the HandlerThread's Looper and use it for our Handler
- //mServiceLooper = thread.getLooper();
- //mServiceHandler = new IncomingHandler(mServiceLooper);
- //mIncomingMessenger = new Messenger( mServiceHandler );
-
+ //super.onCreate();
Log.d("VelocityEstimator", "onCreate");
mContext = getApplicationContext();
// mRunning = false;
@@ -356,10 +312,6 @@ public void run() {
add_data_to_buffer();
// send messages to UI:
send_gui_update_msg();
- // send_speed_msg();
- // send_forward_accel_msg();
- // send_sideways_accel_msg();
- // send_gravity_accel_msg();
}
};
timer.scheduleAtFixedRate( mCalcTimerTask, 0, mUpdateTime );
@@ -450,7 +402,7 @@ private void add_data_to_buffer( ){
String [] currentVals = new String[2];
Date now = new Date();
currentVals[0] = formatDate( now );
- currentVals[1] = String.format("%.2f", mSpeed * 3.6f );
+ currentVals[1] = String.format("%.3f", Math.max( mSpeed * 3.6f, 0. ) );
mUploadBuffer.add( currentVals );
}
@@ -531,30 +483,32 @@ private void set_update_interval( int updtime ){
/// --------- END DATA UPLOADER -------------
- private void set_sign_forward( int sign ){
- this.forwardsign = (float) sign;
- }
-
- private void set_window( int windowsize ){
- /*
- if ( this.mWindowSize != windowsize ){
- mBuffer = null;
- mBuffer = new CircularFloatArrayBuffer2( 3, windowsize );
- }
- */
- this.mWindowSize = windowsize;
- }
-
- private void set_update_time( int updtime ){
- /*
- if ( this.mUpdateTime != updtime ){
- mCalcTimerTask.cancel();
- timer.scheduleAtFixedRate( mCalcTimerTask, 0, updtime );
- }
- */
- this.mUpdateTime = updtime;
- }
-
+//
+// private void set_sign_forward( int sign ){
+// this.forwardsign = (float) sign;
+// }
+//
+// private void set_window( int windowsize ){
+// /*
+// if ( this.mWindowSize != windowsize ){
+// mBuffer = null;
+// mBuffer = new CircularFloatArrayBuffer2( 3, windowsize );
+// }
+// */
+// this.mWindowSize = windowsize;
+// }
+//
+// private void set_update_time( int updtime ){
+// /*
+// if ( this.mUpdateTime != updtime ){
+// mCalcTimerTask.cancel();
+// timer.scheduleAtFixedRate( mCalcTimerTask, 0, updtime );
+// }
+// */
+// this.mUpdateTime = updtime;
+// }
+//
+
private void set_sensor( int newsensor ){
if ( this.mType != newsensor ){
mListener.changeListening( newsensor, 0 );
@@ -580,28 +534,28 @@ private void set_gravity_axis( int newaxis ){
}
}
- private void set_threshold_acceleration( float newth ){
- threshold_acceleration = newth;
- }
-
- private void set_threshold_steady( float newth ){
- threshold_steady = newth;
- }
-
- private void set_threshold_deceleration( float newth1, float newth2 ){
- threshold_decel_std = newth1;
- threshold_decel_mean = newth2;
- }
-
- private void set_threshold_still( float newth1, float newth2, float newth3 ){
- threshold_still_side = newth1;
- threshold_still_forward = newth2;
- threshold_still_time = newth3;
- }
-
- private void set_offset_macoef( float newth1 ){
- macoef = newth1;
- }
+// private void set_threshold_acceleration( float newth ){
+// threshold_acceleration = newth;
+// }
+//
+// private void set_threshold_steady( float newth ){
+// threshold_steady = newth;
+// }
+//
+// private void set_threshold_deceleration( float newth1, float newth2 ){
+// threshold_decel_std = newth1;
+// threshold_decel_mean = newth2;
+// }
+//
+// private void set_threshold_still( float newth1, float newth2, float newth3 ){
+// threshold_still_side = newth1;
+// threshold_still_forward = newth2;
+// threshold_still_time = newth3;
+// }
+//
+// private void set_offset_macoef( float newth1 ){
+// macoef = newth1;
+// }
private void send_server_update_msg()
{
@@ -729,7 +683,7 @@ public void updateVelocityMeasurement(){
this.mLastTime = newtime;
// get readings
- //float [] currentReadings = this.mListener.getCurrentValues();
+ float [] currentReadings = this.mListener.getCurrentValues();
// put readings in circular buffer
//mBuffer.add( currentReadings );
@@ -742,7 +696,7 @@ public void updateVelocityMeasurement(){
// reset offsets when we are in still:
if ( this.mState == 0 ) {
for ( int axis = 0; axis < 3; axis++ ){
- if ( curStats[0][axis] < 20.f ){
+ if ( curStats[0][axis] < 20.f ){ // just to make sure we're not killed by NaN's
this.mOffsets[axis] = this.mOffsets[axis] * macoef + curStats[0][axis] * (1-macoef);
}
}
@@ -753,7 +707,26 @@ public void updateVelocityMeasurement(){
curStats[0][axis] = curStats[0][axis] - this.mOffsets[axis];
}
+ // correct sign for forward axis
+ curStats[0][0] = curStats[0][0] * forwardsign;
+ currentReadings[0] = (currentReadings[0] - this.mOffsets[0]) * forwardsign;
+
// determine state
+
+ if ( curStats[1][0] > threshold_motion_forward && curStats[1][1] > threshold_motion_side ){
+ this.mState = 1; // moving
+ }
+ if ( curStats[1][0] < threshold_still_forward && curStats[1][1] > threshold_still_side ){
+ this.mState = 0; // still
+ }
+ if ( curStats[1][0] > threshold_acceleration_forward && curStats[0][0] > threshold_acceleration_mean ){
+ this.mState = 2; // accelerating
+ }
+ if ( curStats[1][0] > threshold_deceleration_forward && curStats[0][0] < threshold_deceleration_mean ){
+ this.mState = 3; // decelerating
+ }
+
+ /*
switch (this.mState){
case 0: // still
mStillTime = 0.0f;
@@ -791,29 +764,31 @@ public void updateVelocityMeasurement(){
}
}
}
+ */
// calculate forward speed
+ if ( this.mState == 0 ){
+ this.mSpeed = this.mSpeed * speed_decay;
+ } else {
+ this.mSpeed += ( mean_weight*curStats[0][0] + raw_weight*currentReadings[0]) * this.mDeltaTime * 0.001;
+ }
+
+ /*
switch (this.mState){
case 0: // still
- this.mSpeed = (float) 0.0;
+ this.mSpeed = this.mSpeed * speed_decay_factor;
+ // this.mSpeed = (float) 0.0;
break;
case 2: // accelerating
// set the sign of what is forward:
- /*
- if ( mCurrentStats[0][0] < 0 ){
- forwardsign = -1.f;
- } else {
- forwardsign = 1.f;
- }
- */
case 1: // steady motion
case 3: // decelerating
this.mSpeed += curStats[0][0] * forwardsign * this.mDeltaTime * 0.001;
break;
default:
break;
}
-
+ */
synchronized( this ){
for ( int axis = 0; axis < 3; axis++ ){
mCurrentStats[0][axis] = curStats[0][axis];
@@ -898,45 +873,6 @@ public void closeLocalLog(){
}
mWritingLocalLog = false;
}
-
-
- /*
- //@Override
- public void runUploaderThread() {
- while (myThread != null && mRunning ) {
- send_server_update_msg();
-
- if ( mHost != null && mPort != 0 ){
- try {
-
- Socket s = new Socket( mHost, mPort );
-
- // outgoing stream redirect to socket
- OutputStream out = s.getOutputStream();
-
- PrintWriter output = new PrintWriter(out);
- // print the circular buffer
- output.println("Hello Android!");
-
- // Close connection
- s.close();
-
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- try {
- Thread.sleep( mUpdateServerTime );
- } catch (InterruptedException e) { }
- }
- }
- */
-
}
+

0 comments on commit a1c5f82

Please sign in to comment.