Skip to content

Commit 76d62a3

Browse files
committed
Added ability to modify the GUIDED SCAN roi altitude.
1 parent ccbed60 commit 76d62a3

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

ServiceApp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727
applicationId 'org.droidplanner.services.android'
2828
minSdkVersion 14
2929
targetSdkVersion 21
30-
versionCode 10109
30+
versionCode 10110
3131
versionName getGitVersion()
3232
}
3333

ServiceApp/src/org/droidplanner/services/android/api/DroneApi.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.droidplanner.core.gcs.follow.Follow;
7171
import org.droidplanner.core.gcs.follow.FollowAlgorithm;
7272
import org.droidplanner.core.helpers.coordinates.Coord2D;
73+
import org.droidplanner.core.helpers.coordinates.Coord3D;
7374
import org.droidplanner.core.model.Drone;
7475
import org.droidplanner.core.parameters.Parameter;
7576
import org.droidplanner.core.survey.CameraInfo;
@@ -730,9 +731,10 @@ private FollowState getFollowState() {
730731
for(Map.Entry<String, Object> entry : modeParams.entrySet()){
731732
switch(entry.getKey()){
732733
case FollowType.EXTRA_FOLLOW_ROI_TARGET:
733-
Coord2D target = (Coord2D) entry.getValue();
734+
Coord3D target = (Coord3D) entry.getValue();
734735
if(target != null){
735-
params.putParcelable(entry.getKey(), new LatLong(target.getLat(), target.getLng()));
736+
params.putParcelable(entry.getKey(), new LatLongAlt(target.getLat(), target.getLng(),
737+
target.getAltitude().valueInMeters()));
736738
}
737739
break;
738740

@@ -999,11 +1001,20 @@ public void performAction(Action action) throws RemoteException {
9991001
if(followAlgorithm != null){
10001002
Map<String, Object> paramsMap = new HashMap<>();
10011003
Set<String> dataKeys = data.keySet();
1004+
10021005
for(String key: dataKeys){
10031006
if(FollowType.EXTRA_FOLLOW_ROI_TARGET.equals(key)){
10041007
LatLong target = data.getParcelable(key);
10051008
if(target != null) {
1006-
Coord2D roiTarget = new Coord2D(target.getLatitude(), target.getLongitude());
1009+
final Coord2D roiTarget;
1010+
if(target instanceof LatLongAlt) {
1011+
roiTarget = new Coord3D(target.getLatitude(), target.getLongitude(),
1012+
new org.droidplanner.core.helpers.units.Altitude(((LatLongAlt) target)
1013+
.getAltitude()));
1014+
}
1015+
else{
1016+
roiTarget = new Coord2D(target.getLatitude(), target.getLongitude());
1017+
}
10071018
paramsMap.put(key, roiTarget);
10081019
}
10091020
}

dependencyLibs/Core/src/org/droidplanner/core/gcs/follow/FollowGuidedScan.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
*/
1717
public class FollowGuidedScan extends FollowAbove {
1818

19+
private static final String TAG = FollowGuidedScan.class.getSimpleName();
20+
1921
public static final String EXTRA_FOLLOW_ROI_TARGET = "extra_follow_roi_target";
2022

23+
public static final double DEFAULT_FOLLOW_ROI_ALTITUDE = 10; //meters
24+
private static final Altitude sDefaultRoiAltitude = new Altitude(DEFAULT_FOLLOW_ROI_ALTITUDE);
25+
2126
@Override
2227
public FollowModes getType() {
2328
return FollowModes.GUIDED_SCAN;
@@ -31,7 +36,16 @@ public FollowGuidedScan(Drone drone, DroneInterfaces.Handler handler) {
3136
public void updateAlgorithmParams(Map<String, ?> params){
3237
super.updateAlgorithmParams(params);
3338

34-
Coord2D target = (Coord2D) params.get(EXTRA_FOLLOW_ROI_TARGET);
39+
final Coord3D target;
40+
41+
Coord2D tempCoord = (Coord2D) params.get(EXTRA_FOLLOW_ROI_TARGET);
42+
if(tempCoord == null || tempCoord instanceof Coord3D){
43+
target = (Coord3D) tempCoord;
44+
}
45+
else{
46+
target = new Coord3D(tempCoord, sDefaultRoiAltitude);
47+
}
48+
3549
getROIEstimator().updateROITarget(target);
3650
}
3751

@@ -54,26 +68,29 @@ protected GuidedROIEstimator getROIEstimator(){
5468

5569
private static class GuidedROIEstimator extends ROIEstimator {
5670

57-
private Coord2D roiTarget;
71+
private Coord3D roiTarget;
5872

5973
public GuidedROIEstimator(Drone drone, DroneInterfaces.Handler handler) {
6074
super(drone, handler);
6175
}
6276

63-
void updateROITarget(Coord2D roiTarget){
77+
void updateROITarget(Coord3D roiTarget){
6478
this.roiTarget = roiTarget;
6579
onLocationChanged(null);
6680
}
6781

6882
@Override
6983
protected void updateROI(){
7084
if(roiTarget == null){
85+
System.out.println("Cancelling ROI lock.");
7186
//Fallback to the default behavior
7287
super.updateROI();
7388
}
7489
else{
90+
System.out.println("ROI Target: " + roiTarget.toString());
91+
7592
//Track the target until told otherwise.
76-
MavLinkROI.setROI(drone, new Coord3D(roiTarget, new Altitude(1.0)));
93+
MavLinkROI.setROI(drone, roiTarget);
7794
}
7895
}
7996
}

dependencyLibs/Core/src/org/droidplanner/core/helpers/coordinates/Coord3D.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public void set(double lat, double lon, Altitude alt) {
2626
public Altitude getAltitude() {
2727
return alt;
2828
}
29+
30+
@Override
31+
public String toString() {
32+
return "lat/lon/alt: " + getLat() + "/" + getLng() + "/" + alt.toString();
33+
}
2934
}

0 commit comments

Comments
 (0)