Skip to content

Unity Plugin for Android Application to use Tello Low-Level Protocol

License

Notifications You must be signed in to change notification settings

ototadana/tydrone-android

Repository files navigation

tydrone-android-plugin

Unity Plugin for Android Application to use Tello Low-Level Protocol.

This is for running tello-llp-wrapper on android devices.

Requirement

Android 10. This plugin has been tested with Meta Quest 2 and Meta Quest Pro.

Setup

  1. Download tello-llp-wrapper-1.1.2.jar from this page.
  2. Copy tello-llp-wrapper-1.1.2.jar to the ./tydrone-android-plugin/libs folder. If the folder does not exist, create it.
  3. Download javacv-platform-1.5.8-bin.zip
  4. Create a small jar file using a script like the following:
    # unzip the downloaded file
    unzip javacv-platform-1.5.8-bin.zip
    
    # cd to the destination folder of the zip file
    cd javacv-platform-1.5.8-bin
    
    # create a working directory
    mkdir tmp
    
    # copy important files
    cp LICENSE.txt tmp
    cp README.md tmp
    cp CHANGELOG.md tmp
    
    # extract jar files to the tmp directory
    cd tmp
    jar xf ../ffmpeg.jar
    jar xf ../ffmpeg-android-arm64.jar
    jar xf ../javacpp.jar
    jar xf ../javacpp-android-arm64.jar
    jar xf ../javacv.jar
    jar xf ../openblas.jar
    jar xf ../openblas-android-arm64.jar
    jar xf ../opencv.jar
    jar xf ../opencv-android-arm64.jar
    
    # remove some files to avoid build errors
    rm -fr META-INF/versions
    rm -fr META-INF/native-image
    
    # create jar file
    jar cf javacv-1.5.8.jar *
  5. Copy the created jar file to the ./tydrone-android-plugin/libs folder.
  6. Copy classes.jar from Unity to the ./tydrone-android-plugin/dev-libs folder.
  7. Build tydrone-android-plugin module.
  8. Copy ./tydrone-android-plugin/build/outputs/aar/tydrone-android-plugin-*.aar to Assets/Plugins/Android folder of your Unity Project.

Usage

The Facade interface of the tello-llp-wrapper can be used in Unity scripts by creating a simple wrapper class like the following:

public class TyDroneAndroidPlugin
{
    private AndroidJavaObject tyDrone;

    public TyDroneAndroidPlugin()
    {
        this.tyDrone = new AndroidJavaObject("com.xpfriend.tydrone.AndroidMain");
    }

    public void EntryCommand(string command)
    {
        tyDrone.Call("entryCommand", command);
    }

    public string GetNotice()
    {
        return tyDrone.Call<string>("getNotice");
    }

    public string GetSentCommand()
    {
        return tyDrone.Call<string>("getSentCommand");
    }

    public string GetStates()
    {
        return tyDrone.Call<string>("getStates");
    }

    public bool IsRecording()
    {
        return tyDrone.Call<bool>("isRecording");
    }

    public byte[] PickImage()
    {
        AndroidJavaObject obj = this.tyDrone.Call<AndroidJavaObject>("pickImage");
        if (obj == null || obj.GetRawObject() == null)
        {
            return new byte[] { };
        }

        sbyte[] image = AndroidJNIHelper.ConvertFromJNIArray<sbyte[]>(obj.GetRawObject());
        if (image == null)
        {
            return new byte[] { };
        }
        return (byte[])(Array)image;
    }

    public void SetRecording(bool value)
    {
        this.tyDrone.Call("setRecording", value);
    }

    public void Run()
    {
        this.tyDrone.Call("run");
    }
}

For example, you can apply the video image obtained from Tello to Texture2D as follows:

byte[] bytes = tyDrone.PickImage();
if (bytes.Length == 0)
{
   return;
}

Texture2D texture = new Texture2D(960, 720, TextureFormat.RGB24, false);
texture.LoadRawTextureData(bytes);
texture.Apply();

See README.md of the tello-llp-wrapper for information on the use of other methods.

License

This software is released under the MIT License, see LICENSE.

For dependent software licenses, see:

About

Unity Plugin for Android Application to use Tello Low-Level Protocol

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages