This article Evacuation advisory system using drone This is the first chapter of. Please refer to it for the production background.
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.
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.
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 |
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.
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.
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.
AWS IoT Core Next, log in to AWS, open IoT Core, and register Drone as a thing.
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.
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)
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.
It is easy to understand, and the operation is summarized in the video. https://youtu.be/MKF2P_rrS9U
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