[PYTHON] [AWS / Tello] Build a system to operate the drone on the cloud

Introduction

This article Evacuation advisory system using drone This is the first chapter of. Please refer to it for the production background.

Overview

Build a system that can operate the Tello drone on AWS. If you can operate it on AWS, you can link with various services, so let's expand your dreams.

About the drone to use

We will use Tello edu developed by Chinese startup Ryze Tech. The official SDK is being developed by Intel and DJI, and v2 can be used with the edu version, and the drone is a slave unit. It is recommended to purchase the edu version because it is possible to fly in a formation. Since this SDK is used for drone control, git clone it in advance. For basic flight and image streaming methods in Python using the environment construction and SDK, see the SDK User Guide. See 20User% 20Guide.pdf) and another article about Tello.

Flight command

Just give a command as a character string to the argument of the send_command method of the Tello class and it will fly. For reference, the basic flight command is as follows. In addition to these, there are also rotation commands and commands that draw an arc by specifying the speed, so check as appropriate according to how you use it.

Command Description
command Start SDK mode
takeoff take off
land landing
emergency Motor stop immediately
up x 20~Rise between 500 cm
down x 20~Descent between 500 cm
left x 20~Fly to the left between 500 cm
right x 20~Fly to the right between 500 cm
forward x 20~Fly forward between 500 cm
back x 20~Fly back between 500 cm

Communication between Tello <-> PC <-> AWS

In the first place, the Tello drone does not support mobile communication services such as 4G communication, and it is unlikely that it will be operated remotely in actual operation, but it will be useful in the future to control it by using services on the Internet as a trigger. It is considered. In this system, we will use AWS as a cloud service and try to fly the tello from the cloud.

Connection method

When using Tello as a wifi base unit and connecting to a PC via wifi, it is not possible to use a wifi connection to connect to AWS. Therefore, this time, we connected the PC and the smartphone by wire so that the PC and AWS can communicate via the tethering of the smartphone. At this time, the priority of the tethering service used for connecting to the Internet must be higher than that of Wifi. wificonnect.png

Communication protocol with drone

This time, MQTT communication was adopted instead of HTTP communication for communication between AWS and the drone. It is a message protocol that is lighter than HTTP communication, and I thought that MQTT communication would be suitable for sending character string commands (I also wanted to try MQTT lol). MQTT communication is performed by setting a channel in the MQTT broker and subscribing to the published data on that channel. A major feature is that many-to-many communication can be performed easily. (maybe) AWSIoTCore provides MQTT broker, and in this system, the drone publishes the flight command on the subscribe side of the flight command and confirms the flight for the time being. iotcore2tello.png

AWS IoT Core Next, log in to AWS, open IoT Core, and register Drone as a thing.

droneiot.png

Create a certificate, attach a policy, and activate the certificate. This article is overwhelmingly easy to understand for detailed procedures. (Reference URL) I will use the certificate later, so I will definitely download it.

Tello control program

It seems that the Tello SDK is compliant with the python2 system, so I think that the library etc. should be adapted to the 2 system. (Not verified if it works with python3) pip install AWSIoTPythonSDK And put the library for IoT Core from Python. It is OK if you write the following main control program in the directory where the certificate and Tello.py are located (eg Single_Tello_Test).

main.py


# -*- coding:utf8 -*-
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
from datetime import datetime
from tello import Tello
import ast
import time
import json
import sys

# For certificate based connection
myMQTTClient = AWSIoTMQTTClient('device001') #Appropriate value
myMQTTClient.configureEndpoint('xxxxxxxxxxxx.ap-northeast-1.amazonaws.com', 8883) #Check on the management screen
myMQTTClient.configureCredentials('rootCA.pem', 'xxxxx-private.pem.key', 'xxxxx-certificate.pem.crt') #Various certificates
myMQTTClient.configureOfflinePublishQueueing(-1) # Infinite offline Publish queueing
myMQTTClient.configureDrainingFrequency(2) # Draining: 2 Hz
myMQTTClient.configureConnectDisconnectTimeout(10) # 10 sec
myMQTTClient.configureMQTTOperationTimeout(5) # 5 sec
myMQTTClient.connect()

