Skip to content

Commit

Permalink
corrected integration for initial velocity and position
Browse files Browse the repository at this point in the history
cleaned up code
  • Loading branch information
cmaier-wm committed May 13, 2015
1 parent 8a461e0 commit 5149bfc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion NextStop.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="NextStop" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="nextstop" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
Expand Down
12 changes: 6 additions & 6 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="NextStop" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="nextstop" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -86,12 +86,12 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="dropbox-android-sdk-1.6.3" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
<orderEntry type="library" exported="" name="json_simple-1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="library" exported="" name="dropbox-android-sdk-1.6.3" level="project" />
</component>
</module>
55 changes: 9 additions & 46 deletions app/src/main/java/cjmaier2_dkturne2/nextstop/DedReck.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@
import java.util.List;
import java.util.Locale;

//below for CSV


public class DedReck extends ActionBarActivity implements SensorEventListener, LocationListener {

private final int capture_speed = 0;
//0: DELAY_FASTEST
//1: DELAY_GAME
//3: DELAY_NORMAL
Expand Down Expand Up @@ -245,19 +241,6 @@ protected void onResume()
}
if(LOC_ENABLED)
{
// This seems to cause issues since different providers have
// different locations at the same time.
// for(String provider:lProviders)
// lManager.requestLocationUpdates(provider,50,0,this);
//
// Location loc = null;
//
// for(String provider:lProviders)
// {
// loc = lManager.getLastKnownLocation(provider);
// if(loc != null)
// break;
// }
lManager.requestLocationUpdates(lManager.GPS_PROVIDER,50,10,this);
Location loc = lManager.getLastKnownLocation(lManager.GPS_PROVIDER);
if(loc != null)
Expand All @@ -281,7 +264,6 @@ protected void onPause() {
lManager.removeUpdates(this);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand Down Expand Up @@ -543,19 +525,6 @@ else if(a_x_data.size() == 5) {
v_y = 0;
}

// a_x = values[0]-a_x_off;
// a_y = values[1]-a_y_off;
// a_z = values[2]-a_z_off;
//accounting for gravity in acceleration: http://developer.android.com/reference/android/hardware/SensorEvent.html#values
// float alpha = 0.1f;
// a_x = values[0]*alpha + a_x*(1.0f-alpha);
// a_y = values[1]*alpha + a_y*(1.0f-alpha);
// a_z = values[2]*alpha + a_z*(1.0f-alpha);
//
// a_x = values[0];
// a_y = values[1];
// a_z = values[2];

//dead reckoning, with time in seconds
dt = (new Double((event.timestamp - time_prev)/1000000000.0)).floatValue(); //double to float

Expand All @@ -564,32 +533,26 @@ else if(a_x_data.size() == 5) {
}
else if (dedreck_itr == 1) { //enough readings to get velocity
dedreck_itr = 2;
v_x = (a_x - a_x_prev)*dt;
v_y = (a_y - a_y_prev)*dt;
v_z = (a_z - a_z_prev)*dt;
v_x = (a_x + a_x_prev)/2*dt;
v_y = (a_y + a_y_prev)/2*dt;
v_z = (a_z + a_z_prev)/2*dt;
}
else if (dedreck_itr == 2){ //enough readings to get velocity and position
dedreck_itr = 3;
v_x = (a_x - a_x_prev)*dt;
v_y = (a_y - a_y_prev)*dt;
v_z = (a_z - a_z_prev)*dt;
p_x += (v_x - v_x_prev)*dt;
p_y += (v_y - v_y_prev)*dt;
p_z += (v_z - v_z_prev)*dt;
v_x = (a_x + a_x_prev)/2*dt;
v_y = (a_y + a_y_prev)/2*dt;
v_z = (a_z + a_z_prev)/2*dt;
p_x += (v_x + v_x_prev)/2*dt;
p_y += (v_y + v_y_prev)/2*dt;
p_z += (v_z + v_z_prev)/2*dt;
}
else {
// if((a_x-a_x_prev) > 0.1 || (a_x-a_x_prev) < -0.1) v_x += a_x*dt;
// if((a_y-a_y_prev) > 0.0 || (a_y-a_y_prev) < -0.1) v_y += a_y*dt;
// if((a_z-a_z_prev) > 0.0 || (a_z-a_z_prev) < -0.1) v_z += a_z*dt;
if(Math.abs(a_x-a_x_prev) > 0.1) v_x += a_x*dt;
if(Math.abs(a_y-a_y_prev) > 0.1) v_y += a_y*dt;
if(Math.abs(a_z-a_z_prev) > 0.1) v_z += a_z*dt;
p_x += v_x*dt;
p_y += v_y*dt;
p_z += v_z*dt;
// if(Math.abs(v_x-v_x_prev) > 0.003) p_x += v_x*dt;
// if(Math.abs(v_y-v_y_prev) > 0.003) p_y += v_y*dt;
// if(Math.abs(v_z-v_z_prev) > 0.003) p_z += v_z*dt;
}

p_net = (float) Math.sqrt(p_x*p_x+p_y*p_y); //not accounting for z direction
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/cjmaier2_dkturne2/nextstop/RoutePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

import java.util.List;

/**
* Created by David K Turner on 5/10/2015.
*/
public class RoutePath {
private List<Location> waypoints;
private Location curPos;
Expand Down

0 comments on commit 5149bfc

Please sign in to comment.