2022-07-18 10:52:56 -03:00
|
|
|
# AP_FLAKE8_CLEAN
|
|
|
|
|
|
|
|
|
2017-07-21 20:09:51 -03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
from LogAnalyzer import Test, TestResult
|
2017-09-29 02:21:28 -03:00
|
|
|
from VehicleType import VehicleType
|
2014-01-27 02:38:57 -04:00
|
|
|
|
|
|
|
|
2014-06-15 18:40:09 -03:00
|
|
|
class TestThrust(Test):
|
2014-08-12 12:54:15 -03:00
|
|
|
'''test for sufficient thrust (copter only for now)'''
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
def __init__(self):
|
|
|
|
Test.__init__(self)
|
|
|
|
self.name = "Thrust"
|
2022-07-18 11:09:04 -03:00
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
def run(self, logdata, verbose):
|
|
|
|
self.result = TestResult()
|
|
|
|
self.result.status = TestResult.StatusType.GOOD
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2017-09-23 22:51:51 -03:00
|
|
|
if logdata.vehicleType != VehicleType.Copter:
|
2014-08-12 12:54:15 -03:00
|
|
|
self.result.status = TestResult.StatusType.NA
|
|
|
|
return
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2022-07-18 10:52:56 -03:00
|
|
|
if "CTUN" not in logdata.channels:
|
2014-08-12 12:54:15 -03:00
|
|
|
self.result.status = TestResult.StatusType.UNKNOWN
|
|
|
|
self.result.statusMessage = "No CTUN log data"
|
|
|
|
return
|
2022-07-18 10:52:56 -03:00
|
|
|
if "ATT" not in logdata.channels:
|
2014-08-12 12:54:15 -03:00
|
|
|
self.result.status = TestResult.StatusType.UNKNOWN
|
|
|
|
self.result.statusMessage = "No ATT log data"
|
|
|
|
return
|
2014-02-22 15:36:30 -04:00
|
|
|
|
2017-09-23 22:51:51 -03:00
|
|
|
throut_key = None
|
|
|
|
for key in "ThO", "ThrOut":
|
|
|
|
if key in logdata.channels["CTUN"]:
|
|
|
|
throut_key = key
|
|
|
|
break
|
|
|
|
if throut_key is None:
|
|
|
|
self.result.status = TestResult.StatusType.UNKNOWN
|
|
|
|
self.result.statusMessage = "Could not find throttle out column"
|
|
|
|
return
|
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
# check for throttle (CTUN.ThrOut) above 700 for a chunk of time with copter not rising
|
2014-02-22 15:36:30 -04:00
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
highThrottleThreshold = 700
|
2022-07-18 11:09:04 -03:00
|
|
|
tiltThreshold = 20 # ignore high throttle when roll or tilt is above this value
|
2014-08-12 12:54:15 -03:00
|
|
|
climbThresholdWARN = 100
|
|
|
|
climbThresholdFAIL = 50
|
|
|
|
minSampleLength = 50
|
2014-02-22 15:36:30 -04:00
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
highThrottleSegments = []
|
2014-02-22 15:36:30 -04:00
|
|
|
|
2022-07-18 10:52:56 -03:00
|
|
|
# find any contiguous chunks where CTUN.ThrOut > highThrottleThreshold, ignore high throttle if
|
|
|
|
# tilt > tiltThreshold, and discard any segments shorter than minSampleLength
|
2014-08-12 12:54:15 -03:00
|
|
|
start = None
|
2017-09-23 22:51:51 -03:00
|
|
|
data = logdata.channels["CTUN"][throut_key].listData
|
2022-07-18 11:09:04 -03:00
|
|
|
for i in range(0, len(data)):
|
|
|
|
(lineNumber, value) = data[i]
|
2014-08-12 12:54:15 -03:00
|
|
|
isBelowTiltThreshold = True
|
|
|
|
if value > highThrottleThreshold:
|
2022-07-18 11:09:04 -03:00
|
|
|
(roll, meh) = logdata.channels["ATT"]["Roll"].getNearestValue(lineNumber)
|
|
|
|
(pitch, meh) = logdata.channels["ATT"]["Pitch"].getNearestValue(lineNumber)
|
2014-08-12 12:54:15 -03:00
|
|
|
if (abs(roll) > tiltThreshold) or (abs(pitch) > tiltThreshold):
|
|
|
|
isBelowTiltThreshold = False
|
|
|
|
if (value > highThrottleThreshold) and isBelowTiltThreshold:
|
2022-07-18 10:52:56 -03:00
|
|
|
if start is None:
|
2014-08-12 12:54:15 -03:00
|
|
|
start = i
|
2022-07-18 10:52:56 -03:00
|
|
|
elif start is not None:
|
2022-07-18 11:09:04 -03:00
|
|
|
if (i - start) > minSampleLength:
|
|
|
|
highThrottleSegments.append((start, i))
|
2014-08-12 12:54:15 -03:00
|
|
|
start = None
|
2014-02-22 15:36:30 -04:00
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
climbRate = "CRate"
|
|
|
|
if "CRate" not in logdata.channels["CTUN"]:
|
|
|
|
climbRate = "CRt"
|
2014-03-19 20:37:23 -03:00
|
|
|
|
2014-08-12 12:54:15 -03:00
|
|
|
# loop through each checking climbRate, if < 50 FAIL, if < 100 WARN
|
|
|
|
# TODO: we should filter climbRate and use its slope rather than value for this test
|
|
|
|
for seg in highThrottleSegments:
|
2022-07-18 11:09:04 -03:00
|
|
|
(startLine, endLine) = (data[seg[0]][0], data[seg[1]][0])
|
|
|
|
avgClimbRate = logdata.channels["CTUN"][climbRate].getSegment(startLine, endLine).avg()
|
|
|
|
avgThrOut = logdata.channels["CTUN"][throut_key].getSegment(startLine, endLine).avg()
|
2014-08-12 12:54:15 -03:00
|
|
|
if avgClimbRate < climbThresholdFAIL:
|
|
|
|
self.result.status = TestResult.StatusType.FAIL
|
2022-07-18 11:09:04 -03:00
|
|
|
self.result.statusMessage = "Avg climb rate %.2f cm/s for throttle avg %d" % (avgClimbRate, avgThrOut)
|
2014-08-12 12:54:15 -03:00
|
|
|
return
|
|
|
|
if avgClimbRate < climbThresholdWARN:
|
|
|
|
self.result.status = TestResult.StatusType.WARN
|
2022-07-18 11:09:04 -03:00
|
|
|
self.result.statusMessage = "Avg climb rate %.2f cm/s for throttle avg %d" % (avgClimbRate, avgThrOut)
|