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.


Follow me framing target
#3

Hello! Help me, please. I try to realize follow me procedure
i set target`s gps coordinates by command

case IHM_SEND_GPS:
if (deviceController != NULL)
{
struct timeval now;
gettimeofday(&now, NULL);
error = deviceController->controller_info->sendGps(deviceController->controller_info, 48.879212, 2.368318, 0.7, 1.0, 1.0, 1.0, 1.0, 1.0, now.tv_sec);
}

and then start follow me by command:
case IHM_START_FOLLOW_ME:
if(deviceController != NULL)
{
error = deviceController->follow_me->sendConfigureRelative(deviceController->follow_me, 0, 0.0, 0.0, 0.0);
error = deviceController->follow_me->sendTargetFramingPosition(deviceController->follow_me, 50, 50);
error = deviceController->follow_me->sendStart(deviceController->follow_me, ARCOMMANDS_FOLLOW_ME_MODE_RELATIVE);
}

But drone does not follow the target. what am I doing wrong? In “commandReceived” on “state of follow me” callback i get relative mode and idle behavior. i use sphinx emulator


#4

I have not tried this in Sphinx. I have always tested the hard way, using a real drone and a lot of personal grit.


#5

Hello, @synman!
I tried to implement “follow me” for unix, but without success. Do you have a working implementation of this function for Unix? It would help me a lot. Thank you!


#6

Unfortunately I do not have a “native” implementation. I use the SDK through java (android).