Pythonのインストール

まずはじめに、PythonをWindows10にインストールします。Anaconda 2019.03 for Windows Installer Python 3.7 versionをダウンロードしてインストールします。

# Pythonのバージョンを確認
python --version

Telloとの接続

次に、Telloとの接続を行います。Telloの電源を入れ、パソコンのWi-Fi設定から「TELLO-XXXXX」を選択します。

Telloのプログラミング

Telloをプログラミングするためには、tellopyというライブラリをインストールします。

# tellopyのインストール
pip install tellopy

Telloを制御するための基本的なコードは以下の通りです。

import socket
import time

# Create a UDP socket
socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tello_address = ('192.168.10.1', 8889)

# Send command to Tello
socket.sendto('command'.encode('utf-8'), tello_address)
print('start')

# Take off
socket.sendto('takeoff'.encode('utf-8'), tello_address)
print('takeoff')
time.sleep(5)

# Move forward
socket.sendto('forward 200'.encode('utf-8'), tello_address)
time.sleep(5)

# Move right
socket.sendto('right 100'.encode('utf-8'), tello_address)
time.sleep(5)

# Move back
socket.sendto('back 200'.encode('utf-8'), tello_address)
time.sleep(5)

# Move left
socket.sendto('left 100'.encode('utf-8'), tello_address)
time.sleep(5)

# Land
socket.sendto('land'.encode('utf-8'), tello_address)

このコードを実行すると、Telloは離陸し、前進、右移動、後退、左移動を行った後、着陸します。

以上が、Windows上でPythonを使用してTelloドローンをプログラミングする基本的な手順です。さらに詳細な情報や、他の操作方法については、公式のTello SDKをご覧ください。.

投稿者 admin

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です