Code Monkey home page Code Monkey logo

tellodrone's Introduction

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.

tellodrone's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

utsingh

tellodrone's Issues

takkeOff method

Hi, in the documentation you have written takkeof() method but is badly written it throws an error (Tello.takeoff is not a function), you need to change documentation for takeOf().

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.