Skip to content

Commit

Permalink
autotest: make WaitAndMaintainEKFFlags progress nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Jun 28, 2024
1 parent 780352c commit 9d7c827
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Tools/autotest/vehicle_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def run(self):

# check for timeout
if now - tstart > self.timeout:
self.print_failure_text(now, current_value)
raise self.timeoutexception()

# handle the case where we are are achieving our value:
Expand Down Expand Up @@ -401,6 +402,10 @@ def print_progress(self, now, value):
text += f" (maintain={delta:.1f}/{self.minimum_duration})"
self.progress(text)

def print_failure_text(self, now, value):
'''optionally print a more detailed error string'''
pass

def progress_text(self, value):
return f"want={self.get_target_value()} got={value}"

Expand Down Expand Up @@ -501,10 +506,39 @@ def timeoutexception(self):
return AutoTestTimeoutException(f"Failed to get EKF.flags={self.required_flags}")

def progress_text(self, current_value):
error_bits_str = ""
if current_value & self.error_bits:
error_bits_str = " (error bits present)"
return (f"Want=({self.required_flags}) got={current_value}{error_bits_str}")
error_bits = current_value & self.error_bits
return (f"Want={self.required_flags} got={current_value} errors={error_bits}")

def ekf_flags_string(self, bits):
ret = []
for i in range(0, 16):
bit = 1 << i
try:
if not bits & bit:
continue
name = mavutil.mavlink.enums["ESTIMATOR_STATUS_FLAGS"][bit].name
trimmed_name = name.removeprefix("ESTIMATOR_")
ret.append(trimmed_name)
except KeyError:
ret.append(str(bit))
return "|".join(ret)

def failure_text(self, now, current_value):
components = []
components.append(("want", self.ekf_flags_string(self.required_flags)))

missing_bits = self.required_flags & ~current_value
if missing_bits:
components.append(("missing", self.ekf_flags_string(missing_bits)))

error_bits = current_value & self.error_bits
if error_bits:
components.append(("errors", self.ekf_flags_string(error_bits)))

return " ".join([f"{n}={v}" for (n, v) in components])

def print_failure_text(self, now, current_value):
self.progress(self.failure_text(now, current_value))


class WaitAndMaintainArmed(WaitAndMaintain):
Expand Down

0 comments on commit 9d7c827

Please sign in to comment.