2014-01-27 02:38:57 -04:00
|
|
|
import DataflashLog
|
2022-07-18 11:09:04 -03:00
|
|
|
from LogAnalyzer import Test, TestResult
|
2016-09-07 19:54:50 -03:00
|
|
|
from VehicleType import VehicleType
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
|
2014-01-27 02:38:57 -04:00
|
|
|
class TestBalanceTwist(Test):
|
2014-10-21 17:30:55 -03:00
|
|
|
'''test for badly unbalanced copter, including yaw twist'''
|
2022-07-18 11:09:04 -03:00
|
|
|
|
2014-10-21 17:30:55 -03:00
|
|
|
def __init__(self):
|
|
|
|
Test.__init__(self)
|
2014-10-27 01:53:42 -03:00
|
|
|
self.name = "Motor Balance"
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2014-10-21 17:30:55 -03:00
|
|
|
def run(self, logdata, verbose):
|
|
|
|
self.result = TestResult()
|
|
|
|
self.result.status = TestResult.StatusType.GOOD
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2016-09-07 19:54:50 -03:00
|
|
|
if logdata.vehicleType != VehicleType.Copter:
|
2014-10-21 17:30:55 -03:00
|
|
|
self.result.status = TestResult.StatusType.NA
|
|
|
|
return
|
2014-01-27 02:38:57 -04:00
|
|
|
|
2014-10-21 17:30:55 -03:00
|
|
|
self.result.status = TestResult.StatusType.UNKNOWN
|
|
|
|
if not "RCOU" in logdata.channels:
|
|
|
|
return
|
|
|
|
|
|
|
|
ch = []
|
|
|
|
|
|
|
|
for i in range(8):
|
2016-09-07 19:54:50 -03:00
|
|
|
for prefix in "Chan", "Ch", "C":
|
2022-07-18 11:09:04 -03:00
|
|
|
if prefix + repr((i + 1)) in logdata.channels["RCOU"]:
|
|
|
|
ch.append(map(lambda x: x[1], logdata.channels["RCOU"][prefix + repr((i + 1))].listData))
|
2014-10-21 17:30:55 -03:00
|
|
|
|
|
|
|
ch = zip(*ch)
|
|
|
|
num_channels = 0
|
2020-07-16 20:22:10 -03:00
|
|
|
ch = list(ch)
|
2014-10-21 17:30:55 -03:00
|
|
|
for i in range(len(ch)):
|
2022-07-18 11:09:04 -03:00
|
|
|
ch[i] = list(filter(lambda x: (x > 0 and x < 3000), ch[i]))
|
2014-10-21 17:30:55 -03:00
|
|
|
if num_channels < len(ch[i]):
|
|
|
|
num_channels = len(ch[i])
|
|
|
|
|
2017-09-10 22:59:37 -03:00
|
|
|
if logdata.frame:
|
|
|
|
num_channels = logdata.num_motor_channels()
|
|
|
|
|
2014-10-21 17:30:55 -03:00
|
|
|
if num_channels < 2:
|
|
|
|
return
|
|
|
|
|
2016-09-07 19:54:50 -03:00
|
|
|
try:
|
2022-07-18 11:09:04 -03:00
|
|
|
min_throttle = (
|
|
|
|
logdata.parameters["RC3_MIN"]
|
|
|
|
+ logdata.parameters["THR_MIN"]
|
|
|
|
/ (logdata.parameters["RC3_MAX"] - logdata.parameters["RC3_MIN"])
|
|
|
|
/ 1000.0
|
|
|
|
)
|
2016-09-07 19:54:50 -03:00
|
|
|
except KeyError as e:
|
2022-07-18 11:09:04 -03:00
|
|
|
min_throttle = (
|
|
|
|
logdata.parameters["MOT_PWM_MIN"]
|
|
|
|
/ (logdata.parameters["MOT_PWM_MAX"] - logdata.parameters["RC3_MIN"])
|
|
|
|
/ 1000.0
|
|
|
|
)
|
2016-09-07 19:54:50 -03:00
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
ch = list(filter(lambda x: sum(x) / num_channels > min_throttle, ch))
|
2014-10-21 17:30:55 -03:00
|
|
|
|
|
|
|
if len(ch) == 0:
|
|
|
|
return
|
|
|
|
|
2017-09-23 22:51:51 -03:00
|
|
|
avg_sum = 0
|
2014-10-21 17:30:55 -03:00
|
|
|
avg_ch = []
|
|
|
|
for i in range(num_channels):
|
2022-07-18 11:09:04 -03:00
|
|
|
avg = list(map(lambda x: x[i], ch))
|
|
|
|
avg = sum(avg) / len(avg)
|
2014-10-21 17:30:55 -03:00
|
|
|
avg_ch.append(avg)
|
2017-09-23 22:51:51 -03:00
|
|
|
avg_sum += avg
|
|
|
|
avg_all = avg_sum / num_channels
|
2014-10-21 17:30:55 -03:00
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
self.result.statusMessage = (
|
|
|
|
"Motor channel averages = %s\nAverage motor output = %.0f\nDifference between min and max motor averages = %.0f"
|
|
|
|
% (str(avg_ch), avg_all, abs(min(avg_ch) - max(avg_ch)))
|
|
|
|
)
|
2014-10-21 17:30:55 -03:00
|
|
|
|
|
|
|
self.result.status = TestResult.StatusType.GOOD
|
|
|
|
|
2022-07-18 11:09:04 -03:00
|
|
|
if abs(min(avg_ch) - max(avg_ch)) > 75:
|
2014-10-21 17:30:55 -03:00
|
|
|
self.result.status = TestResult.StatusType.WARN
|
2022-07-18 11:09:04 -03:00
|
|
|
if abs(min(avg_ch) - max(avg_ch)) > 150:
|
2014-10-21 17:30:55 -03:00
|
|
|
self.result.status = TestResult.StatusType.FAIL
|