From e5f274993c2b94103f09734121fb19b8d6ba7e8e Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 10 Mar 2012 10:03:17 -0500 Subject: [PATCH 1/4] Inital Commit of my mulitiple point navigation changes Change-Id: I33996d4aaf6200b25cd46e95aba78330494c09a9 Signed-off-by: Ricky Barrette --- IOIOTruck/assets/exceptionhandler.properties | 2 +- .../TwentyCodes/android/IOIOTruck/Main.java | 2 + .../android/IOIOTruck/MapFragment.java | 81 +++++++++++++++++-- .../android/IOIOTruck/NavigationActivity.java | 70 +++++++++++++--- 4 files changed, 136 insertions(+), 19 deletions(-) diff --git a/IOIOTruck/assets/exceptionhandler.properties b/IOIOTruck/assets/exceptionhandler.properties index 910dadd..0d0db1f 100644 --- a/IOIOTruck/assets/exceptionhandler.properties +++ b/IOIOTruck/assets/exceptionhandler.properties @@ -13,7 +13,7 @@ # get is the path to your json retrieval script # app is the redmine project name # tracker is the redmine tracker -server = http://rickbarrette.dyndns.org:8080/redmine/exceptionhandler +server = http://rickbarrette.dyndns.org:8888 app = IOIO Truck tracker = Development Bug diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java index b2e4c43..bab5fa8 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/Main.java @@ -47,6 +47,8 @@ public class Main extends Activity implements OnClickListener { Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); setContentView(R.layout.main); +// Integer.parseInt("poop"); + findViewById(R.id.test_activity_button).setOnClickListener(this); findViewById(R.id.nav_activity_button).setOnClickListener(this); findViewById(R.id.camera_activity_button).setOnClickListener(this); diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java index 3102058..8c4fc63 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java @@ -21,12 +21,19 @@ */ package com.TwentyCodes.android.IOIOTruck; +import java.io.IOException; + +import org.apache.http.client.ClientProtocolException; +import org.json.JSONException; + import android.util.Log; -import com.TwentyCodes.android.location.LocationSelectedListener; +import com.TwentyCodes.android.fragments.UserOverlayMapFragment; import com.TwentyCodes.android.location.MapView; -import com.TwentyCodes.android.location.RadiusOverlay; -import com.TwentyCodes.android.location.UserOverlayMapFragment; +import com.TwentyCodes.android.location.OnLocationSelectedListener; +import com.TwentyCodes.android.overlays.DirectionsOverlay; +import com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener; +import com.TwentyCodes.android.overlays.RadiusOverlay; import com.google.android.maps.GeoPoint; /** @@ -35,12 +42,16 @@ import com.google.android.maps.GeoPoint; * Specifically this map view will allow user to select a point on the map via RadiusOverlay * @author ricky barrette */ -public class MapFragment extends UserOverlayMapFragment implements LocationSelectedListener { +public class MapFragment extends UserOverlayMapFragment implements OnLocationSelectedListener, OnDirectionsCompleteListener { private final String TAG = "MapFragment"; private RadiusOverlay mRadiusOverlay; - private LocationSelectedListener mLocationSelectedListener; + private OnLocationSelectedListener mLocationSelectedListener; + + private OnDirectionsCompleteListener mDirectionsCompleteListener; + + private DirectionsOverlay mDirectionsOverlay; /** * Creates a new MapFragment @@ -50,6 +61,18 @@ public class MapFragment extends UserOverlayMapFragment implements LocationSelec super(); } + /** + * Called whrn the directions overlay is finished getting the directions. + * (non-Javadoc) + * @see com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener#onDirectionsComplete(com.TwentyCodes.android.overlays.DirectionsOverlay) + */ + @Override + public void onDirectionsComplete(DirectionsOverlay directionsOverlay) { + mDirectionsOverlay = directionsOverlay; + if(mDirectionsCompleteListener != null) + mDirectionsCompleteListener.onDirectionsComplete(directionsOverlay); + } + /** * Called when a point is selected on the map * (non-Javadoc) @@ -73,7 +96,7 @@ public class MapFragment extends UserOverlayMapFragment implements LocationSelec } else if(Debug.DEBUG) Log.d(TAG, "onLocationSelected() Location was null"); } - + /** * (non-Javadoc) * @see com.TwentyCodes.android.location.UserOverlayMapFragment#onMapViewCreate(com.TwentyCodes.android.location.MapView) @@ -88,13 +111,55 @@ public class MapFragment extends UserOverlayMapFragment implements LocationSelec } /** + * (non-Javadoc) + * @see com.TwentyCodes.android.fragments.UserOverlayMapFragment#setDestination(com.google.android.maps.GeoPoint) + */ + @Override + public void setDestination(final GeoPoint destination) { + if(mDirectionsOverlay != null) + mDirectionsOverlay.removePath(); + + if(mDirectionsCompleteListener != null) + new Thread( new Runnable(){ + @Override + public void run(){ + try { + new DirectionsOverlay(getMap(), getUserLocation(), destination, MapFragment.this); + } catch (IllegalStateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClientProtocolException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); + super.setDestination(destination); + } + + /** + * sets the distener for the directions overlay * @param listener * @author ricky barrette */ - public void setLocationSelectedListener(LocationSelectedListener listener){ - mLocationSelectedListener = listener; + public void setDirectionsCompleteListener(OnDirectionsCompleteListener listener){ + mDirectionsCompleteListener = listener; } + /** + * @param listener + * @author ricky barrette + */ + public void setLocationSelectedListener(OnLocationSelectedListener listener){ + mLocationSelectedListener = listener; + } + /** * @param radius meters * @author ricky barrette diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java index f93e211..74fc20f 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java @@ -21,6 +21,8 @@ */ package com.TwentyCodes.android.IOIOTruck; +import java.util.ArrayList; + import android.content.Context; import android.os.Bundle; import android.os.PowerManager; @@ -42,7 +44,10 @@ import com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListene import com.TwentyCodes.android.location.CompassListener; import com.TwentyCodes.android.location.GeoPointLocationListener; import com.TwentyCodes.android.location.GeoUtils; -import com.TwentyCodes.android.location.LocationSelectedListener; +import com.TwentyCodes.android.location.OnLocationSelectedListener; +import com.TwentyCodes.android.overlays.DirectionsOverlay; +import com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener; +import com.TwentyCodes.android.overlays.PathOverlay; import com.google.android.maps.GeoPoint; @@ -57,7 +62,7 @@ import com.google.android.maps.GeoPoint; * + drive the truck forward or reverse to best navigate to the selected point * @author ricky barrette */ -public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, LocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener { +public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, OnLocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener, OnDirectionsCompleteListener { private static final String TAG = "NavigationActivity"; private IOIOTruckManager mIOIOManager; @@ -79,6 +84,9 @@ public class NavigationActivity extends FragmentActivity implements CompassListe private long mLast; private WakeLock mWakeLock; private int mCount; + private ArrayList mPoints; + private int mIndex = 0; + private GeoPoint mDestPoint; /** * This thread will be used to update all the informational displays @@ -106,6 +114,8 @@ public class NavigationActivity extends FragmentActivity implements CompassListe +"\nSteering: "+mIOIOManager.getSteerValue() +"\nBearing: "+mBearing +"\nisRunning: "+isRunning); + if(mPoints != null) + updateLog("Point = "+mIndex +" of "+ mPoints.size()); updateLastUpdateTextView(); @@ -282,19 +292,35 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mDistance = updateProgress(point); /* - * here we will update the progress bar - * + * if we have a destination, check to see if we are there yet */ if(mPoint != null) if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), mPoint, Debug.RADIUS, Debug.FUDGE_FACTOR)) { - mCount++; + /* + * if we get 5 positives, we are at our waypoint/dest + */ if(mCount > 5){ - Log.v(TAG, "Dest Reached, Stopping"); - mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP); - updateGoButton(true); - updateLog(R.string.dest_reached); + + /* + * if ther points list is null, or there are no more points + */ + if(mPoints == null || mIndex == mPoints.size()+1){ + mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP); + updateGoButton(true); + updateLog(R.string.dest_reached); + } else { + mIndex ++; + + if(mIndex <= mPoints.size()+1) { + updateLog("last Waypoint reached, moving to dest"); + mPoint = mPoints.get(mIndex); + } else { + updateLog("Waypoint reached, moving to next"); + mPoint = mDestPoint; + } + } } } else { Log.v(TAG, "Driving Forward"); @@ -315,9 +341,11 @@ public class NavigationActivity extends FragmentActivity implements CompassListe */ @Override public void onLocationSelected(GeoPoint point) { - mPoint = point; + mDestPoint = point; mDistance = updateProgress(mMap.getUserLocation()); updateLog(getString(R.string.point_selected)+point.toString()); + mIndex = 0; + mCount = 0; } /** @@ -353,7 +381,9 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mMap.setCompassListener(this); mMap.setGeoPointLocationListener(this); mMap.setLocationSelectedListener(this); + mMap.setDirectionsCompleteListener(this); mMap.setRadius((int) (Debug.RADIUS * 1E3)); + mMap.enableGPSProgess(); mIOIOManager = new IOIOTruckManager(this, this); mIOIOManager.start(); @@ -421,5 +451,25 @@ public class NavigationActivity extends FragmentActivity implements CompassListe public void onLogUpdate(String log) { updateLog(log); } + + /** + * called when the directions overlay is generated + * (non-Javadoc) + * @see com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener#onDirectionsComplete(com.TwentyCodes.android.overlays.DirectionsOverlay) + */ + @Override + public void onDirectionsComplete(DirectionsOverlay directionsOverlay) { + ArrayList points = new ArrayList(); + for(PathOverlay item : directionsOverlay.getPath()) + if(item.getEndPoint() != null) + points.add(item.getEndPoint()); + mPoints = points; + mPoint = points.get(points.size()-1); + } + + @Override + public void onFirstFix(boolean isFirstFix) { + mMap.disableGPSProgess(); + } } \ No newline at end of file From 9174336fc90abbb2c360f0071a8a1e00e3b4469e Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 10 Mar 2012 11:39:21 -0500 Subject: [PATCH 2/4] Added waypoint dots to drawn path (overlay) added a calls to set the compass's dest point when directions are generated, and when a waypoint is changed. refactored NavigationActivity (sorted) Change-Id: Ibbb0a5651a12b00dcce4b3973609adf1c1648632 Signed-off-by: Ricky Barrette --- .../android/IOIOTruck/MapFragment.java | 19 +- .../android/IOIOTruck/NavigationActivity.java | 212 ++++++++++-------- 2 files changed, 128 insertions(+), 103 deletions(-) diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java index 8c4fc63..5a97a5e 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java @@ -45,12 +45,9 @@ import com.google.android.maps.GeoPoint; public class MapFragment extends UserOverlayMapFragment implements OnLocationSelectedListener, OnDirectionsCompleteListener { private final String TAG = "MapFragment"; - private RadiusOverlay mRadiusOverlay; private OnLocationSelectedListener mLocationSelectedListener; - private OnDirectionsCompleteListener mDirectionsCompleteListener; - private DirectionsOverlay mDirectionsOverlay; /** @@ -81,6 +78,8 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel @Override public void onLocationSelected(GeoPoint point) { + removePath(); + setDestination(point); if(mLocationSelectedListener != null) @@ -110,15 +109,21 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel super.onMapViewCreate(map); } + /** + * Removes the path if displayed + * @author ricky barrette + */ + public void removePath(){ + if(mDirectionsOverlay != null) + mDirectionsOverlay.removePath(); + } + /** * (non-Javadoc) * @see com.TwentyCodes.android.fragments.UserOverlayMapFragment#setDestination(com.google.android.maps.GeoPoint) */ @Override - public void setDestination(final GeoPoint destination) { - if(mDirectionsOverlay != null) - mDirectionsOverlay.removePath(); - + public void setDestination(final GeoPoint destination) { if(mDirectionsCompleteListener != null) new Thread( new Runnable(){ @Override diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java index 74fc20f..154ad6a 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java @@ -24,6 +24,7 @@ package com.TwentyCodes.android.IOIOTruck; import java.util.ArrayList; import android.content.Context; +import android.graphics.Color; import android.os.Bundle; import android.os.PowerManager; import android.os.PowerManager.WakeLock; @@ -64,30 +65,6 @@ import com.google.android.maps.GeoPoint; */ public class NavigationActivity extends FragmentActivity implements CompassListener, GeoPointLocationListener, OnLocationSelectedListener, OnClickListener, OnCheckedChangeListener, IOIOTruckThreadListener, OnDirectionsCompleteListener { - private static final String TAG = "NavigationActivity"; - private IOIOTruckManager mIOIOManager; - private MapFragment mMap; - private TextView mLog; - private GeoPoint mPoint; - private ProgressBar mProgress; - private int mMaxDistance = 0; //meters - private boolean isRunning = false; - private Button mGoButton; - private float mBearing; - private ScrollView mScrollView; - - private boolean isScrollingEnabled = true; - private int mDistance; - private LogUpdater mLoggerThread; - private TextView mAccuracyTextView; - private TextView mLastUpdateTextView; - private long mLast; - private WakeLock mWakeLock; - private int mCount; - private ArrayList mPoints; - private int mIndex = 0; - private GeoPoint mDestPoint; - /** * This thread will be used to update all the informational displays * @author ricky barrette @@ -143,6 +120,29 @@ public class NavigationActivity extends FragmentActivity implements CompassListe } } + private static final String TAG = "NavigationActivity"; + private IOIOTruckManager mIOIOManager; + private MapFragment mMap; + private TextView mLog; + private GeoPoint mPoint; + private ProgressBar mProgress; + private int mMaxDistance = 0; //meters + private boolean isRunning = false; + private Button mGoButton; + private float mBearing; + private ScrollView mScrollView; + private boolean isScrollingEnabled = true; + private int mDistance; + private LogUpdater mLoggerThread; + private TextView mAccuracyTextView; + private TextView mLastUpdateTextView; + private long mLast; + private WakeLock mWakeLock; + private int mCount; + private ArrayList mPoints; + private int mIndex = 0; + private GeoPoint mDestPoint; + private ArrayList mWayPoints; /** * Called when the scrolling switch is checked @@ -191,44 +191,6 @@ public class NavigationActivity extends FragmentActivity implements CompassListe } } - /** - * updates the go/stop button based on isRunning - * thread safe - * @author ricky barrette - */ - private void updateGoButton() { - updateGoButton(isRunning); - } - - /** - * Sets the go/stop button to the provided value - * thread safe - * @param isRunnuing true = stop, false = go - * @author ricky barrette - */ - private void updateGoButton(final boolean isRun) { - mIOIOManager.setStatLedEnabled(!isRun); - runOnUiThread(new Runnable() { - @Override - public void run(){ - if(isRun){ - mCount = 0; - mGoButton.setText(R.string.go); - isRunning = false; - updateLog(R.string.stop); - if(mLoggerThread != null) - mLoggerThread.abort(); - } else { - mGoButton.setText(R.string.stop); - isRunning = true; - updateLog(R.string.go); - mLoggerThread = new LogUpdater(); - mLoggerThread.start(); - } - } - }); - } - /** * Called when there is an update from the compass * (non-Javadoc) @@ -249,7 +211,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mBearing = bearing; } - + /** * (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) @@ -278,6 +240,39 @@ public class NavigationActivity extends FragmentActivity implements CompassListe findViewById(R.id.my_location_button).setOnClickListener(this); findViewById(R.id.map_button).setOnClickListener(this); } + + /** + * called when the directions overlay is generated + * (non-Javadoc) + * @see com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener#onDirectionsComplete(com.TwentyCodes.android.overlays.DirectionsOverlay) + */ + @Override + public void onDirectionsComplete(DirectionsOverlay directionsOverlay) { + ArrayList path = directionsOverlay.getPath(); + + if(path.size() > 0){ + mWayPoints = new ArrayList(); + ArrayList points = new ArrayList(); + points.add(path.get(0).getStartPoint()); + for(PathOverlay item : path) + if(item.getEndPoint() != null) { + points.add(item.getEndPoint()); + mWayPoints.add(new PathOverlay(item.getEndPoint(), 5, Color.GRAY)); + } + + mPoints = points; + mPoint = points.get(0); + mMap.setDestination(mPoint); + mWayPoints.add(new PathOverlay(mPoint, 5, Color.MAGENTA)); + mMap.getMap().getOverlays().addAll(mWayPoints); + mWayPoints.addAll(path); + } + } + + @Override + public void onFirstFix(boolean isFirstFix) { + mMap.disableGPSProgess(); + } /** * Called when android's location services have an update @@ -313,13 +308,18 @@ public class NavigationActivity extends FragmentActivity implements CompassListe } else { mIndex ++; - if(mIndex <= mPoints.size()+1) { + if(mIndex <= mPoints.size()) { updateLog("last Waypoint reached, moving to dest"); mPoint = mPoints.get(mIndex); } else { updateLog("Waypoint reached, moving to next"); mPoint = mDestPoint; } + + /* + * we have to notify the compass that the point has changed + */ + mMap.setDestination(mPoint); } } } else { @@ -341,6 +341,8 @@ public class NavigationActivity extends FragmentActivity implements CompassListe */ @Override public void onLocationSelected(GeoPoint point) { + if(mWayPoints != null) + mMap.getMap().getOverlays().removeAll(mWayPoints); mDestPoint = point; mDistance = updateProgress(mMap.getUserLocation()); updateLog(getString(R.string.point_selected)+point.toString()); @@ -348,6 +350,16 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mCount = 0; } + /** + * Called when the IOIOTruckThread has a log it wants to display + * (non-Javadoc) + * @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String) + */ + @Override + public void onLogUpdate(String log) { + updateLog(log); + } + /** * Called when the application is paused. We want to disconnect with the * IOIO at this point, as the user is no longer interacting with our @@ -369,7 +381,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mWakeLock.release(); super.onPause(); } - + /** * (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onResume() @@ -391,7 +403,45 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.acquire(); } - + + /** + * updates the go/stop button based on isRunning + * thread safe + * @author ricky barrette + */ + private void updateGoButton() { + updateGoButton(isRunning); + } + + /** + * Sets the go/stop button to the provided value + * thread safe + * @param isRunnuing true = stop, false = go + * @author ricky barrette + */ + private void updateGoButton(final boolean isRun) { + mIOIOManager.setStatLedEnabled(!isRun); + runOnUiThread(new Runnable() { + @Override + public void run(){ + if(isRun){ + mCount = 0; + mGoButton.setText(R.string.go); + isRunning = false; + updateLog(R.string.stop); + if(mLoggerThread != null) + mLoggerThread.abort(); + } else { + mGoButton.setText(R.string.stop); + isRunning = true; + updateLog(R.string.go); + mLoggerThread = new LogUpdater(); + mLoggerThread.start(); + } + } + }); + } + /** * updates the log with the provided string res * thread safe @@ -441,35 +491,5 @@ public class NavigationActivity extends FragmentActivity implements CompassListe mProgress.setProgress(distance); return distance; } - - /** - * Called when the IOIOTruckThread has a log it wants to display - * (non-Javadoc) - * @see com.TwentyCodes.android.IOIOTruck.IOIOTruckManager.IOIOTruckThreadListener#onLogUpdate(java.lang.String) - */ - @Override - public void onLogUpdate(String log) { - updateLog(log); - } - - /** - * called when the directions overlay is generated - * (non-Javadoc) - * @see com.TwentyCodes.android.overlays.DirectionsOverlay.OnDirectionsCompleteListener#onDirectionsComplete(com.TwentyCodes.android.overlays.DirectionsOverlay) - */ - @Override - public void onDirectionsComplete(DirectionsOverlay directionsOverlay) { - ArrayList points = new ArrayList(); - for(PathOverlay item : directionsOverlay.getPath()) - if(item.getEndPoint() != null) - points.add(item.getEndPoint()); - mPoints = points; - mPoint = points.get(points.size()-1); - } - - @Override - public void onFirstFix(boolean isFirstFix) { - mMap.disableGPSProgess(); - } } \ No newline at end of file From b2475f84740f02a62a2d45eb65182f346bc6be21 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sat, 10 Mar 2012 12:11:11 -0500 Subject: [PATCH 3/4] Updated onLocationChanged() to be synchronous and tweaked the waypoit algorithm. Change-Id: I1e29bfa072239dca7e4592f1de4db8e65537da73 Signed-off-by: Ricky Barrette --- .../android/IOIOTruck/NavigationActivity.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java index 154ad6a..b023d3f 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java @@ -280,7 +280,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe * @see com.TwentyCodes.android.location.GeoPointLocationListener#onLocationChanged(com.google.android.maps.GeoPoint, int) */ @Override - public void onLocationChanged(GeoPoint point, int accuracy) { + public synchronized void onLocationChanged(GeoPoint point, int accuracy) { mLast = System.currentTimeMillis(); mAccuracyTextView.setText(accuracy+getString(R.string.m)); @@ -301,18 +301,22 @@ public class NavigationActivity extends FragmentActivity implements CompassListe /* * if ther points list is null, or there are no more points */ - if(mPoints == null || mIndex == mPoints.size()+1){ + if(mPoints == null || mIndex == mPoints.size()){ mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP); updateGoButton(true); updateLog(R.string.dest_reached); } else { mIndex ++; - if(mIndex <= mPoints.size()) { - updateLog("last Waypoint reached, moving to dest"); + /* + * if there are more waypoints, then move on to the next + * otherwise move on to the dest + */ + if(mIndex < mPoints.size()) { + updateLog("Waypoint reached, moving to next"); mPoint = mPoints.get(mIndex); } else { - updateLog("Waypoint reached, moving to next"); + updateLog("last Waypoint reached, moving to dest"); mPoint = mDestPoint; } From f6b9f664d065cbb205314397f6992b10e0e1af81 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sun, 11 Mar 2012 17:59:04 -0400 Subject: [PATCH 4/4] Finished path navigation Change-Id: Ibfba63ac41ae9e701851be58eff6ec984ae12e72 Signed-off-by: Ricky Barrette --- .../android/IOIOTruck/MapFragment.java | 54 ++++----- .../android/IOIOTruck/NavigationActivity.java | 108 +++++++++--------- 2 files changed, 76 insertions(+), 86 deletions(-) diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java index 5a97a5e..e7a6a0b 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/MapFragment.java @@ -76,7 +76,29 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel * @see com.TwentyCodes.android.location.LocationSelectedListener#onLocationSelected(com.google.android.maps.GeoPoint) */ @Override - public void onLocationSelected(GeoPoint point) { + public void onLocationSelected(final GeoPoint point) { + + if(mDirectionsCompleteListener != null) + new Thread( new Runnable(){ + @Override + public void run(){ + try { + new DirectionsOverlay(getMap(), getUserLocation(), point, MapFragment.this); + } catch (IllegalStateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClientProtocolException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); removePath(); @@ -118,36 +140,6 @@ public class MapFragment extends UserOverlayMapFragment implements OnLocationSel mDirectionsOverlay.removePath(); } - /** - * (non-Javadoc) - * @see com.TwentyCodes.android.fragments.UserOverlayMapFragment#setDestination(com.google.android.maps.GeoPoint) - */ - @Override - public void setDestination(final GeoPoint destination) { - if(mDirectionsCompleteListener != null) - new Thread( new Runnable(){ - @Override - public void run(){ - try { - new DirectionsOverlay(getMap(), getUserLocation(), destination, MapFragment.this); - } catch (IllegalStateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ClientProtocolException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }).start(); - super.setDestination(destination); - } - /** * sets the distener for the directions overlay * @param listener diff --git a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java index b023d3f..5ed402d 100644 --- a/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java +++ b/IOIOTruck/src/com/TwentyCodes/android/IOIOTruck/NavigationActivity.java @@ -77,15 +77,13 @@ public class NavigationActivity extends FragmentActivity implements CompassListe * aborts the thread * @author ricky barrette */ - public void abort() { + public synchronized void abort() { isAborted = true; } @Override public void run(){ - while (true) { - if (isAborted) - break; + while (!isAborted) { updateLog("\nDistance: "+ mDistance +getString(R.string.m) +"\nDrive: "+mIOIOManager.getDriveValue() +"\nSteering: "+mIOIOManager.getSteerValue() @@ -93,9 +91,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe +"\nisRunning: "+isRunning); if(mPoints != null) updateLog("Point = "+mIndex +" of "+ mPoints.size()); - - updateLastUpdateTextView(); - + updateLastUpdateTextView(); try { sleep(1000); } catch (InterruptedException e) { @@ -124,9 +120,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe private IOIOTruckManager mIOIOManager; private MapFragment mMap; private TextView mLog; - private GeoPoint mPoint; private ProgressBar mProgress; - private int mMaxDistance = 0; //meters private boolean isRunning = false; private Button mGoButton; private float mBearing; @@ -138,7 +132,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe private TextView mLastUpdateTextView; private long mLast; private WakeLock mWakeLock; - private int mCount; + private int mCount = 0; private ArrayList mPoints; private int mIndex = 0; private GeoPoint mDestPoint; @@ -171,7 +165,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe break; case R.id.mark_my_lcoation_button: - GeoPoint point = mMap.getUserLocation(); + final GeoPoint point = mMap.getUserLocation(); if(point != null){ mMap.onLocationSelected(point); @@ -180,7 +174,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe break; case R.id.my_location_button: - GeoPoint user = mMap.getUserLocation(); + final GeoPoint user = mMap.getUserLocation(); if(user != null){ mMap.setMapCenter(user); @@ -198,7 +192,7 @@ public class NavigationActivity extends FragmentActivity implements CompassListe */ @Override public void onCompassUpdate(float bearing) { - bearing = GeoUtils.calculateBearing(mMap.getUserLocation(), mPoint, bearing); + bearing = GeoUtils.calculateBearing(mMap.getUserLocation(), mMap.getDestination(), bearing); if(bearing > 355 || bearing < 5) mIOIOManager.setSteerValue(IOIOTruckValues.STEER_STRAIGHT); @@ -261,9 +255,8 @@ public class NavigationActivity extends FragmentActivity implements CompassListe } mPoints = points; - mPoint = points.get(0); - mMap.setDestination(mPoint); - mWayPoints.add(new PathOverlay(mPoint, 5, Color.MAGENTA)); + mMap.setDestination(points.get(0)); + mWayPoints.add(new PathOverlay(points.get(0), 5, Color.MAGENTA)); mMap.getMap().getOverlays().addAll(mWayPoints); mWayPoints.addAll(path); } @@ -280,59 +273,67 @@ public class NavigationActivity extends FragmentActivity implements CompassListe * @see com.TwentyCodes.android.location.GeoPointLocationListener#onLocationChanged(com.google.android.maps.GeoPoint, int) */ @Override - public synchronized void onLocationChanged(GeoPoint point, int accuracy) { + public synchronized void onLocationChanged(final GeoPoint point, final int accuracy) { mLast = System.currentTimeMillis(); mAccuracyTextView.setText(accuracy+getString(R.string.m)); - mDistance = updateProgress(point); + final GeoPoint currentDest = mMap.getDestination(); /* * if we have a destination, check to see if we are there yet + * if we are then increment mCount */ - if(mPoint != null) - if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), mPoint, Debug.RADIUS, Debug.FUDGE_FACTOR)) { - mCount++; + if(point != null) + if(currentDest != null) + /* - * if we get 5 positives, we are at our waypoint/dest + * are we closer than 15 feet? */ - if(mCount > 5){ - + if (GeoUtils.distanceKm(point, currentDest) < 0.009144) { +// if(GeoUtils.isIntersecting(point, (float) (accuracy / 1E3), currentDest, Debug.RADIUS, Debug.FUDGE_FACTOR)) { + updateLog("Count = "+ (++mCount)); /* - * if ther points list is null, or there are no more points + * if we get 6 positives, we are problay at our waypoint/dest */ - if(mPoints == null || mIndex == mPoints.size()){ - mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP); - updateGoButton(true); - updateLog(R.string.dest_reached); - } else { - mIndex ++; + if(mCount == 6){ + + mCount = 0; /* - * if there are more waypoints, then move on to the next - * otherwise move on to the dest + * if the points list is null, or there are no more waypoints */ - if(mIndex < mPoints.size()) { - updateLog("Waypoint reached, moving to next"); - mPoint = mPoints.get(mIndex); + if(mPoints == null || mIndex == mPoints.size()){ + mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP); + updateGoButton(true); + updateLog(R.string.dest_reached); + mMap.setDestination(null); } else { - updateLog("last Waypoint reached, moving to dest"); - mPoint = mDestPoint; + updateLog("Index = " + (++mIndex)); + + /* + * if there are more waypoints, then move on to the next + * otherwise move on to the dest + */ + if(mIndex < mPoints.size()) { + updateLog("Waypoint reached, moving to next"); + mMap.setDestination(mPoints.get(mIndex)); + } else { + updateLog("last Waypoint reached, moving to dest"); + mMap.setDestination(mDestPoint); + } + + updateLog("New dest = "+ mMap.getDestination().toString()); } - - /* - * we have to notify the compass that the point has changed - */ - mMap.setDestination(mPoint); } + + } else { + Log.v(TAG, "Driving Forward"); + mCount = 0; + mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_FORWARD); } - } else { - Log.v(TAG, "Driving Forward"); - mCount = 0; - mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_FORWARD); - } - else{ - Log.v(TAG, "Lost GPS signal, stopping"); + else { + updateLog("Lost GPS signal (point was null), stopping"); mIOIOManager.setDriveValue(IOIOTruckValues.DRIVE_STOP); } @@ -487,13 +488,10 @@ public class NavigationActivity extends FragmentActivity implements CompassListe * @author ricky barrette */ private int updateProgress(GeoPoint point) { - int distance = (int) (GeoUtils.distanceKm(point, mPoint) * 1000); - if (distance > mMaxDistance) { - mMaxDistance = distance; + int distance = (int) (GeoUtils.distanceKm(point, mMap.getDestination()) * 1000); + if (distance > mProgress.getMax()) mProgress.setMax(distance); - } mProgress.setProgress(distance); return distance; } - } \ No newline at end of file