Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera footprint #1266

Merged
merged 12 commits into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Android/res/values/preferences_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This file is used to store the preferences keys so that it's accessible and modi
<string name="pref_permanent_notification_key">pref_permanent_notification</string>
<string name="pref_ui_gps_hdop_key">pref_ui_gps_hdop</string>
<string name="pref_ui_language_english_key">pref_ui_language_english</string>
<string name="pref_ui_realtime_footprints_key">pref_ui_realtime_footprints_key</string>
<string name="pref_dshare_username_key">dshare_username</string>
<string name="pref_dshare_password_key">dshare_password</string>
<string name="pref_dshare_enabled_key">dshare_enabled</string>
Expand Down
2 changes: 2 additions & 0 deletions Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@
<string name="pref_title_osm">Open Street Map Preferences</string>
<string name="pref_title_mapbox">MapBox Preferences</string>
<string name="activity_title_map_provider_preferences">Map Provider Preferences</string>
<string name="pref_ui_realtime_footprints_title">Realtime camera footprint</string>
<string name="pref_ui_realtime_footprints_summary">Display the camera projection on the ground in realtime</string>

<!-- Others (when possible move to a grouping above) -->
<string name="tune_roll">Manual adjustment of roll and pitch tuning. Rate_P is the primary value to adjust.</string>
Expand Down
6 changes: 6 additions & 0 deletions Android/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
android:key="@string/pref_map_provider_settings_key"
android:summary="@string/pref_map_provider_settings_summary"
android:title="@string/pref_map_provider_settings_title" />

<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_ui_realtime_footprints_key"
android:summary="@string/pref_ui_realtime_footprints_summary"
android:title="@string/pref_ui_realtime_footprints_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_notifications" >
<CheckBoxPreference
Expand Down
19 changes: 18 additions & 1 deletion Android/src/org/droidplanner/android/fragments/DroneMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
import org.droidplanner.core.drone.DroneInterfaces.DroneEventsType;
import org.droidplanner.core.drone.DroneInterfaces.OnDroneListener;
import org.droidplanner.core.helpers.coordinates.Coord2D;
import org.droidplanner.core.helpers.units.Altitude;
import org.droidplanner.core.model.Drone;
import org.droidplanner.core.survey.CameraInfo;
import org.droidplanner.core.survey.Footprint;

import com.MAVLink.Messages.ardupilotmega.msg_camera_feedback;
import com.google.android.gms.internal.ln;

