import socket import time tello = ("192.168.10.1", 8889) def init_drone(): # create upd client on PC try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error as err: print(err) exit() try: # send control commands to the drone s.sendto('command', tello) time.sleep(5) except socket.error as err: print(err) return s def takeoff(s): s.sendto('takeoff', tello) time.sleep(10) def rotate90(s): s.sendto('cw 90', tello) time.sleep(10) def flip_left(s): s.sendto('flip l', tello) time.sleep(10) def land(s): s.sendto('land', tello) time.sleep(5) def main(): s = init_drone() takeoff(s) rotate90(s) flip_left(s) land(s) if __name__ == '__main__': main()
import socket import time tello = ("192.168.10.1", 8889) def init_drone(): # create upd client on PC try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error as err: print(err) exit() try: # send control commands to the drone s.sendto('command', tello) time.sleep(5) except socket.error as err: print(err) return s def info(s): speed = s.sendto('speed?', tello) battery = s.sendto('battery?', tello) time = s.sendto('time?', tello) height = s.sendto('height?', tello) print('-----------Informaiton------------') print('Speed: %f cm/s' % float(speed)) print('Battery: %f %%' % float(battery)) print('Time: %f' % float(time)) print('Height: %f' % float(height)) def takeoff(s): s.sendto('takeoff', tello) time.sleep(10) def land(s): s.sendto('land', tello) time.sleep(5) def main(): s = init_drone() takeoff(s) info(s) land(s) if __name__ == '__main__': main()