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

WIP: Adding Alt Frames (ie. Terrain) to API #460

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

billbonney
Copy link
Collaborator

@billbonney billbonney commented Oct 30, 2016

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.

- 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.
@billbonney billbonney changed the title WIP: Adding Frames to API WIP: Adding Alt Frames (ie. Terrain) to API Oct 30, 2016
@billbonney
Copy link
Collaborator Author

billbonney commented Nov 9, 2016

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@billbonney How so?

Copy link
Collaborator Author

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(){
Copy link
Member

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;
Copy link
Member

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() {
Copy link
Member

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.

Copy link
Collaborator Author

@billbonney billbonney Nov 15, 2016

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);
    }

Copy link
Collaborator Author

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()) )
Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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) {
Copy link
Member

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.

Copy link
Collaborator Author

@billbonney billbonney Nov 15, 2016

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){
Copy link
Member

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?

Copy link
Collaborator Author

@billbonney billbonney Nov 15, 2016

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.

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

Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants