Skip to content

Commit

Permalink
completed implementation of the Guided scan follow mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gr3d committed Jan 28, 2015
1 parent d487999 commit 65bc1be
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 107 deletions.
4 changes: 2 additions & 2 deletions Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
compile 'com.android.support:cardview-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.2'

compile 'com.o3dr:3dr-services-lib:2.2.2'
compile 'com.o3dr:3dr-services-lib:2.2.6'

compile files('libs/droneapi-java-0.3-SNAPSHOT.jar')
compile files('libs/j2xx.jar')
Expand All @@ -28,7 +28,7 @@ android {
applicationId 'org.droidplanner.android'
minSdkVersion 14
targetSdkVersion 21
versionCode 30013
versionCode 30014
versionName getGitVersion()
}

Expand Down
2 changes: 1 addition & 1 deletion Android/res/layout/fragment_mode_follow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
style="@style/ModeDetailText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mode_guided"/>
android:text="@string/mode_follow"/>

<Spinner
android:id="@+id/follow_type_spinner"
Expand Down
3 changes: 3 additions & 0 deletions Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<string name="mode_sport">Sport allows a pilot to control rate of rotation directly with the addition of self-leveling.</string>
<string name="mode_stabilize">Stabilize levels the vehicle in flight.</string>
<string name="mode_poshold">PosHold allows position hold (GPS) with direct response to pilot input.</string>
<string name="mode_follow">The vehicle follows the user based on the device GPS location.</string>

<!-- Waypoint types -->
<string name="waypointType_Waypoint">Waypoint</string>
Expand Down Expand Up @@ -526,5 +527,7 @@
<string name="delete_selected_waypoints_confirm">Clear selected waypoints from the map?</string>
<string name="delete_selected_waypoints_title">Clear selected waypoints</string>
<string name="label_select_all">select all</string>
<string name="guided_scan_roi_set_message">Targeting selected location.</string>
<string name="mode_follow_guided_scan">Vehicle follows the user while remaining locked on a point of interest. Long click on the map to select the point of interest.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

import org.droidplanner.android.R;
import org.droidplanner.android.fragments.DroneMap;
import org.droidplanner.android.fragments.FlightActionsFragment;
import org.droidplanner.android.fragments.FlightMapFragment;
import org.droidplanner.android.fragments.TelemetryFragment;
Expand Down Expand Up @@ -415,6 +416,14 @@ public void setGuidedClickListener(FlightMapFragment.OnGuidedClickListener liste
mapFragment.setGuidedClickListener(listener);
}

public void addMapMarkerProvider(DroneMap.MapMarkerProvider provider){
mapFragment.addMapMarkerProvider(provider);
}

public void removeMapMarkerProvider(DroneMap.MapMarkerProvider provider){
mapFragment.removeMapMarkerProvider(provider);
}

@Override
public void onStart() {
super.onStart();
Expand Down
56 changes: 55 additions & 1 deletion Android/src/org/droidplanner/android/fragments/DroneMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@
import org.droidplanner.android.utils.prefs.AutoPanMode;
import org.droidplanner.android.utils.prefs.DroidPlannerPrefs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;

public abstract class DroneMap extends ApiListenerFragment {

private final static String TAG = DroneMap.class.getSimpleName();

public static final String ACTION_UPDATE_MAP = Utils.PACKAGE_NAME + ".action.UPDATE_MAP";

private static final IntentFilter eventFilter = new IntentFilter();
static {
eventFilter.addAction(MissionProxy.ACTION_MISSION_PROXY_UPDATE);
Expand All @@ -51,19 +56,24 @@ public abstract class DroneMap extends ApiListenerFragment {
eventFilter.addAction(AttributeEvent.STATE_DISCONNECTED);
eventFilter.addAction(AttributeEvent.CAMERA_FOOTPRINTS_UPDATED);
eventFilter.addAction(AttributeEvent.ATTITUDE_UPDATED);
eventFilter.addAction(ACTION_UPDATE_MAP);
}

private final BroadcastReceiver eventReceiver = new BroadcastReceiver() {
private static final List<MarkerInfo> NO_EXTERNAL_MARKERS = Collections.emptyList();

private final BroadcastReceiver eventReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!isResumed())
return;

final String action = intent.getAction();
switch (action) {
case ACTION_UPDATE_MAP:
case MissionProxy.ACTION_MISSION_PROXY_UPDATE:
postUpdate();
break;

case AttributeEvent.GPS_POSITION: {
mMapFragment.updateMarker(graphicDrone);
mMapFragment.updateDroneLeashPath(guided);
Expand Down Expand Up @@ -124,8 +134,10 @@ public void run() {
return;

final List<MarkerInfo> missionMarkerInfos = missionProxy.getMarkersInfos();
final List<MarkerInfo> externalMarkers = collectMarkersFromProviders();

final boolean isThereMissionMarkers = !missionMarkerInfos.isEmpty();
final boolean isThereExternalMarkers = !externalMarkers.isEmpty();
final boolean isHomeValid = home.isValid();
final boolean isGuidedVisible = guided.isVisible();

Expand All @@ -145,6 +157,9 @@ public void run() {
markersOnTheMap.removeAll(missionMarkerInfos);
}

if(isThereExternalMarkers)
markersOnTheMap.removeAll(externalMarkers);

mMapFragment.removeMarkers(markersOnTheMap);
}

Expand All @@ -160,6 +175,9 @@ public void run() {
mMapFragment.updateMarkers(missionMarkerInfos, isMissionDraggable());
}

if(isThereExternalMarkers)
mMapFragment.updateMarkers(externalMarkers, false);

mMapFragment.updateMissionPath(missionProxy);

mMapFragment.updatePolygonsPaths(missionProxy.getPolygonsPath());
Expand All @@ -168,6 +186,8 @@ public void run() {
}
};

private final ConcurrentLinkedQueue<MapMarkerProvider> markerProviders = new ConcurrentLinkedQueue<>();

protected DPMap mMapFragment;

protected DroidPlannerPrefs mAppPrefs;
Expand Down Expand Up @@ -342,4 +362,38 @@ public void updateMapBearing(float bearing) {
public void skipMarkerClickEvents(boolean skip) {
mMapFragment.skipMarkerClickEvents(skip);
}

public void addMapMarkerProvider(MapMarkerProvider provider){
if(provider != null) {
markerProviders.add(provider);
postUpdate();
}
}

public void removeMapMarkerProvider(MapMarkerProvider provider){
if(provider != null) {
markerProviders.remove(provider);
postUpdate();
}
}

public interface MapMarkerProvider {
MarkerInfo[] getMapMarkers();
}

private List<MarkerInfo> collectMarkersFromProviders(){
if(markerProviders.isEmpty())
return NO_EXTERNAL_MARKERS;

List<MarkerInfo> markers = new ArrayList<>();
for(MapMarkerProvider provider : markerProviders){
MarkerInfo[] externalMarkers = provider.getMapMarkers();
Collections.addAll(markers, externalMarkers);
}

if(markers.isEmpty())
return NO_EXTERNAL_MARKERS;

return markers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void onApiDisconnected() {

private void onModeUpdate(Drone drone) {
// Update the info panel fragment
drone = getDrone();
final State droneState = drone.getAttribute(AttributeType.STATE);
Fragment infoPanel;
if (droneState == null || !droneState.isConnected()) {
Expand Down
Loading

0 comments on commit 65bc1be

Please sign in to comment.