Implement Follow Me option in Android App


#1

Could you please share an idea to implement Follow Me option using Parrot SDK 3.0. I searched lot, but didn’t get an idea about coding part.

I am trying to create a Demo App with Follow Me, Basic Controllers, Video/Image capture or streaming for Behop 2.0 Quadcopter in an Indoor Area.

Please suggest, Is any documentation/samples available for Follow Me feature.


#2

It’s actually pretty easy:

In a Location Services onLocationChanged listener you need to provide the drone location updates:

private Location lastLoc = null;

public void onLocationChanged(final Location location) {

    final double lat = location.getLatitude();
    final double lng = location.getLongitude();
    final float alt = (float) location.getAltitude();

    final float accuracy = location.getAccuracy();

    if (lastLoc != null) {
        // calculate ns, es, and ds
        final LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        final LatLng lastNsLatLng = new LatLng(lastLoc.getLatitude(), location.getLongitude());
        final LatLng lastEsLatLng = new LatLng(location.getLatitude(), lastLoc.getLongitude());

        final float timeOffset = (location.getTime() - lastLoc.getTime()) / 1000f;

        ns = (float) SphericalUtil.computeDistanceBetween(lastNsLatLng, latLng) * timeOffset * (location.getLatitude() > lastLoc.getLatitude() ? -1f : 1f);
        es = (float) SphericalUtil.computeDistanceBetween(lastEsLatLng, latLng) * timeOffset * (location.getLongitude() > lastLoc.getLongitude() ? 1f : -1f);
        ds = (float) (lastLoc.getAltitude() - alt) * timeOffset;
    }

    featureControllerInfo.setGps(lat, lng, alt, accuracy, accuracy, ns, es, ds, System.currentTimeMillis());
    lastLoc = location;
}

If your device has a barometer be sure to include its pressure updates:

private long refTime = 0;

@Override
public void onSensorChanged(SensorEvent event) {

    if (event.accuracy == SensorManager.SENSOR_STATUS_ACCURACY_HIGH) {
        if (event.values != null && event.values.length > 0) {
             featureControllerInfo.setBarometer(event.values[0] * 100f, System.currentTimeMillis());
        }
    }
}

And then toggle using the FollowMe feature commands within some user generated event:

            if (featureFollowMe != null) {
                if (following) {
                    featureFollowMe.sendStop();
                    following = false;
                } else {
                    featureFollowMe.sendConfigureRelative((byte) 0, (float) 0f, 0f, 0f);
                    featureFollowMe.sendTargetFramingPosition((byte) 50, (byte) 50);
                    featureFollowMe.sendStart(ARCOMMANDS_FOLLOW_ME_MODE_ENUM.RELATIVE);

                    following = true;
                }
           }

There’s a couple different ways to do Camera Orientation movement. I do some basic geometry and set the perspective based on calculated angles between the drone and controller using altitude differences.