import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -95,6 +101,8 @@ public void run() {

protected Context context;

private CameraInfo camera = new CameraInfo();

protected abstract boolean isMissionDraggable();

@Override
Expand Down Expand Up @@ -182,6 +190,15 @@ public void onDroneEvent(DroneEventsType event, Drone drone) {
}
break;

case ATTITUDE:
if (((DroidPlannerApp) getActivity().getApplication()).getPreferences()
.isRealtimeFootprintsEnabled()) {
if (drone.getGps().isPositionValid()) {
mMapFragment.updateRealTimeFootprint(drone.getCamera().getCurrentFieldOfView());
}

}
break;
case GUIDEDPOINT:
mMapFragment.updateMarker(guided);
mMapFragment.updateDroneLeashPath(guided);
Expand All @@ -197,7 +214,7 @@ public void onDroneEvent(DroneEventsType event, Drone drone) {
mMapFragment.updateMarker(graphicDrone);
break;
case FOOTPRINT:
mMapFragment.addCameraFootprint(drone.getCameraFootprints().getLastFootprint());
mMapFragment.addCameraFootprint(drone.getCamera().getLastFootprint());
break;
default:
break;
Expand Down
2 changes: 2 additions & 0 deletions Android/src/org/droidplanner/android/maps/DPMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,7 @@ interface OnMarkerDragListener {
* @param skip if it should skip further events
*/
public void skipMarkerClickEvents(boolean skip);

public void updateRealTimeFootprint(Footprint footprint);

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public class GoogleMapFragment extends SupportMapFragment implements DPMap, Loca

private List<Polygon> polygonsPaths = new ArrayList<Polygon>();

private Polygon footprintPoly;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup,
Bundle bundle) {
Expand Down Expand Up @@ -525,6 +527,26 @@ public void updateMissionPath(PathSource pathSource) {


@Override
public void updateRealTimeFootprint(Footprint footprint) {
if (footprintPoly == null) {
PolygonOptions pathOptions = new PolygonOptions();
pathOptions.strokeColor(FOOTPRINT_DEFAULT_COLOR).strokeWidth(FOOTPRINT_DEFAULT_WIDTH);
pathOptions.fillColor(FOOTPRINT_FILL_COLOR);

for (Coord2D vertex : footprint.getVertexInGlobalFrame()) {
pathOptions.add(DroneHelper.CoordToLatLang(vertex));
}
footprintPoly = getMap().addPolygon(pathOptions);
}else{
List<LatLng> list = new ArrayList<LatLng>();
for (Coord2D vertex : footprint.getVertexInGlobalFrame()) {
list.add(DroneHelper.CoordToLatLang(vertex));
}
footprintPoly.setPoints(list);
}
}

@Override
public void updatePolygonsPaths(List<List<Coord2D>> paths){
for (Polygon poly : polygonsPaths) {
poly.remove();
Expand All @@ -550,7 +572,7 @@ public void addCameraFootprint(Footprint footprintToBeDraw) {
pathOptions.strokeColor(FOOTPRINT_DEFAULT_COLOR).strokeWidth(FOOTPRINT_DEFAULT_WIDTH);
pathOptions.fillColor(FOOTPRINT_FILL_COLOR);

for (Coord2D vertex : footprintToBeDraw.getVertex()) {
for (Coord2D vertex : footprintToBeDraw.getVertexInGlobalFrame()) {
pathOptions.add(DroneHelper.CoordToLatLang(vertex));
}
getMap().addPolygon(pathOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,10 @@ public void addCameraFootprint(Footprint footprintToBeDraw) {
// TODO Auto-generated method stub

}

@Override
public void updateRealTimeFootprint(Footprint footprint) {
// TODO Auto-generated method stub

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.droidplanner.R;
import org.droidplanner.android.utils.file.help.CameraInfoLoader;
import org.droidplanner.core.mission.survey.CameraInfo;
import org.droidplanner.core.survey.CameraInfo;

import android.content.Context;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.droidplanner.android.widgets.spinners.SpinnerSelfSelect;
import org.droidplanner.core.helpers.units.Altitude;
import org.droidplanner.core.mission.MissionItemType;
import org.droidplanner.core.mission.survey.CameraInfo;
import org.droidplanner.core.mission.waypoints.StructureScanner;
import org.droidplanner.core.survey.CameraInfo;

import android.content.Context;
import android.os.Bundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.droidplanner.core.drone.DroneInterfaces;
import org.droidplanner.core.helpers.units.Altitude;
import org.droidplanner.core.mission.MissionItemType;
import org.droidplanner.core.mission.survey.CameraInfo;
import org.droidplanner.core.mission.survey.Survey;
import org.droidplanner.core.model.Drone;
import org.droidplanner.core.survey.CameraInfo;

import android.content.Context;
import android.graphics.Color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.IOException;
import java.io.InputStream;

import org.droidplanner.core.mission.survey.CameraInfo;
import org.droidplanner.core.survey.CameraInfo;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.droidplanner.android.utils.file.DirectoryPath;
import org.droidplanner.android.utils.file.FileList;
import org.droidplanner.android.utils.file.IO.CameraInfoReader;
import org.droidplanner.core.mission.survey.CameraInfo;
import org.droidplanner.core.survey.CameraInfo;

import android.content.Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public boolean isEnglishDefaultLanguage() {
return prefs.getBoolean(context.getString(R.string.pref_ui_language_english_key),
DEFAULT_PREF_UI_LANGUAGE);
}

public boolean isRealtimeFootprintsEnabled() {
return prefs.getBoolean(context.getString(R.string.pref_ui_realtime_footprints_key),
false);
}

public String getMapProviderName() {
return prefs.getString(context.getString(R.string.pref_maps_providers_key), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void receiveData(MAVLinkMessage msg) {
}
break;
case msg_camera_feedback.MAVLINK_MSG_ID_CAMERA_FEEDBACK:
drone.getCameraFootprints().newImageLocation((msg_camera_feedback) msg);
drone.getCamera().newImageLocation((msg_camera_feedback) msg);
break;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions Core/src/org/droidplanner/core/drone/DroneImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.droidplanner.core.drone.variables.Altitude;
import org.droidplanner.core.drone.variables.Battery;
import org.droidplanner.core.drone.variables.Calibration;
import org.droidplanner.core.drone.variables.CameraFootprints;
import org.droidplanner.core.drone.variables.Camera;
import org.droidplanner.core.drone.variables.GPS;
import org.droidplanner.core.drone.variables.GuidedPoint;
import org.droidplanner.core.drone.variables.HeartBeat;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class DroneImpl implements Drone {
private final Calibration calibrationSetup;
private final WaypointManager waypointManager;
private final Magnetometer mag;
private final CameraFootprints footprints;
private final Camera footprints;
private final State state;
private final HeartBeat heartbeat;
private final Parameters parameters;
Expand Down Expand Up @@ -85,7 +85,7 @@ public DroneImpl(MAVLinkStreams.MAVLinkOutputStream mavClient, DroneInterfaces.C
this.calibrationSetup = new Calibration(this);
this.waypointManager = new WaypointManager(this);
this.mag = new Magnetometer(this);
this.footprints = new CameraFootprints(this);
this.footprints = new Camera(this);

loadVehicleProfile();
}
Expand Down Expand Up @@ -271,7 +271,7 @@ public Magnetometer getMagnetometer() {
return mag;
}

public CameraFootprints getCameraFootprints() {
public Camera getCamera() {
return footprints;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import java.util.ArrayList;
import java.util.List;

import org.droidplanner.core.drone.DroneVariable;
import org.droidplanner.core.drone.DroneInterfaces.DroneEventsType;
import org.droidplanner.core.helpers.coordinates.Coord2D;
import org.droidplanner.core.mission.survey.CameraInfo;
import org.droidplanner.core.drone.DroneVariable;
import org.droidplanner.core.model.Drone;
import org.droidplanner.core.survey.CameraInfo;
import org.droidplanner.core.survey.Footprint;

import com.MAVLink.Messages.ardupilotmega.msg_camera_feedback;

public class CameraFootprints extends DroneVariable {
public class Camera extends DroneVariable {
private CameraInfo camera = new CameraInfo();
private List<Footprint> footprints = new ArrayList<Footprint>();

public CameraFootprints(Drone myDrone) {
public Camera(Drone myDrone) {
super(myDrone);
}

Expand All @@ -28,5 +27,16 @@ public void newImageLocation(msg_camera_feedback msg) {
public Footprint getLastFootprint() {
return footprints.get(footprints.size()-1);
}

public CameraInfo getCamera(){
return camera;
}

public Footprint getCurrentFieldOfView() {
return new Footprint(camera, myDrone .getGps()
.getPosition(), myDrone.getAltitude().getAltitude(), myDrone.getOrientation()
.getPitch(), myDrone.getOrientation().getRoll(), myDrone.getOrientation()
.getYaw());
}

}
15 changes: 15 additions & 0 deletions Core/src/org/droidplanner/core/helpers/coordinates/Coord2D.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.droidplanner.core.helpers.coordinates;

import org.droidplanner.core.helpers.geoTools.GeoTools;

public class Coord2D {
private double latitude; // aka x
private double longitude; // aka y
Expand Down Expand Up @@ -71,4 +73,17 @@ public static Coord2D sum(Coord2D... toBeAdded) {
}
return new Coord2D(latitude, longitude);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof Coord2D) {
return equals((Coord2D) obj);
}else{
return super.equals(obj);
}
}

public boolean equals(Coord2D obj) {
return GeoTools.getDistance(this, obj).valueInMeters()<1e-6;
}
}
22 changes: 20 additions & 2 deletions Core/src/org/droidplanner/core/helpers/geoTools/GeoTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Double getAproximatedDistance(Coord2D p1, Coord2D p2) {
return (Math.hypot((p1.getX() - p2.getX()), (p1.getY() - p2.getY())));
}

public static Double metersTolat(double meters) {
private static Double metersTolat(double meters) {
return Math.toDegrees(meters / RADIUS_OF_EARTH);
}

Expand Down Expand Up @@ -72,7 +72,25 @@ public static Coord2D newCoordFromBearingAndDistance(Coord2D origin, double bear

return (new Coord2D(Math.toDegrees(lat2), Math.toDegrees(lon2)));
}


/**
* Offset a coordinate by a local distance
* @param original location in WGS84
* @param xMeters Offset distance in the east direction
* @param yMeters Offset distance in the north direction
* @return new coordinate with the offset
*/
public static Coord2D moveCoordinate(Coord2D origin, double xMeters, double yMeters) {
double lon = origin.getLng();
double lat = origin.getLat();
double lon1 = Math.toRadians(lon);
double lat1 = Math.toRadians(lat);

double lon2 = lon1+ Math.toRadians(metersTolat(xMeters));
double lat2 = lat1+ Math.toRadians(metersTolat(yMeters));
return (new Coord2D(Math.toDegrees(lat2), Math.toDegrees(lon2)));
}

/**
* Calculates the arc between two points
* http://en.wikipedia.org/wiki/Haversine_formula
Expand Down
28 changes: 28 additions & 0 deletions Core/src/org/droidplanner/core/helpers/math/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,32 @@ public static double bisectAngle(double a, double b, double alpha) {
public static Length hypot(Length altDelta, Length distDelta) {
return new Length(Math.hypot(altDelta.valueInMeters(), distDelta.valueInMeters()));
}

/**
* Create a rotation matrix given some euler angles
* this is based on http://gentlenav.googlecode.com/files/EulerAngles.pdf
*/
public static double [][] dcmFromEuler(double roll, double pitch, double yaw)
{
double dcm[][] = new double[3][3];

double cp = Math.cos(pitch);
double sp = Math.sin(pitch);
double sr = Math.sin(roll);
double cr = Math.cos(roll);
double sy = Math.sin(yaw);
double cy = Math.cos(yaw);

dcm[0][0] = cp * cy;
dcm[1][0] = (sr * sp * cy) - (cr * sy);
dcm[2][0] = (cr * sp * cy) + (sr * sy);
dcm[0][1] = cp * sy;
dcm[1][1] = (sr * sp * sy) + (cr * cy);
dcm[2][1] = (cr * sp * sy) - (sr * cy);
dcm[0][2] = -sp;
dcm[1][2] = sr * cp;
dcm[2][2] = cr * cp;

return dcm;
}
}
1 change: 1 addition & 0 deletions Core/src/org/droidplanner/core/mission/survey/Survey.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.droidplanner.core.mission.survey.grid.Grid;
import org.droidplanner.core.mission.survey.grid.GridBuilder;
import org.droidplanner.core.polygon.Polygon;
import org.droidplanner.core.survey.CameraInfo;

import com.MAVLink.Messages.ardupilotmega.msg_mission_item;
import com.MAVLink.Messages.enums.MAV_CMD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.droidplanner.core.helpers.units.Altitude;
import org.droidplanner.core.helpers.units.Area;
import org.droidplanner.core.helpers.units.Length;
import org.droidplanner.core.survey.CameraInfo;

public class SurveyData {
private Altitude altitude = new Altitude(50.0);
Expand Down
Loading