2022-07-18 10:52:56 -03:00
|
|
|
# AP_FLAKE8_CLEAN
|
|
|
|
|
|
|
|
|
2017-07-21 20:09:51 -03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2014-09-24 01:56:48 -03:00
|
|
|
from math import sqrt
|
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
from LogAnalyzer import Test, TestResult
|
|
|
|
|
2014-09-24 01:56:48 -03:00
|
|
|
|
|
|
|
class TestIMUMatch(Test):
|
|
|
|
'''test for empty or near-empty logs'''
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
Test.__init__(self)
|
|
|
|
self.name = "IMU Mismatch"
|
|
|
|
|
|
|
|
def run(self, logdata, verbose):
|
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
# tuning parameters:
|
|
|
|
warn_threshold = 0.75
|
2014-09-24 01:56:48 -03:00
|
|
|
fail_threshold = 1.5
|
|
|
|
filter_tc = 5.0
|
|
|
|
|
|
|
|
self.result = TestResult()
|
|
|
|
self.result.status = TestResult.StatusType.GOOD
|
|
|
|
|
2022-07-18 10:52:56 -03:00
|
|
|
if ("IMU" in logdata.channels) and ("IMU2" not in logdata.channels):
|
2014-09-24 01:56:48 -03:00
|
|
|
self.result.status = TestResult.StatusType.NA
|
|
|
|
self.result.statusMessage = "No IMU2"
|
|
|
|
return
|
|
|
|
|
2022-07-18 10:52:56 -03:00
|
|
|
if ("IMU" not in logdata.channels) or ("IMU2" not in logdata.channels):
|
2014-09-24 01:56:48 -03:00
|
|
|
self.result.status = TestResult.StatusType.UNKNOWN
|
|
|
|
self.result.statusMessage = "No IMU log data"
|
|
|
|
return
|
|
|
|
|
|
|
|
imu1 = logdata.channels["IMU"]
|
|
|
|
imu2 = logdata.channels["IMU2"]
|
|
|
|
|
2015-07-09 23:25:17 -03:00
|
|
|
timeLabel = None
|
2022-07-18 11:09:04 -03:00
|
|
|
for i in 'TimeMS', 'TimeUS', 'Time':
|
2015-07-09 23:25:17 -03:00
|
|
|
if i in logdata.channels["GPS"]:
|
|
|
|
timeLabel = i
|
|
|
|
break
|
|
|
|
imu1_timems = imu1[timeLabel].listData
|
2014-09-24 01:56:48 -03:00
|
|
|
imu1_accx = imu1["AccX"].listData
|
|
|
|
imu1_accy = imu1["AccY"].listData
|
|
|
|
imu1_accz = imu1["AccZ"].listData
|
|
|
|
|
2015-07-09 23:25:17 -03:00
|
|
|
imu2_timems = imu2[timeLabel].listData
|
2014-09-24 01:56:48 -03:00
|
|
|
imu2_accx = imu2["AccX"].listData
|
|
|
|
imu2_accy = imu2["AccY"].listData
|
|
|
|
imu2_accz = imu2["AccZ"].listData
|
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
imu_multiplier = 1.0e-3
|
2015-07-09 23:25:17 -03:00
|
|
|
if timeLabel == 'TimeUS':
|
2022-07-18 11:09:04 -03:00
|
|
|
imu_multiplier = 1.0e-6
|
2015-07-09 23:25:17 -03:00
|
|
|
|
2014-09-24 01:56:48 -03:00
|
|
|
imu1 = []
|
|
|
|
imu2 = []
|
|
|
|
|
|
|
|
for i in range(len(imu1_timems)):
|
2022-07-18 11:09:04 -03:00
|
|
|
imu1.append(
|
|
|
|
{
|
|
|
|
't': imu1_timems[i][1] * imu_multiplier,
|
|
|
|
'x': imu1_accx[i][1],
|
|
|
|
'y': imu1_accy[i][1],
|
|
|
|
'z': imu1_accz[i][1],
|
|
|
|
}
|
|
|
|
)
|
2014-09-24 01:56:48 -03:00
|
|
|
|
|
|
|
for i in range(len(imu2_timems)):
|
2022-07-18 11:09:04 -03:00
|
|
|
imu2.append(
|
|
|
|
{
|
|
|
|
't': imu2_timems[i][1] * imu_multiplier,
|
|
|
|
'x': imu2_accx[i][1],
|
|
|
|
'y': imu2_accy[i][1],
|
|
|
|
'z': imu2_accz[i][1],
|
|
|
|
}
|
|
|
|
)
|
2014-09-24 01:56:48 -03:00
|
|
|
|
|
|
|
imu1.sort(key=lambda x: x['t'])
|
|
|
|
imu2.sort(key=lambda x: x['t'])
|
|
|
|
|
|
|
|
imu2_index = 0
|
|
|
|
|
|
|
|
last_t = None
|
|
|
|
|
|
|
|
xdiff_filtered = 0
|
|
|
|
ydiff_filtered = 0
|
|
|
|
zdiff_filtered = 0
|
|
|
|
max_diff_filtered = 0
|
|
|
|
|
|
|
|
for i in range(len(imu1)):
|
2022-07-18 11:09:04 -03:00
|
|
|
# find closest imu2 value
|
2014-09-24 01:56:48 -03:00
|
|
|
t = imu1[i]['t']
|
2022-07-18 11:09:04 -03:00
|
|
|
dt = 0 if last_t is None else t - last_t
|
|
|
|
dt = min(dt, 0.1)
|
2014-09-24 01:56:48 -03:00
|
|
|
|
|
|
|
next_imu2 = None
|
2022-07-18 11:09:04 -03:00
|
|
|
for i in range(imu2_index, len(imu2)):
|
2014-09-24 01:56:48 -03:00
|
|
|
next_imu2 = imu2[i]
|
2022-07-18 11:09:04 -03:00
|
|
|
imu2_index = i
|
2014-09-24 01:56:48 -03:00
|
|
|
if next_imu2['t'] >= t:
|
|
|
|
break
|
2022-07-18 11:09:04 -03:00
|
|
|
prev_imu2 = imu2[imu2_index - 1]
|
|
|
|
closest_imu2 = next_imu2 if abs(next_imu2['t'] - t) < abs(prev_imu2['t'] - t) else prev_imu2
|
2014-09-24 01:56:48 -03:00
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
xdiff = imu1[i]['x'] - closest_imu2['x']
|
|
|
|
ydiff = imu1[i]['y'] - closest_imu2['y']
|
|
|
|
zdiff = imu1[i]['z'] - closest_imu2['z']
|
2014-09-24 01:56:48 -03:00
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
xdiff_filtered += (xdiff - xdiff_filtered) * dt / filter_tc
|
|
|
|
ydiff_filtered += (ydiff - ydiff_filtered) * dt / filter_tc
|
|
|
|
zdiff_filtered += (zdiff - zdiff_filtered) * dt / filter_tc
|
2014-09-24 01:56:48 -03:00
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
diff_filtered = sqrt(xdiff_filtered**2 + ydiff_filtered**2 + zdiff_filtered**2)
|
|
|
|
max_diff_filtered = max(max_diff_filtered, diff_filtered)
|
2014-09-24 01:56:48 -03:00
|
|
|
last_t = t
|
|
|
|
|
|
|
|
if max_diff_filtered > fail_threshold:
|
2022-07-18 11:09:04 -03:00
|
|
|
self.result.statusMessage = (
|
|
|
|
"Check vibration or accelerometer calibration. (Mismatch: %.2f, WARN: %.2f, FAIL: %.2f)"
|
|
|
|
% (max_diff_filtered, warn_threshold, fail_threshold)
|
|
|
|
)
|
2014-09-24 01:56:48 -03:00
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
|
|
|
elif max_diff_filtered > warn_threshold:
|
2022-07-18 11:09:04 -03:00
|
|
|
self.result.statusMessage = (
|
|
|
|
"Check vibration or accelerometer calibration. (Mismatch: %.2f, WARN: %.2f, FAIL: %.2f)"
|
|
|
|
% (max_diff_filtered, warn_threshold, fail_threshold)
|
|
|
|
)
|
2014-09-24 01:56:48 -03:00
|
|
|
self.result.status = TestResult.StatusType.WARN
|
|
|
|
else:
|
2022-07-18 11:09:04 -03:00
|
|
|
self.result.statusMessage = "(Mismatch: %.2f, WARN: %.2f, FAIL: %.2f)" % (
|
|
|
|
max_diff_filtered,
|
|
|
|
warn_threshold,
|
|
|
|
fail_threshold,
|
|
|
|
)
|