Coder Social home page Coder Social logo

liuxuan30 / telloswift Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 7.0 1.28 MB

DJI Tello Swift Framework powered by SwiftNIO

License: Apache License 2.0

Objective-C 0.63% Swift 99.37%
tello dji-tello tello-frameworks swiftnio swift-framework macos ios

telloswift's Introduction

TelloSwift Build Status License Codecov

A DJI Tello(plus EDU) Swift Framework, powered by Apple's SwiftNIO

Logo

There are already a lot of Tello frameworks in Python, but I don't see a decent one for Apple's platform, especially in Swift.

Therefore I decided to develop this framework combining latest Swift trend and replaced traditional socket programming fashion with SwiftNIO, an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol.

TelloSwift is built upon SwiftNIO purely in Swift, providing flexible protocols and All-In-One Tello class that you can use to control your Tello drone. It supports both Tello and Tello EDU/IronMan edition.

Features

  • Flexible Protocol design so you can implement your own Tello controller;
  • Event-driven duplex command handlers based on SwiftNIO, powering sync and async command execution;
  • Many useful built-in control commands to design your own flight flow;
  • Full coverage for both Tello SDK and Tello 2.0 SDK (except for swarm)
  • Provide a default H264 video decoder, more details here

Requirement

  • Xcode 11 / Swift 5
  • iOS >= 12.0
  • macOS >= 10.15*
  • Ubuntu**

*For simplicity and Catalyst, I choose 10.15, but the source code itself should support macOS since 10.13, aligned with SwiftNIO's requirement.

** For Linux OS, refer Swift and SwiftNIO compatibility.

Installation

Just grab the source code, or add Swift package by

dependencies: [
    .package(url: "https://github.com/liuxuan30/TelloSwift.git")
]

Or, if your project is set up as an Xcode project and you're using Xcode 11+, you can add TelloSwift as a dependency to your Xcode project by clicking File -> Swift Packages -> Add Package Dependency.

How to use it

To use Tello you just have to create Tello object, like

let tello = Tello()

print("connected:", tello.activate())

print("battery:", tello.battery)
if tello.battery < 20 {
    tello.shutdown()
    print("battery too low")
}

print(tello.speed)

By default, Tello is initialized as EDU version. If your drone is not EDU, just use another initializer such as

public convenience init(localAddr: String, localPort: Int, EDU: Bool)

There are several convenience initializer for your favorite.

To take off, first invoke tello.activate() and then simply call tello.takeoff(), or use convenient method:

takeoffAnd(operation: @escaping () -> Void)

You can even chain the command:

tello.chain("takeoff").chain("forward 20", failover: .hover).chain("land")

After you finished playing with your drone, simply call tello.shutdown(), which will close the channel and free NIO event loop resources.

Note you should always call shutdown() before Tello object get deallocated. Otherwise the threads and already associated file descriptors could be leaked.

Architecture

Tello is assembled with multiple protocols.

TelloCommandHandler and TelloCommander

What if the existing methods could not meet my demand?

At the heart of TelloSwift, TelloCommander is resonsible for sending tello commands either in sync or async mode. Behind the scene, TelloCommandHandler is a duplex ChannelHander, mirroring from RequestResponseHandler in swift-nio-extras.

You can replace them with your own implementations, or just get the promise from TelloCommander.dispatchCommand(). You can find more about EventLoopPromise from NIO documentation

TelloMotion, TelloFlightControl and MissionPadControl protocol

These protocols encapsulate commands for tello flight control. To turn on mission pad detection, simply call tello.enable(detection: true and setDirection(direction: .both)

For single flight commands taking distance argument, if the distance exceeds max value, it will automatically mod (max value + 1), if it's less then min value, it will return false. For commands only takes angles, it will mod 361.

For flight commands that involves both speed and distance like go/curve/jump, for safety purpose, TelloSwift will check if the parameter falls in to the valid range. It would also check if the command requires Tello EDU. If not satisfied, command would return false.

TelloState and DroneTello protocol

TelloState is the delegate protocol for receiving tello state raw string from UDP packets. Currently there are no further processing about the state string. DroneTello is for obtaining the Tello state in real time. To turn on state reporting, set stateDelegate.

TelloVideoSteam and CameraControl protocol

It will directly forward the raw stream bytes to the delegate. To turn on the camera, just call tello.enable(video: true)

TODO list

  1. Swarm support

telloswift's People

Contributors

liuxuan30 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

telloswift's Issues

I got confuse just need to update swift-nio

/Users/xxxx/Library/Developer/Xcode/DerivedData/TelloSwift-abixwqckxzxfmzarxoesypgigocg/SourcePackages/checkouts/swift-nio/Sources/NIO/MarkedCircularBuffer.swift:132:1 Type 'MarkedCircularBuffer' does not conform to protocol 'MutableCollection'

/Users/xxxx/Library/Developer/Xcode/DerivedData/TelloSwift-abixwqckxzxfmzarxoesypgigocg/SourcePackages/checkouts/swift-nio/Sources/NIO/MarkedCircularBuffer.swift:132:1 Unavailable subscript 'subscript(_:)' was used to satisfy a requirement of protocol 'MutableCollection'

Video stream Data

Hi @liuxuan30,
I'm trying out your library which works great but I'm having trouble getting the video stream to work.

I set the videoDelegate and I'm receiving frames but can you clarify a bit more what to do with it? I'm getting a Data object back but I would like to get a NSImage or UIImage object from it. Can you describe how to do that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.