tello = Tello() #Create a Tello instance
tello.send_command('command') #Start SDK mode

def customCallback(client, userdata, message):
    payload = message.payload
    print('Received a new message: ')
    print(payload)
    print('from topic: ')
    print(message.topic)
    print('--------------\n\n')
    # command = payload[0]
    dic = ast.literal_eval(payload)
    tello.send_command(dic['message'])

myMQTTClient.subscribe("test/pub", 1, customCallback) # test/Subscribe to pub channel
while True:
    time.sleep(1)

test

Yes, I will test it. First, execute the above Python code to check the connection with Tello. Next, open the test tab on IoT Core, specify the channel, specify the flight command as a character string in the value of "message", and issue it to the topic. takeoff.png

It is easy to understand, and the operation is summarized in the video. https://youtu.be/MKF2P_rrS9U IMAGE ALT TEXT HERE

Summary

I entered a command from AWS IoT Core and succeeded in flying Tello. Next, let's link with an external service. [AWS / Tello] I tried to operate the drone with voice Part1

Recommended Posts

[AWS / Tello] Build a system to operate the drone on the cloud
Build a WardPress environment on AWS with pulumi
Build a cheap summarization system with AWS components
A record of the time it took to deploy mysql on Cloud9 + Rails
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
How to deploy a Django application on Alibaba Cloud
Make a parrot return LINE Bot on AWS Cloud9
It was a life I wanted to OCR on AWS Lambda to locate the characters.
How to build a Python environment on amazon linux 2
How to build a new python virtual environment on Ubuntu
[Introduction to AWS] A memorandum of building a web server on AWS
I tried to launch ipython cluster to the minimum on AWS
I tried to build a SATA software RAID configuration that boots the OS on Ubuntu Server
[AWS] What to do when the ping command causes a "timeout"
[AWS / Tello] I tried operating the drone with my voice Part2
A note on how to check the connection to the license server port
Build a Selenium environment on Amazon Linux 2 in the shortest time
Build a game leaderboard on Alibaba cloud using Python and Redis
Build a Flask / Bottle-like web application on AWS Lambda with Chalice
How easy is it to synthesize a drug on the market?
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
I just wrote a script to build Android on another machine
The simplest way to build a Spleeter usage environment using Windows
I want to create a system to prevent forgetting to tighten the key 1
I tried to register a station on the IoT platform "Rimotte"
[AWS / Tello] I tried operating the drone with my voice Part1
Write a script to calculate the distance with Elasticsearch 5 system painless
A command to easily check the speed of the network on the console
How to deploy a web application on Alibaba Cloud as a freelancer
How to update the python version of Cloud Shell on GCP
Building an environment to run ChainerMN on a GPU instance on AWS
Create a REST API to operate dynamodb with the Django REST Framework
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)
Start data science on the cloud
Build a python3 environment on CentOS7
Work memo to migrate and update Python 2 series scripts on the cloud to 3 series
Build your Django app on Docker and deploy it to AWS Fargate
I made a kitchen timer to be displayed on the status bar!
Semi-automatically generate a description of the package to be registered on PyPI
I tried to draw a system configuration diagram with Diagrams on Docker
How to set up a jupyter notebook on ssh destination (AWS EC2)
June 2017 version to build Tensorflow / Keras environment on GPU instance of AWS
Build a "Deep learning from scratch" learning environment on Cloud9 (jupyter miniconda python3)
How to build an application from the cloud using the Django web framework
Build Linux on a Windows environment. Steps to install Laradock and migrate
Try to build a pipeline to store the result in Bigquery by hitting the Youtube API regularly using Cloud Composer