2022-01-24 08:50:04 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Parses a log file and shows how the solution status changed over time
|
|
|
|
|
|
|
|
AP_FLAKE8_CLEAN
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import optparse
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from pymavlink import mavutil
|
|
|
|
|
|
|
|
|
|
|
|
class SolutionStatusChange(object):
|
2024-10-19 22:53:41 -03:00
|
|
|
def __init__(self, master, core=None):
|
2022-01-24 08:50:04 -04:00
|
|
|
self.master = master
|
2024-10-19 22:53:41 -03:00
|
|
|
self.core = core
|
|
|
|
if self.core is not None:
|
|
|
|
self.core = set(self.core)
|
2022-01-24 08:50:04 -04:00
|
|
|
|
|
|
|
def progress(self, text):
|
|
|
|
'''emit text with possible timestamps etc'''
|
|
|
|
print("%u: %s" % (time.time(), text))
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
|
|
|
self.progress("Creating connection")
|
|
|
|
self.conn = mavutil.mavlink_connection(master)
|
|
|
|
|
|
|
|
bit_descriptions = {
|
|
|
|
"attitude": 0,
|
|
|
|
"horiz_vel": 1,
|
|
|
|
"vert_vel": 2,
|
|
|
|
"horiz_pos_rel": 3,
|
|
|
|
"horiz_pos_abs": 4,
|
|
|
|
"vert_pos": 5,
|
|
|
|
"terrain_alt": 6,
|
|
|
|
"const_pos_mode": 7,
|
|
|
|
"pred_horiz_pos_rel": 8,
|
|
|
|
"pred_horiz_pos_abs": 9,
|
|
|
|
"takeoff_detected": 10,
|
|
|
|
"takeoff": 11,
|
|
|
|
"touchdown": 12,
|
|
|
|
"using_gps": 13,
|
|
|
|
"gps_glitching": 14,
|
|
|
|
"gps_quality_good": 15,
|
|
|
|
"initalized": 16,
|
|
|
|
}
|
|
|
|
|
|
|
|
desired_type = "XKF4"
|
|
|
|
old_message_per_core = {}
|
|
|
|
while True:
|
|
|
|
m = self.conn.recv_match(type=desired_type)
|
|
|
|
if m is None:
|
|
|
|
break
|
|
|
|
if m.C not in old_message_per_core:
|
|
|
|
old_message_per_core[m.C] = m
|
|
|
|
continue
|
2024-10-19 22:53:41 -03:00
|
|
|
if self.core is not None and m.C not in self.core:
|
|
|
|
continue
|
2022-01-24 08:50:04 -04:00
|
|
|
current = old_message_per_core[m.C]
|
2023-06-15 05:52:59 -03:00
|
|
|
if m.SS == current.SS:
|
2022-01-24 08:50:04 -04:00
|
|
|
continue
|
|
|
|
line = ""
|
2023-06-15 05:52:59 -03:00
|
|
|
for (name, bit) in bit_descriptions.items():
|
|
|
|
old_bit_set = current.SS & (1 << bit)
|
|
|
|
new_bit_set = m.SS & (1 << bit)
|
2022-01-24 08:50:04 -04:00
|
|
|
if new_bit_set and not old_bit_set:
|
2023-06-15 05:52:59 -03:00
|
|
|
line += " +%s" % name
|
2022-01-24 08:50:04 -04:00
|
|
|
elif not new_bit_set and old_bit_set:
|
2023-06-15 05:52:59 -03:00
|
|
|
line += " -%s" % name
|
2022-01-24 08:50:04 -04:00
|
|
|
|
|
|
|
old_message_per_core[m.C] = m
|
|
|
|
|
|
|
|
timestamp = getattr(m, '_timestamp', 0.0)
|
|
|
|
formatted_timestamp = "%s.%02u" % (
|
|
|
|
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)),
|
|
|
|
int(timestamp * 100.0) % 100)
|
|
|
|
|
|
|
|
print("%s: C=%u %s" % (formatted_timestamp, m.C, line))
|
|
|
|
current = m
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = optparse.OptionParser("solution-status-change.py [options]")
|
|
|
|
|
2024-10-19 22:53:41 -03:00
|
|
|
parser.add_option("", "--core", action="append", type="int",
|
|
|
|
default=[], help="core to show (default is all)")
|
|
|
|
|
2022-01-24 08:50:04 -04:00
|
|
|
(opts, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if len(args) < 1:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
master = args[0]
|
|
|
|
|
2024-10-19 22:53:41 -03:00
|
|
|
if len(opts.core) == 0:
|
|
|
|
opts.core = None
|
|
|
|
|
|
|
|
tester = SolutionStatusChange(master, core=opts.core)
|
2022-01-24 08:50:04 -04:00
|
|
|
tester.run()
|