Getting Started with Ryze Tello Matlab Control

Description

This version {1.0} toolbox provides an API for connecting with the ryze tello drone and streaming and visualizing in real time the drone's state variables that the user specifies with the API. The data collected can be used for system identification or modelling of the drone's dynamic behaviour. For example, a dynamic altitude model can be derived using matlab's system identification toolbox with altitude data collected from the ryze tello drone using the API.
For more information on the Drone's state variables and the Tello's SDK see, Ryze Tello SDK
This Toolbox makes use of 2 primary classes.
The TelloControl class rovides functions for connecting to the Ryze Tello Drone over WIFI using the UDP protocol, initializing the onboard SDK and a primary function, cmdTello(str:<cmd>), for sending control commands over UDP to the drone. See Ryze Tello SDK for more information on the acceptable commands. This class can be used independently.
This is the typical process for observing and collecting data.

Initialize Ryze Tello Controller

Before the controller is initialized, it is important to clear all workspace variables and close all pre-existing figures as this may interfere with the proper starting of the script.
clear;clc;close all;
tc = TelloControl
tc =
TelloControl with properties: telloSDKPort: 8889 telloDroneStatePort: 8890 telloIP: '192.168.10.1' localhost: '0.0.0.0' telloSDKClient: [1×1 udpport.byte.UDPPort] telloStateClient: [1×1 udpport.byte.UDPPort] telloCameraClient: [1×1 udpport.byte.UDPPort] telloCameraPort: 11111 telloState: {}

Initialize the Drone's onboard SDK

Run this to initialize the Tello's onboard SDK to allow the controller to interact with the drone.
tc.initTello();
Pass the controller 'tc' to the TelloStateObserver class. See this implemented in the example below.
The TelloStateObserver provides a way of observing the state variables and visualizing them in real time on a live matlab plot while accepting vertical mouse or trackpad motion
as control input for altitude control while the selected states are observed and collected.
The class is used as follows. Call the class by passing the following arguments. The controller 'tc' is the ony required positionial argument. The follwoing are optional named arguments that can be passed in addition. Pass them like regular matlab named arguments.
observers <cell{string}> : Cell of strings. These are those state variables you ony wish to observe and visualize in real time but not save or collect.
collectors <cell{string}>: Cell of strings. Like observers, and wish to save after running script.
limitAltitude <double> : Impose an approximate altitude limit
n_samples <double> : Number of samples to observe or run script for after which the controller issues a commanad to land the drone.
Example usage:
tso = TelloStateObserver(tc,"observers",{'h'},'collectors',{'h','vgz','agz'},limitAltitude=20,n_samples=100);

Typical Example

