Skip to content

Commit

Permalink
Tools: autotest: suite: add check_parameter_value to to check parma…
Browse files Browse the repository at this point in the history
…mter is withing a given percentage of the expected value
  • Loading branch information
IamPete1 authored and tridge committed Feb 3, 2025
1 parent f59f28b commit 31fe3d3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Tools/autotest/vehicle_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -6271,6 +6271,35 @@ def add_param_value(mav, m):
return
raise ValueError("Failed to set parameters (%s)" % want)

def check_parameter_value(self, name, expected_value, max_error_percent):
value = self.get_parameter_direct(name, verbose=False)

# Convert to ratio and find limits
error_ratio = max_error_percent / 100
limits = [expected_value * (1 + error_ratio), expected_value * (1 - error_ratio)]

# Ensure that min and max are always the corret way round
upper_limit = max(limits)
lower_limit = min(limits)

# Work out the true error percentage
error_percent = math.nan
if expected_value != 0:
error_percent = abs(1.0 - (value / expected_value)) * 100

# Check value is within limits
if (value > upper_limit) or (value < lower_limit):
raise ValueError("%s expected %f ± %f%% (%f to %f) got %s with %f%% error" % (
name,
expected_value,
max_error_percent,
lower_limit,
upper_limit,
value,
error_percent))

self.progress("%s: (%f) check passed %f%% error less than %f%%" % (name, value, error_percent, max_error_percent))

def get_parameter(self, *args, **kwargs):
return self.get_parameter_direct(*args, **kwargs)

Expand Down

0 comments on commit 31fe3d3

Please sign in to comment.