astitello

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2020 License: MIT Imports: 9 Imported by: 0

README

GoReportCard GoDoc Travis Coveralls

This is a Golang implementation of the DJI Tello SDK.

Up-to-date SDK documentation can be downloaded here.

Right now this library is compatible with v1.3.0.0 of SDK (documentation)

Disclaimer

Tello is a registered trademark of Ryze Tech. The author of this package is in no way affiliated with Ryze, DJI, or Intel.

Use this package at your own risk. The author(s) is/are in no way responsible for any damage caused either to or by the drone when using this software.

Install the project

Run the following command:

$ go get -u github.com/asticode/go-astitello/...

Run the example

IMPORTANT: the drone will make a flip to its right during this example, make sure you have enough space around the drone!

  1. Switch on your drone

  2. Connect to its Wifi

  3. If this is the first time you're using it, you may have to activate it using the official app

  4. If you want to test the video, install ffmpeg on your machine

  5. Run the following command:

$ go run example/main.go
  1. Watch your drone take off, make a flip to its right and land! Make sure to look at the terminal output too, some valuable information were printed there!

  2. If you've installed ffmpeg you should also see a new file called example.ts. Check it out!

Use it in your code

WARNING1: the code below doesn't handle errors for readibility purposes. However you SHOULD!

WARNING2: the code below doesn't list all available methods, be sure to check out the doc!

Set up the drone

// Create logger
l := log.New(os.StdErr, "", 0)

// Create the drone
d := astitello.New(l)

// Start the drone
d.Start()

// Make sure to close the drone once everything is over
defer d.Close()

Basic commands

// Handle take off event
d.On(astitello.TakeOffEvent, func(interface{}) { l.Println("drone has took off!") })

// Take off
d.TakeOff()

// Flip
d.Flip(astitello.FlipRight)

// Log state
l.Printf("state is: %+v\n", d.State())

// In case you're using controllers, you can use set sticks positions directly
d.SetSticks(-20, 10, -30, 40)

// Land
d.Land()

Video

// Handle new video packet
d.On(astitello.VideoPacketEvent, astitello.VideoPacketEventHandler(func(p []byte) {
    l.Printf("video packet length: %d\n", len(p))
}))

// Start video
d.StartVideo()

// Make sure to stop video
defer d.StopVideo()

Why this library?

First off, I'd like to say there are very nice DJI Tello libraries out there such as:

Unfortunately they seem to rely on reverse-engineering the official app which is undocumented.

If you'd rather use a library that is based on an official documentation, you've come to the right place!

Known problems with the SDK

  • sometimes a cmd doesn't get any response back from the SDK. In that case the cmd will idle until its timeout is reached.

Documentation

Index

Constants

View Source
const (
	LandEvent        = "land"
	StateEvent       = "state"
	TakeOffEvent     = "take.off"
	VideoPacketEvent = "video.packet"
)

Events

View Source
const (
	FlipBack    = "b"
	FlipForward = "f"
	FlipLeft    = "l"
	FlipRight   = "r"
)

Flip directions

Variables

View Source
var ErrNotConnected = errors.New("astitello: not connected")

ErrNotConnected is the error thrown when trying to send a cmd while not connected to the drone

Functions

func StateEventHandler

func StateEventHandler(f func(s State)) astikit.EventerHandler

StateEventHandler returns the proper EventHandler for the State event

func VideoPacketEventHandler

func VideoPacketEventHandler(f func(p []byte)) astikit.EventerHandler

VideoPacketEventHandler returns the proper EventHandler for the VideoPacket event

Types

type Acceleration

type Acceleration struct {
	X float64
	Y float64
	Z float64
}

Acceleration represents the drone's acceleration

type Attitude

type Attitude struct {
	Pitch int // The degree of the attitude pitch
	Roll  int // The degree of the attitude roll
	Yaw   int // The degree of the attitude yaw
}

Attitude represents the drone's attitude

type Drone

type Drone struct {
	// contains filtered or unexported fields
}

Drone represents an object capable of interacting with the SDK

func New

func New(l astikit.StdLogger) *Drone

New creates a new Drone

func (*Drone) Back

func (d *Drone) Back(x int) (err error)

