test.py
Go to the documentation of this file.
1 from time import sleep
2 import tellopy
3 from tellopy._internal.utils import *
4 
5 prev_flight_data = None
6 
7 
8 def handler(event, sender, data, **args):
9  global prev_flight_data
10  drone = sender
11  if event is drone.EVENT_CONNECTED:
12  print('connected')
13  drone.start_video()
14  drone.set_exposure(0)
15  drone.set_video_encoder_rate(4)
16  elif event is drone.EVENT_FLIGHT_DATA:
17  if prev_flight_data != str(data):
18  print(data)
19  prev_flight_data = str(data)
20  elif event is drone.EVENT_TIME:
21  print('event="%s" data=%d' % (event.getname(), data[0] + data[1] << 8))
22  elif event is drone.EVENT_VIDEO_FRAME:
23  pass
24  else:
25  print('event="%s" data=%s' % (event.getname(), str(data)))
26 
27 
28 def test():
29  drone = tellopy.Tello()
30  try:
31  # drone.set_loglevel(d.LOG_ALL)
32  drone.subscribe(drone.EVENT_CONNECTED, handler)
33  # drone.subscribe(drone.EVENT_WIFI, handler)
34  # drone.subscribe(drone.EVENT_LIGHT, handler)
35  drone.subscribe(drone.EVENT_FLIGHT_DATA, handler)
36  # drone.subscribe(drone.EVENT_LOG, handler)
37  drone.subscribe(drone.EVENT_TIME, handler)
38  drone.subscribe(drone.EVENT_VIDEO_FRAME, handler)
39 
40  drone.connect()
41  # drone.takeoff()
42  # time.sleep(5)
43  drone.down(50)
44  sleep(3)
45  drone.up(50)
46  sleep(3)
47  drone.down(0)
48  sleep(2)
49  drone.land()
50  sleep(5)
51  except Exception as ex:
52  print(ex)
53  show_exception(ex)
54  finally:
55  drone.quit()
56  print('end.')
57 
58 if __name__ == '__main__':
59  test()
def test()
Definition: test.py:28
def handler(event, sender, data, args)
Definition: test.py:8
def show_exception(ex)
Definition: utils.py:35


tello_driver
Author(s): Jordy van Appeven
autogenerated on Wed May 13 2020 03:34:54