Yuneec + AirMap Android Integration

Learn how to build an Android app using the Yuneec SDK and AirMap SDK to Create a Flight, Send Telemetry and Receive Real-Time Traffic Alerts.

Setup

AirMap Setup

Start by adding the AirMap SDK to your project. If this is your first time working with the AirMap SDK, you may want to review the detailed Android Setup guide before continuing. To summarize:

  1. Add implementation 'com.airmap.airmapsdk:airmapsdk:2.0.0' to your module-level build.grade file

  2. Initialize the SDK by calling AirMap.init in your onCreate method:

AirMap.init(MainActivity.this);
  1. Add airmap.config.json file to your project that you have downloaded from your Developer Account

Yuneec Setup

Please follow the Yuneec SDK Setup Guide

You may also find the API Reference and Example Android App helpful.

Integration

Connect to the drone

The Yuneec SDK Connection class provides a way to establish connection with the drone. Please see the Yuneec Guide for more details.

public static
void registerConnectionListener ()
{

    Connection.Listener connectionListener = new Connection.Listener ( )
    {
        @Override
        public
        void onDiscoverCallback ( )
        {
            // Handle on discover
            Log.d ( TAG, "Discovered Drone" );
        }

        @Override
        public
        void onTimeoutCallback ( )
        {
            // Handle on time out
            Log.d ( TAG, "Timed Out! Reconnect" );
        }
    };

    Connection.addListener ( connectionListener );

    Connection.Result result = Connection.addConnection ( );

}

AirMap Login

To connect to AirMap, a user must be logged in. This can be done anonymously using Anonymous Authentication like so:

String userId = "acme|123";

AirMap.performAnonymousLogin(userId, new AirMapCallback<Void>() {
    @Override
    public void onSuccess(Void response) {
        AirMapLog.d(TAG, "Token is: " + AirMap.getAuthToken());

        // Handle login
    }

    @Override
    public void onError(AirMapException e) {
        AirMapLog.e(TAG, e.getDetailedMessage(), e);

        // Handle error here
    }
});

Create a Mission

To create a mission, you need to first create a list of waypoints using the MissionItem class:

MissionItem makeMissionItem(double latitudeDeg, 
                            double longitude, 
                            float relativeAltitude, 
                            MissionItem.CameraAction cameraAction, 
                            float gimbalPitchDeg, float gimbalYawDeg) {
        MissionItem newItem = new MissionItem();
        newItem.setPosition(latitudeDeg, longitudeM);
        newItem.setRelativeAltitude(relativeAltitudeM);
        newItem.setCameraAction(cameraAction);
        newItem.setGimbalPitchAndYaw(gimbalPitchDeg, gimbalYawDeg);
        return newItem;
    }

Please see the Yuneec Guide for more details.

Once you have a list of waypoints, you can send this mission to the drone:

sendMissionAsync(ArrayList missionItems, Mission.ResultListener listener)

After this mission is loaded on the drone, you can create an AirMap Flight Plan in the Mission.ResultListener.

// sets required params
AirMapFlightPlan flightPlan = new AirMapFlightPlan();
flightPlan.setPilotId(AirMap.getUserId());
flightPlan.setGeometry(polygon);
flightPlan.setBuffer(buffer);
flightPlan.setTakeoffCoordinate(takeoffCoordinate);
flightPlan.setRulesetIds(rulesetIds);

flightPlan.setMaxAltitude(100);

flightPlan.setStartsAt(startDate);
flightPlan.setEndsAt(endDate);

AirMap.createFlightPlan(flightPlan, new AirMapCallback<AirMapFlightPlan>() {
    @Override
    protected void onSuccess(AirMapFlightPlan response) {
        AirMapLog.d(TAG, "Flight plan created: " + response.getPlanId());
        // Handle success
    }

    @Override
    protected void onError(AirMapException e) {
        AirMapLog.e(TAG, "Failed to create flight plan", e);
        // Handle error
    }
});

Fly

Finally, to execute this mission, send this command:

startMissionAsync(Mission.ResultListener listener)

Once the mission is executed, we should submit the AirMap Flight Plan in the Mission.ResultListener:

 AirMap.submitFlightPlan(flightPlanId, new AirMapCallback<AirMapFlightPlan>() {
    @Override
    protected void onSuccess(AirMapFlightPlan flightPlan) {
        AirMapLog.d(TAG, "Flight id: " + flightPlan.getFlightId());
    }

    @Override
    protected void onError(AirMapException e) {
        // Handle error case
    }
});

Traffic Alerts

Still within the Mission.ResultListener, we can start listening for Traffic Alerts:

// To turn on traffic alerts
AirMap.enableTrafficAlerts(new AirMapTrafficListener() {
    @Override
    public void onAddTraffic(List<AirMapTraffic> added) {
        // Display traffic on map
    }

    @Override
    public void onUpdateTraffic(List<AirMapTraffic> updated) {
        // Update traffic on map
    }

    @Override
    public void onRemoveTraffic(List<AirMapTraffic> removed) {
        // Remove traffic from map
    }
});

// To turn off traffic alerts
AirMap.disableTrafficAlerts();

End Flight

When the mission is finished, end the AirMap Flight:

// only call end if the flight is active
AirMap.endFlight(flightId, new AirMapCallback<AirMapFlight>() {
    @Override
    public void onSuccess(AirMapFlight response) {
        // Handle success (remove from map, disable traffic alerts, etc)
    }

    @Override
    public void onError(AirMapException e) {
        // Handle error
    }
});

Yuneec + AirMap Android Integration

Learn how to build an Android app using the Yuneec SDK and AirMap SDK to Create a Flight, Send Telemetry and Receive Real-Time Traffic Alerts.