Back makes Tello fly back with distance x cm

func (*Drone) Close

func (d *Drone) Close()

Close closes the drone properly

func (*Drone) Curve

func (d *Drone) Curve(x1, y1, z1, x2, y2, z2, speed int) (err error)

Curve makes Tello fly a curve defined by the current and two given coordinates with speed (cm/s)

func (*Drone) Down

func (d *Drone) Down(x int) (err error)

Down makes Tello fly down with distance x cm

func (*Drone) Emergency

func (d *Drone) Emergency() (err error)

Emergency makes Tello stop all motors immediately This cmd doesn't seem to be receiving any response, that's why we don't provide any handler

func (*Drone) Flip

func (d *Drone) Flip(x string) (err error)

Flip makes Tello flip in the specified direction Check out Flip... constants for available flip directions

func (*Drone) Forward

func (d *Drone) Forward(x int) (err error)

Forward makes Tello fly forward with distance x cm

func (*Drone) Go

func (d *Drone) Go(x, y, z, speed int) (err error)

Go makes Tello fly to x y z in speed (cm/s)

func (*Drone) Land

func (d *Drone) Land() (err error)

Land makes Tello auto land

func (*Drone) Left

func (d *Drone) Left(x int) (err error)

Left makes Tello fly left with distance x cm

func (*Drone) On

func (d *Drone) On(name string, h astikit.EventerHandler)

On adds an event handler

func (*Drone) Right

func (d *Drone) Right(x int) (err error)

Right makes Tello fly right with distance x cm

func (*Drone) RotateClockwise

func (d *Drone) RotateClockwise(x int) (err error)

RotateClockwise makes Tello rotate x degree clockwise

func (*Drone) RotateCounterClockwise

func (d *Drone) RotateCounterClockwise(x int) (err error)

RotateCounterClockwise makes Tello rotate x degree counter-clockwise

func (*Drone) SetSpeed

func (d *Drone) SetSpeed(x int) (err error)

SetSpeed sets speed to x cm/s

func (*Drone) SetSticks

func (d *Drone) SetSticks(lr, fb, ud, y int) (err error)

SetSticks sends RC control via four channels All values are between -100 and 100 lr: left/right fb: forward/backward ud: up/down y: yawn This cmd doesn't seem to be receiving any response, that's why we don't provide any handler

func (*Drone) SetWifi

func (d *Drone) SetWifi(ssid, password string) (err error)

SetWifi sets Wi-Fi with SSID password I couldn't make this work (it returned 'error' even though the SSID was changed but the password was not) If anyone manages to make it work, create an issue in github, I'm really interested in how you managed that :D

func (*Drone) Speed

func (d *Drone) Speed() (x int, err error)

Speed returns the current speed (cm/s)

func (*Drone) Start

func (d *Drone) Start() (err error)

Start starts to the drone

func (*Drone) StartVideo

func (d *Drone) StartVideo() (err error)

StartVideo makes Tello start streaming video

func (*Drone) State

func (d *Drone) State() State

State returns the drone's state

func (*Drone) StopVideo

func (d *Drone) StopVideo() (err error)

StopVideo makes Tello stop streaming video

func (*Drone) TakeOff

func (d *Drone) TakeOff() (err error)

TakeOff makes Tello auto takeoff

func (*Drone) Up

func (d *Drone) Up(x int) (err error)

Up makes Tello fly up with distance x cm

func (*Drone) Wifi

func (d *Drone) Wifi() (snr int, err error)

Wifi returns the Wifi SNR

type Speed

type Speed struct {
	X int
	Y int
	Z int
}

Speed represents the drone's speed

type State

type State struct {
	Acceleration       Acceleration // The acceleration
	Attitude           Attitude     // The attitude
	Barometer          float64      // The barometer measurement in cm
	Battery            int          // The percentage of the current battery level
	FlightDistance     int          // The time of flight distance in cm
	FlightTime         int          // The amount of time the motor has been used
	Height             int          // The height in cm
	HighestTemperature int          // The highest temperature in degree Celsius
	LowestTemperature  int          // The lowest temperature in degree Celsius
	Speed              Speed        // The speed
}

State represents the drone's state

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL