Skip to content

eliabiraschi/TelloDrone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TelloDrone (Yet Another Tello SDK Wrapper)

A NodeJS wrapper for the Ryze Tello SDK 1.3.

Motivation

I did not find a library I liked, so I made mine.

Features

  • Easy set up and minimal boilerplate.
  • All the SDK commands are available and return a promise.
  • Telemetry is broadcasted as a stringified object.
  • Video buffer is broadcasted too and ready to use.
  • Built in method for taking pictures (experimental).

Installation and basic use

Install with npm:

npm install --save yatsw

The library exports a single class:

const { TelloDrone } = require('yatsw')

Create a new instance:

const Tello = new TelloDrone()

Fly:

Tello.start()
Tello.takeOff()
Tello.forward(100)
Tello.yawCW(360)
Tello.land()

Fly better:

async function roll() {
  Tello.start()
  Tello.takeOff()
  Tello.forward(100)
  const height = await Tello.getHeight()
  console.log(height)
  Tello.yawCW(360)
  Tello.up(150)
  const r = await Tello.takePicture('./img.jpg')
  console.log(r)
  Tello.land()
}
roll()

Events

You can listen to the messages from the aircraft through the MESSAGE event:

Tello.on(Tello.events.MESSAGE, data => {
	console.log(data)
})

These would be the same results you would get when the single promises of the command methods resolve.

Telemetry data can be reached in the same fashion:

Tello.on(Tello.events.STATE, data => {
	console.log(JSON.parse(data))
})

In the same way you can consume the video stream (the below example is for Linux)

const { spawn } = require('child_process')
const { TelloDrone } = require('./src/TelloDrone')
const videoPlayer = spawn('mplayer', ['-fps', '35', '-'])
const Tello = new TelloDrone('myTello')
Tello.on(Tello.events.VIDEO, data => videoPlayer.stdin.write(data))
Tello.start()
Tello.streamOn()

NOTE

Don't forget to connect to the Tello WiFi before running any related script.

The TelloDrone class

The TelloDrone class constructor accepts 3 arguments, all of them are optionals.

  1. A string used as id to identify the class itself;
  2. An object for specifying non default values to connect to the aircraft. A partial object is ok too and the missing values will be filled by the defaults.
{
  AIRCRAFT_PORT: 8889,
  STATUS_PORT: 8890,
  VIDEO_PORT: 11111,
  HOST: '192.168.10.1',
}
  1. An array of objects describing the methods names and the commands to send to the aircraft. Please check the source code if you're interested in working with this.

List of the public methods

The public methods reflect the commands you can send to the aircraft. I've only changed a couple of them for clarity. The returned values and/or arguments are those described in the official SDK documentation. Each one of them returns a promise. The promises both resolve and reject with an object: resolve({ message }) or reject({ error: message || error }).

  • start() puts the aircraft in SDK mode, it has to be called prior to any other command
  • panic() stops all the rotors (emergency command)
  • getHeight()
  • getBattery()
  • getTime()
  • getSpeed()
  • getWiFi()
  • getTemp()
  • getAttitude()
  • getBaro()
  • getAcceleration()
  • getTOF()
  • setSpeed(value)
  • takeOff()
  • land()
  • emergencyLand() it will send the land command with higher priority and skip all those commands queued
  • up(value)
  • down(value)
  • left(value)
  • right(value)
  • forward(value)
  • back(value)
  • yawCW(value) the actual command sent is cw value
  • yawCCW(value) the actual command sent is ccw value
  • flip(value)
  • flyTo(valueX, valueY, valueZ, speed) the actual command sent is go valueX valueY valueZ speed
  • curve(valueX, valueY, valueZ, valueX2, valueY2, valueZ2, speed)
  • fourChannel(chA, chB, chC, chD) the actual command sent is rc chA chB chC chD

NOTE: the command for setting the WiFi is intentionally missing.

In addition there are 3 more commands that are different for some reasons:

  • streamOn() it starts the stream video and set up a ticker to keep the video alive
  • streamOff() stops the video and kill the ticker
  • takePicture(path = '-') it takes a picture using ffmpeg. If a path is provided the image is saved there otherwise the returned promise will resolve an object that will have a buffer field for the image data. In case you trigger the picture without starting the video stream first, the promise will still resolve, but it will return a warning. NOTE: Windows is not supported yet, but OSX might just work if you have ffmpeg installed.

Known issues

  • Taking a picture without for getting the buffer is still buggy and might not work at all.