Tello と scratch を python で接続 (tello video 表示付き)

はじめに

できること (windows10 pro 64bit)
  • Scratch でプログラムして Tello を飛ばす。
  • Tello State を scratch 画面に表示。
  • video を表示。

f:id:shimauma3san:20200416194030j:plain

問題
  • Scratch のプログラム通り、テキパキ動く(飛ぶ)とは言えない。
  • Tello の現在位置取得は出来ていない。
    注意:ここで使う Tello は、Tello EDU ではない。
動作している時のPC画面の映像

tello は、離陸、100cm up、180度回転、180度回転、着陸する。
PC画面下が、scratch_if.py を起動した、windows 10 powershell 画面。
右が scratch 2.0 Offline Editor 画面。 www.dropbox.com

scratch_if.py の プログラム概要説明

python 3 と opencv-python で動作。
scratch_if.py のコードは、 https://github.com/uma3san/tello_scratch_if

主に4つの thread で構成
  • Tello に Commandを送る thread
  • Tello State 受信 thread
  • Scrath と通信する HTTP server thread
  • Tello Video Stream 受信と表示は main thread
tello と scratch と scrach_if.py の関係

f:id:shimauma3san:20200414114230j:plain

tello_scratch_if.py を動かす

  1. Tello を起動。
  2. PC の Wifi を、「TELLO-xxxxx」 につなぐ。
  3. scratch 2.0 Offline Editor を起動。
  4. scratch 2.0 Offline Editor で Tello.s2e を読み込む。
    Shift キーを押しながら、「ファイル」メニューをクリックし、「実験的なHTTP拡張を読み込み」をクリック。
  5. scratch 2.0 Offline Editor で、demo_flight.sb2 (scratch) を読み込む。
  6. tello_scratch_if.py の起動。
    python tello_scratch_if.py」 と起動すると、大量の cv2 の log が表示されるので、 「python tello_scratch_if.py 2> log.file 」と起動する。
  7. プログラムの終了は、powershell 画面で "quit" を入力するか、video 画面にカーソルを置いて、 "q" を入力する。 (終了処理は上手に書けていない。タスクマネージャにお世話になる時もある。)
windows 10 powershell の表示

-> try to connect the tello(b'ok', ('192.168.10.1', 8889))
-> connected : set tello to command mode
-> command ... ok 192.168.10.1 8889
-> streamon ... ok 192.168.10.1 8889
と出て、しばらくすると video が表示される。

scratch 2.0 Offline Editor の takeoff の上の旗のを押すと、離陸して、着陸。
Keyboard の スペースキーを押すと、緊急着陸(墜落)。
(安定しない時は、部屋を明るくする。)

PC環境

項目
OS windows 10 pro 64bit
CPU Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Memory 16GHz
conda 4.8.2 (installed Anaconda3-2019.10-Windows-x86_64.exe)
python 3.7.4.final.0
opencv-python 4.2.0

その他

Tello アプリで、スマートフォンXperia XZ Premium SO-04J) で Tello を飛行させる
  1. Tello アプリをインストール
  2. Xperia と Tello を Wifi接続
  3. Xperia の電波を止める(機内モードにする)
  4. Wifi を active にする
  5. Tello アプリを起動
  6. 接続ボタンを押す
    「接続されました」と出ると成功。
Tips
  • 安定飛行させるには明るくする。
  • takeoff 後静止することを安定とすると、不安定な動作とは、 takeoff 後水平方向の決まった方向に流れるようなことをいう。
メーカ(Ryze Tech)から提供された資料
参考資料
  1. イドローン Tello を Scratch でプログラムする。
    http://blog.a-way-out.net/blog/2019/04/22/program-drone-tello-with-scratch/
    node.js で scratch と tello の接続や、Scratch 2.0 Offline Editor のインストールも書かれている。 この記事で使っているのは、Scratch 2.0 Offline Editorと tello.s2e 。

  2. ドローン「Tello」を使った動画のストリーム表示が出来ません!
    https://teratail.com/questions/182458
    簡単明瞭で良い。

  3. Ryze Tech の Github サイト https://github.com/dji-sdk/Tello-Python
    python 2

  4. DJI Tello drone controller python package
    https://github.com/hanyazou/TelloPy