record_log.py
Go to the documentation of this file.
1 from time import sleep
2 import tellopy
3 import datetime
4 import os
5 
6 file = None
7 write_header = True
8 
9 def handler(event, sender, data, **args):
10  global file
11  global write_header
12  drone = sender
13  if event is drone.EVENT_LOG_DATA:
14  if file == None:
15  path = '%s/Desktop/tello-%s.csv' % (
16  os.getenv('HOME'),
17  datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S'))
18  file = open(path, 'w')
19  if write_header:
20  file.write('%s\n' % data.format_cvs_header())
21  write_header = False
22  file.write('%s\n' % data.format_cvs())
23  if event is drone.EVENT_FLIGHT_DATA or event is drone.EVENT_LOG_DATA:
24  print('record_log: %s: %s' % (event.name, str(data)))
25 
26 def test():
27  drone = tellopy.Tello()
28  try:
29  drone.subscribe(drone.EVENT_FLIGHT_DATA, handler)
30  drone.subscribe(drone.EVENT_LOG_DATA, handler)
31  drone.record_log_data()
32 
33  drone.connect()
34  drone.wait_for_connection(60.0)
35  drone.takeoff()
36  sleep(5)
37  drone.clockwise(100)
38  sleep(5)
39  drone.clockwise(0)
40  drone.down(50)
41  sleep(2)
42  drone.up(50)
43  sleep(2)
44  drone.up(0)
45  drone.land()
46  sleep(5)
47  except Exception as ex:
48  print(ex)
49  finally:
50  drone.quit()
51 
52 if __name__ == '__main__':
53  test()
def handler(event, sender, data, args)
Definition: record_log.py:9


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