-
Notifications
You must be signed in to change notification settings - Fork 245
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
WIP: Adding Alt Frames (ie. Terrain) to API #460
base: develop
Are you sure you want to change the base?
Conversation
- This allow support for using different frames - Absolute (GLOBAL_ABS) which relates to AMSL - Relative (GLOBAL_RELATIVE) which means relative to home location - Terrain (GLOBAL_TERRAIN) which means AGL (via Range Finder or STRM Data) - Tested with “round-robbin” download/upload with APM Planner 2.0 Frame setting is preserved from original setting.
@ne0fhyk @kellyschrock Ok, I think this is ready to go... some comments would be nice... 👍 Thx Also see DroidPlanner/Tower#1826 for the required changes in Tower |
} | ||
|
||
public void set(LatLongAlt source){ | ||
public void set(LatLongAlt source){ // TODO: this looks wrong |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney How so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's like a shallow copy, i'm not sure when set is called and why? why is using set different from
latLgAlt1 = latLgAlt2
@@ -18,6 +18,11 @@ | |||
private double latitude; | |||
private double longitude; | |||
|
|||
public LatLong(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney I don't agree with having a default constructor. This is usually the cause of subtle and hard to find bugs. In which scenario would having a default constructor be helpful?
|
||
private final int frame; | ||
private final String name; | ||
private final String abbreviation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney I'd advocate for the removal of the frame
field since it can be substitute by the enum itself.
@@ -14,24 +15,34 @@ | |||
* Stores the altitude in meters. | |||
*/ | |||
private double mAltitude; | |||
private Frame mFrame; | |||
|
|||
public LatLongAlt() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney Same comment as with LatLong
. I fail to see the utility of a default constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can refactor this. It was a 'quick fix'. To resolve some npe I was having.
LATER: The issue is this in BaseSpatial. And that it constructed without a point.
public LatLongAlt getCoordinate() {
if (coordinate == null)
coordinate = new LatLongAlt();
return coordinate;
}
Which means it's partially created object. And then set to call here
public void addSpatialWaypoint(BaseSpatialItem spatialItem, LatLong point) {
double alt = getLastAltitude();
spatialItem.getCoordinate().set(point);
spatialItem.getCoordinate().setAltitude(alt);
addMissionItem(spatialItem);
}
The fix was to have getCoordinate to create a LatLngAlt when none existed. I can add the parameter list there.
The real fix is to refactor BaseSpatial on construction to take a point so it's not null in the first place (but that may break getNewItem for other mission items (i'll need to think about that)
@Override
public void onMapClick(LatLong point) {
if (missionProxy == null) return;
// If an mission item is selected, unselect it.
missionProxy.selection.clearSelection();
if (selectedType == null)
return;
BaseSpatialItem spatialItem = (BaseSpatialItem) selectedType.getNewItem();
missionProxy.addSpatialWaypoint(spatialItem, point);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like the above is related with change b343b8c
@@ -53,7 +76,9 @@ public boolean equals(Object o) { | |||
|
|||
LatLongAlt that = (LatLongAlt) o; | |||
|
|||
if (Double.compare(that.mAltitude, mAltitude) != 0) return false; | |||
if ((Double.compare(that.mAltitude, mAltitude) != 0) | |||
&& (that.mFrame.asInt() != mFrame.asInt()) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney Since mFrame
is an enum, you can just compare it using that.mFrame != mFrame
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, the equals()
, hashCode()
and toString()
methods were generated automatically via Android Studio: Code
=> Generate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good tip... I'll check that.
|
||
public LatLongAlt(double latitude, double longitude, double altitude) { | ||
public LatLongAlt(double latitude, double longitude, double altitude, Frame frame) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney Given that Frame.GLOBAL_RELATIVE
is the default frame, you could include an additional constructor that omit the frame parameter and sets mFrame
to Frame.GLOBAL_RELATIVE
.
This removes the need to update all the files where the constructor is invoked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that for a reason in that it exposes the parts in the code that sets the frame. I.e you can see explicitly what frame is being assumed. You don't want to accidentally put abs alt into relative. It would seem like a flyaway.
(LATER: Ironically, this is similar thought why default constructors are bad, it hides assumptions)
@@ -277,7 +277,7 @@ public static ConnectionParameter newSoloConnection(String ssid, @Nullable Strin | |||
eventsDispatchingPeriod); | |||
} | |||
|
|||
private ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle){ | |||
public ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billbonney Why make this public
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was having a build issue with this being private. I haven't investigated, and had not meant for it to be checked in. I should put a TODO on it, and come back and investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember class BasicTest complains about the access to this constructor while compilation:
https://github.com/dronekit/dronekit-android/blob/develop/ClientLib/src/androidTest/java/org/droidplanner/services/android/impl/BasicTest.java#L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mariansoban Thanks. I can revert this change for now and we can look at fixing the test cases
NOTE: this is not intended to be merge (yet 😀), more as a point of discussion.
This is the first working draft of adding frames to the current API to support terrain following.
It's also dependent of Tower PR DroidPlanner/Tower#1826
Comments welcome. Thx.