diff options
author | px4dev <px4@purgatory.org> | 2012-08-04 15:12:36 -0700 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-08-04 15:12:36 -0700 |
commit | 8a365179eafdf3aea98e60ab9f5882b200d4c759 (patch) | |
tree | 4f38d6d4cd80bd0b6e22e2bb534c3f117ce44e56 /mavlink/share/pyshared/pymavlink/examples/flighttime.py | |
download | px4-firmware-8a365179eafdf3aea98e60ab9f5882b200d4c759.tar.gz px4-firmware-8a365179eafdf3aea98e60ab9f5882b200d4c759.tar.bz2 px4-firmware-8a365179eafdf3aea98e60ab9f5882b200d4c759.zip |
Fresh import of the PX4 firmware sources.
Diffstat (limited to 'mavlink/share/pyshared/pymavlink/examples/flighttime.py')
-rw-r--r-- | mavlink/share/pyshared/pymavlink/examples/flighttime.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/mavlink/share/pyshared/pymavlink/examples/flighttime.py b/mavlink/share/pyshared/pymavlink/examples/flighttime.py new file mode 100644 index 000000000..81cd38c94 --- /dev/null +++ b/mavlink/share/pyshared/pymavlink/examples/flighttime.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +''' +work out total flight time for a mavlink log +''' + +import sys, time, os + +# allow import from the parent directory, where mavlink.py is +sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) + +from optparse import OptionParser +parser = OptionParser("flighttime.py [options]") +parser.add_option("--mav10", action='store_true', default=False, help="Use MAVLink protocol 1.0") + +(opts, args) = parser.parse_args() + +if opts.mav10: + os.environ['MAVLINK10'] = '1' +import mavutil + +if len(args) < 1: + print("Usage: flighttime.py [options] <LOGFILE...>") + sys.exit(1) + +def flight_time(logfile): + '''work out flight time for a log file''' + print("Processing log %s" % filename) + mlog = mavutil.mavlink_connection(filename) + + in_air = False + start_time = 0.0 + total_time = 0.0 + t = None + + while True: + m = mlog.recv_match(type='VFR_HUD') + if m is None: + if in_air: + total_time += time.mktime(t) - start_time + if total_time > 0: + print("Flight time : %u:%02u" % (int(total_time)/60, int(total_time)%60)) + return total_time + t = time.localtime(m._timestamp) + if m.groundspeed > 3.0 and not in_air: + print("In air at %s" % time.asctime(t)) + in_air = True + start_time = time.mktime(t) + elif m.groundspeed < 3.0 and in_air: + print("On ground at %s" % time.asctime(t)) + in_air = False + total_time += time.mktime(t) - start_time + return total_time + +total = 0.0 +for filename in args: + total += flight_time(filename) + +print("Total time in air: %u:%02u" % (int(total)/60, int(total)%60)) |