This example connects to the Ryze Tello Drone over WIFI and observes in real time the selected state variables. Recommended not to run in a live script. Recommended in a default .m script. Check example script 'tello_altitude_rc.m'
clear;clc;close all; %clear and close all workspace variables and pre-existing figures resp.
tc = TelloControl; %initialize controller
tc.initTello(); %initialize onboard tello sdk
initializing RYZE TELLO SDK... ok: SDK initialization successful on IP: 192.168.10.1 at PORT: 8889
tc.getTelloState() %get and display initial states of drone - returns struct class wtih state variables as fieldnames
ans = struct with fields:
pitch: 0 roll: 0 yaw: 0 vgx: 0 vgy: 0 vgz: 0 templ: 86 temph: 88 tof: 10 h: 0 bat: 70 baro: 367.3100 time: 2 agx: -1 agy: 10 agz: -998
Pass the controller 'tc' to the TelloStateObserver class<required> and initial the TelloStateObserver class with chosen arguments<optional>. collectors, observers, n_samples and limitAltitude. Obsercers can be equal to collectors.
tso = TelloStateObserver(tc,"observers",{'h'},'collectors',{'h','vgz','agz'},limitAltitude=20,n_samples=100);
[collected,observed,input] = tso.stateObserve(); %run observer to collect and visualize state variables in real time
Elapsed time is 0.270265 seconds. Elapsed time is 0.105773 seconds. Elapsed time is 0.067918 seconds. Elapsed time is 0.068840 seconds. Elapsed time is 0.062585 seconds. Elapsed time is 0.066994 seconds. Elapsed time is 0.074158 seconds. Elapsed time is 0.067694 seconds. Elapsed time is 0.065518 seconds. Elapsed time is 0.051031 seconds. Elapsed time is 0.058599 seconds. Elapsed time is 0.057226 seconds. Elapsed time is 0.068552 seconds. Elapsed time is 0.058250 seconds. Elapsed time is 0.061569 seconds. Elapsed time is 0.058554 seconds. Elapsed time is 0.056528 seconds. Elapsed time is 0.064614 seconds. Elapsed time is 0.067957 seconds. Elapsed time is 0.054463 seconds. Elapsed time is 0.057262 seconds. Elapsed time is 0.059793 seconds. Elapsed time is 0.072292 seconds. Elapsed time is 0.064865 seconds. Elapsed time is 0.058317 seconds. Elapsed time is 0.058485 seconds. Elapsed time is 0.056468 seconds. Elapsed time is 0.063984 seconds. Elapsed time is 0.064587 seconds. Elapsed time is 0.068156 seconds. Elapsed time is 0.065154 seconds. Elapsed time is 0.058896 seconds. Elapsed time is 0.056186 seconds. Elapsed time is 0.059901 seconds. Elapsed time is 0.074092 seconds. Elapsed time is 0.063520 seconds. Elapsed time is 0.057687 seconds. Elapsed time is 0.053665 seconds. Elapsed time is 0.060038 seconds. Elapsed time is 0.071205 seconds. Elapsed time is 0.059122 seconds. Elapsed time is 0.054079 seconds. Elapsed time is 0.055150 seconds. Elapsed time is 0.059327 seconds. Elapsed time is 0.070332 seconds. Elapsed time is 0.105346 seconds. Elapsed time is 0.103402 seconds. Elapsed time is 0.114811 seconds. Elapsed time is 0.101441 seconds. Elapsed time is 0.095323 seconds. Elapsed time is 0.093262 seconds. Elapsed time is 0.099958 seconds. Elapsed time is 0.103101 seconds. Elapsed time is 0.098161 seconds. Elapsed time is 0.102516 seconds. Elapsed time is 0.104880 seconds. Elapsed time is 0.102579 seconds. Elapsed time is 0.138179 seconds. Elapsed time is 0.060512 seconds. Elapsed time is 0.104358 seconds. Elapsed time is 0.107169 seconds. Elapsed time is 0.092557 seconds. Elapsed time is 0.107957 seconds. Elapsed time is 0.107147 seconds. Elapsed time is 0.094937 seconds. Elapsed time is 0.102760 seconds. Elapsed time is 0.114103 seconds. Elapsed time is 0.091744 seconds. Elapsed time is 0.098859 seconds. Elapsed time is 0.101793 seconds. Elapsed time is 0.101825 seconds. Elapsed time is 0.097237 seconds. Elapsed time is 0.107317 seconds. Elapsed time is 0.063753 seconds. Elapsed time is 0.090266 seconds. Elapsed time is 0.105009 seconds. Elapsed time is 0.092363 seconds. Elapsed time is 0.101509 seconds. Elapsed time is 0.101389 seconds. Elapsed time is 0.104930 seconds. Elapsed time is 0.099020 seconds. Elapsed time is 0.099682 seconds. Elapsed time is 0.101234 seconds. Elapsed time is 0.102297 seconds. Elapsed time is 0.114636 seconds. Elapsed time is 0.099160 seconds. Elapsed time is 0.091921 seconds. Elapsed time is 0.109492 seconds. Elapsed time is 0.110450 seconds. Elapsed time is 0.093097 seconds. Elapsed time is 0.103553 seconds. Elapsed time is 0.106467 seconds. Elapsed time is 0.097351 seconds. Elapsed time is 0.117624 seconds. Elapsed time is 0.091527 seconds. Elapsed time is 0.097400 seconds. Elapsed time is 0.110437 seconds. Elapsed time is 0.086358 seconds. Elapsed time is 0.103689 seconds.
Elapsed time is 0.099874 seconds.
%post process collected states and save
disp('saving state collected state variables and input...')
saving state collected state variables and input...
telloStateData = {};
telloStateData.states = collected;
telloStateData.input = input;
save('tellosStateData.mat','telloStateData')