WIP: Adding Alt Frames (ie. Terrain) to API#460
WIP: Adding Alt Frames (ie. Terrain) to API#460billbonney wants to merge 6 commits intodronekit:developfrom
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.
It's like a shallow copy, i'm not sure when set is called and why? why is using set different from
latLgAlt1 = latLgAlt2
| private double latitude; | ||
| private double longitude; | ||
|
|
||
| public LatLong(){ |
There was a problem hiding this comment.
@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.
@billbonney I'd advocate for the removal of the frame field since it can be substitute by the enum itself.
| private double mAltitude; | ||
| private Frame mFrame; | ||
|
|
||
| public LatLongAlt() { |
There was a problem hiding this comment.
@billbonney Same comment as with LatLong. I fail to see the utility of a default constructor.
There was a problem hiding this comment.
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.
it looks like the above is related with change b343b8c
|
|
||
| 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.
@billbonney Since mFrame is an enum, you can just compare it using that.mFrame != mFrame.
There was a problem hiding this comment.
In addition, the equals(), hashCode() and toString() methods were generated automatically via Android Studio: Code => Generate.
There was a problem hiding this comment.
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.
@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.
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)
| } | ||
|
|
||
| private ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle){ | ||
| public ConnectionParameter(@ConnectionType.Type int connectionType, Bundle paramsBundle){ |
There was a problem hiding this comment.
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.
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.
@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.