4 show changes in flight modes 6 from __future__
import print_function
12 from argparse
import ArgumentParser
13 parser = ArgumentParser(description=__doc__)
14 parser.add_argument(
"logs", metavar=
"LOG", nargs=
"+")
16 args = parser.parse_args()
18 from pymavlink
import mavutil
22 '''show flight modes for a log file''' 23 print(
"Processing log %s" % filename)
24 mlog = mavutil.mavlink_connection(filename)
28 mode_start_timestamp = -1
31 seconds_per_percent = -1
33 filesize = os.path.getsize(filename)
36 m = mlog.recv_match(type=[
'SYS_STATUS',
'HEARTBEAT',
'MODE'],
37 condition=
'MAV.flightmode!="%s"' % mlog.flightmode)
40 print(
'%s MAV.flightmode=%-12s (MAV.timestamp=%u %u%%)' % (
41 time.asctime(time.localtime(m._timestamp)),
43 m._timestamp, mlog.percent))
45 mode = mlog.flightmode
46 if (mode
not in time_in_mode):
47 time_in_mode[mode] = 0
49 if (mode_start_timestamp == -1):
50 mode_start_timestamp = m._timestamp
51 elif (previous_mode !=
"" and previous_mode != mode):
52 time_in_mode[previous_mode] = time_in_mode[previous_mode] + (m._timestamp - mode_start_timestamp)
56 if (seconds_per_percent == -1
and previous_percent != -1
57 and previous_percent != mlog.percent):
58 seconds_per_percent = (m._timestamp - mode_start_timestamp) / (mlog.percent - previous_percent)
60 mode_start_timestamp = m._timestamp
63 previous_percent = mlog.percent
67 print(
"Time per mode:")
70 if (seconds_per_percent != -1):
71 seconds_remaining = (100.0 - previous_percent) * seconds_per_percent
73 time_in_mode[previous_mode] = time_in_mode[previous_mode] + seconds_remaining
76 for key, value
in time_in_mode.items():
77 total_flight_time = total_flight_time + value
79 for key, value
in time_in_mode.items():
80 print(
'%-12s %s %.2f%%' % (key,
str(datetime.timedelta(seconds=
int(value))), (value / total_flight_time) * 100.0))
83 print(previous_mode,
" 100% of flight time")
85 for filename
in args.logs: