Skip to content

Instantly share code, notes, and snippets.

@microlinux
Last active August 27, 2018 01:56
Show Gist options
  • Save microlinux/5e993f524578a01f941a4a19f41bd695 to your computer and use it in GitHub Desktop.
Save microlinux/5e993f524578a01f941a4a19f41bd695 to your computer and use it in GitHub Desktop.
Tello Advanced Remote Drone Interface System (TARDIS)
#!/usr/bin/env python
# This program requires the Python Tello module at https://github.com/microlinux/tello
import argparse
import curses
import tello # https://github.com/microlinux/tello
import time
import traceback
TITLE = 1
HELP = 2
def main(screen, drone):
command_history = [('', ''), ]
running = True
curses.echo()
curses.init_pair(TITLE, curses.COLOR_WHITE, curses.COLOR_RED)
curses.init_pair(HELP, curses.COLOR_BLACK, curses.COLOR_WHITE)
screen.clear()
screen.refresh()
while running is True:
screen.clear()
screen.addstr(1, 40, ' Available commands ', curses.color_pair(HELP))
screen.addstr(3, 40, 'forward <distance>')
screen.addstr(4, 40, 'back <distance>')
screen.addstr(5, 40, 'up <distance>')
screen.addstr(6, 40, 'down <distance>')
screen.addstr(7, 40, 'left <distance>')
screen.addstr(8, 40, 'right <distance>')
screen.addstr(9, 40, 'cw <degrees>')
screen.addstr(10, 40, 'ccw <degrees>')
screen.addstr(11, 40, 'speed <speed>')
screen.addstr(12, 40, 'flip <direction>')
screen.addstr(13, 40, 'takeoff')
screen.addstr(14, 40, 'land')
screen.addstr(15, 40, 'speed?')
screen.addstr(16, 40, 'battery?')
screen.addstr(17, 40, 'time?')
screen.addstr(18, 40, 'quit')
screen.addstr(1, 1, ' TARDIS Flight Console ', curses.color_pair(TITLE))
screen.addstr(3, 1, 'Last command .....')
screen.addstr(3, 20, command_history[-1][0])
screen.addstr(4, 1, 'Tello response ...')
screen.addstr(4, 20, command_history[-1][1])
screen.addstr(6, 1, 'Command: ')
input = screen.getstr(6, 10, 16)
try:
command, param = input.split()
try:
param = float(param)
except:
pass
except:
command = input
try:
if command == 'forward':
response = drone.move_forward(param)
elif command == 'back':
response = drone.move_backward(param)
elif command == 'right':
response = drone.move_right(param)
elif command == 'left':
response = drone.move_left(param)
elif command == 'up':
response = drone.move_up(param)
elif command == 'down':
response = drone.move_down(param)
elif command == 'cw':
response = drone.rotate_cw(param)
elif command == 'ccw':
response = drone.rotate_ccw(param)
elif command == 'speed':
response = drone.set_speed(param)
elif command == 'flip':
response = drone.flip(param)
elif command == 'takeoff':
response = drone.takeoff()
elif command == 'land':
response = drone.land()
elif command == 'speed?':
response = drone.get_speed()
elif command == 'battery?':
response = drone.get_battery()
elif command == 'time?':
response = drone.get_flight_time()
elif command == 'quit' or command == 'exit':
running = False
continue
else:
continue
except RuntimeError:
command_history.append((input, 'none'))
continue
command_history.append((input, response))
"""Main program."""
try:
imperial = True
parser = argparse.ArgumentParser(description='Tello Advanced Remote Drone Interface System (TARDIS)')
parser.add_argument('-m', '--metric', action='store_true', help='Use metric (meters/KPH) instead of imperial (feet/MPH)')
parser.add_argument('local_ip', nargs='?', default='192.168.10.2', help='Local IP to bind (192.168.10.2)')
parser.add_argument('local_port', nargs='?', default=8887, type=int, help='Local port to bind (8887)')
args = parser.parse_args()
if args.metric is True:
imperial=False
drone = tello.Tello(args.local_ip, args.local_port, imperial)
except Exception as e:
print 'Unable to connect to Tello: %s' % e
exit(1)
curses.wrapper(main, *[drone, ])
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment