mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 01:33:34 +08:00
refactor ecl ekf analysis (#11412)
* refactor ekf analysis part 1: move plotting to functions * add plot_check_flags plot function * put plots in seperate file * use object-oriented programming for plotting * move functions for post processing and pdf report creation to new files * add in_air_detector and description as a csv file * refactor metrics and checks into separate functions * refactor metrics into seperate file, seperate plotting * ecl-ekf tools: re-structure folder and move results table generation * ecl-ekf-tool: fix imports and test_results_table * ecl-ekf tools: bugfix output observer tracking error plot * ecl-ekf-tools: update batch processing to new api, fix exception handling * ecl-ekf-tools: use correct in_air_detector * ecl-ekf-tools: rename csv file containing the bare test results table * ecl-tools: refactor for improving readability * ecl-ekf tools: small plotting bugfixes * ecl-ekf tools: small bugfixes in_air time, on_ground_trans, filenames * ecl-ekf-tools: fix amber metric bug * ecl-ekf-tools: remove custom function in inairdetector * ecl-ekf-tools: remove import of pandas * ecl-ekf-tools: add python interpreter to the script start * ecl-ekf-tools pdf_report: fix python interpreter line * px4-dev-ros-kinetic: update container tag to 2019-02-13 * ecl-ekf-tools python interpreter line: call python3 bin directly * ecl-ekf-tools: change airtime from namedtuple to class for python 3.5 * ecl-ekf-tools: update docker image px4-dev-ros-kinetic * ecl-ekf-tools: fix memory leak by correctly closing matplotlib figures
This commit is contained in:
@@ -1,47 +1,87 @@
|
||||
#!/usr/bin/env python
|
||||
#! /usr/bin/env python3
|
||||
"""
|
||||
Runs process_logdata_ekf.py on the .ulg files in the supplied directory. ulog files are skipped from the analysis, if a
|
||||
corresponding .pdf file already exists (unless the overwrite flag was set).
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import os, glob
|
||||
|
||||
"""
|
||||
Runs process_logdata_ekf.py on the .ulg files in the supplied directory. ulog files are skipped from the analysis, if a
|
||||
corresponding .pdf file already exists (unless the overwrite flag was set).
|
||||
"""
|
||||
from process_logdata_ekf import process_logdata_ekf
|
||||
|
||||
parser = argparse.ArgumentParser(description='Analyse the estimator_status and ekf2_innovation message data for the'
|
||||
' .ulg files in the specified directory')
|
||||
parser.add_argument("directory_path")
|
||||
parser.add_argument('-o', '--overwrite', action='store_true',
|
||||
help='Whether to overwrite an already analysed file. If a file with .pdf extension exists for a .ulg'
|
||||
'file, the log file will be skipped from analysis unless this flag has been set.')
|
||||
parser.add_argument('--no-sensor-safety-margin', action='store_true',
|
||||
help='Whether to not cut-off 5s after take-off and 5s before landing '
|
||||
'(for certain sensors that might be influence by proximity to ground).')
|
||||
def get_arguments():
|
||||
parser = argparse.ArgumentParser(description='Analyse the estimator_status and ekf2_innovation message data for the'
|
||||
' .ulg files in the specified directory')
|
||||
parser.add_argument("directory_path")
|
||||
parser.add_argument('-o', '--overwrite', action='store_true',
|
||||
help='Whether to overwrite an already analysed file. If a file with .pdf extension exists for a .ulg'
|
||||
'file, the log file will be skipped from analysis unless this flag has been set.')
|
||||
parser.add_argument('--no-plots', action='store_true',
|
||||
help='Whether to only analyse and not plot the summaries for developers.')
|
||||
parser.add_argument('--check-level-thresholds', type=str, default=None,
|
||||
help='The csv file of fail and warning test thresholds for analysis.')
|
||||
parser.add_argument('--check-table', type=str, default=None,
|
||||
help='The csv file with descriptions of the checks.')
|
||||
parser.add_argument('--no-sensor-safety-margin', action='store_true',
|
||||
help='Whether to not cut-off 5s after take-off and 5s before landing '
|
||||
'(for certain sensors that might be influence by proximity to ground).')
|
||||
return parser.parse_args()
|
||||
|
||||
def is_valid_directory(parser, arg):
|
||||
if os.path.isdir(arg):
|
||||
# Directory exists so return the directory
|
||||
return arg
|
||||
|
||||
def main() -> None:
|
||||
|
||||
args = get_arguments()
|
||||
|
||||
if args.check_level_thresholds is not None:
|
||||
check_level_dict_filename = args.check_level_thresholds
|
||||
else:
|
||||
parser.error('The directory {} does not exist'.format(arg))
|
||||
file_dir = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||
check_level_dict_filename = os.path.join(file_dir, "check_level_dict.csv")
|
||||
|
||||
args = parser.parse_args()
|
||||
ulog_directory = args.directory_path
|
||||
print("\n"+"analysing the .ulg files in "+ulog_directory)
|
||||
|
||||
# get all the ulog files found in the specified directory and in subdirectories
|
||||
ulog_files = glob.glob(os.path.join(ulog_directory, '**/*.ulg'), recursive=True)
|
||||
|
||||
# remove the files already analysed unless the overwrite flag was specified. A ulog file is consired to be analysed if
|
||||
# a corresponding .pdf file exists.'
|
||||
if not args.overwrite:
|
||||
print("skipping already analysed ulg files.")
|
||||
ulog_files = [ulog_file for ulog_file in ulog_files if not os.path.exists('{}.pdf'.format(ulog_file))]
|
||||
|
||||
# analyse all ulog files
|
||||
for ulog_file in ulog_files:
|
||||
print("\n"+"loading " + ulog_file + " for analysis")
|
||||
if args.no_sensor_safety_margin:
|
||||
os.system("python process_logdata_ekf.py {} --no-sensor-safety-margin".format(ulog_file))
|
||||
if args.check_table is not None:
|
||||
check_table_filename = args.check_table
|
||||
else:
|
||||
os.system("python process_logdata_ekf.py {}".format(ulog_file))
|
||||
file_dir = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||
check_table_filename = os.path.join(file_dir, "check_table.csv")
|
||||
|
||||
ulog_directory = args.directory_path
|
||||
|
||||
# get all the ulog files found in the specified directory and in subdirectories
|
||||
ulog_files = glob.glob(os.path.join(ulog_directory, '**/*.ulg'), recursive=True)
|
||||
print("found {:d} .ulg files in {:s}".format(len(ulog_files), ulog_directory))
|
||||
|
||||
# remove the files already analysed unless the overwrite flag was specified. A ulog file is consired to be analysed if
|
||||
# a corresponding .pdf file exists.'
|
||||
if not args.overwrite:
|
||||
print("skipping already analysed ulg files.")
|
||||
ulog_files = [ulog_file for ulog_file in ulog_files if
|
||||
not os.path.exists('{}.pdf'.format(ulog_file))]
|
||||
|
||||
n_files = len(ulog_files)
|
||||
|
||||
print("analysing the {:d} .ulg files".format(n_files))
|
||||
|
||||
i = 1
|
||||
n_skipped = 0
|
||||
# analyse all ulog files
|
||||
for ulog_file in ulog_files:
|
||||
print('analysing file {:d}/{:d}: {:s}'.format(i, n_files, ulog_file))
|
||||
|
||||
try:
|
||||
_ = process_logdata_ekf(
|
||||
ulog_file, check_level_dict_filename, check_table_filename,
|
||||
plot=not args.no_plots, sensor_safety_margins=not args.no_sensor_safety_margin)
|
||||
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
print('an exception occurred, skipping file {:s}'.format(ulog_file))
|
||||
n_skipped = n_skipped + 1
|
||||
|
||||
i = i + 1
|
||||
|
||||
print('{:d}/{:d} files analysed, {:d} skipped.'.format(n_files-n_skipped, n_files, n_skipped))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user