Skip to content

Commit

Permalink
Tools: support MAV_CMD_EXTERNAL_WIND_ESTIMATE
Browse files Browse the repository at this point in the history
  • Loading branch information
python36 authored and peterbarker committed Sep 4, 2024
1 parent e74afdf commit d802b0e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Tools/autotest/arduplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -6052,6 +6052,43 @@ def ForceArm(self):
)
self.disarm_vehicle()

def _MAV_CMD_EXTERNAL_WIND_ESTIMATE(self, command):
self.reboot_sitl()

def cmp_with_variance(a, b, p):
return abs(a - b) < p

def check_eq(speed, direction, ret_dir, timeout=1):
command(mavutil.mavlink.MAV_CMD_EXTERNAL_WIND_ESTIMATE, p1=speed, p3=direction)

tstart = self.get_sim_time()
while True:
if self.get_sim_time_cached() - tstart > timeout:
raise NotAchievedException(
f"Failed to set wind speed or/and direction: speed != {speed} or direction != {direction}")

m = self.assert_receive_message("WIND")
if cmp_with_variance(m.speed, speed, 0.5) and cmp_with_variance(m.direction, ret_dir, 5):
return True

check_eq(1, 45, 45)
check_eq(2, 90, 90)
check_eq(3, 120, 120)
check_eq(4, 180, -180)
check_eq(5, 240, -120)
check_eq(6, 320, -40)
check_eq(7, 360, 0)

command(mavutil.mavlink.MAV_CMD_EXTERNAL_WIND_ESTIMATE, p1=-2, p3=90, want_result=mavutil.mavlink.MAV_RESULT_DENIED)
command(mavutil.mavlink.MAV_CMD_EXTERNAL_WIND_ESTIMATE, p1=2, p3=-90, want_result=mavutil.mavlink.MAV_RESULT_DENIED)
command(mavutil.mavlink.MAV_CMD_EXTERNAL_WIND_ESTIMATE, p1=-2, p3=-90, want_result=mavutil.mavlink.MAV_RESULT_DENIED)
command(mavutil.mavlink.MAV_CMD_EXTERNAL_WIND_ESTIMATE, p1=2, p3=370, want_result=mavutil.mavlink.MAV_RESULT_DENIED)

def MAV_CMD_EXTERNAL_WIND_ESTIMATE(self):
'''test MAV_CMD_EXTERNAL_WIND_ESTIMATE as a mavlink command'''
self._MAV_CMD_EXTERNAL_WIND_ESTIMATE(self.run_cmd)
self._MAV_CMD_EXTERNAL_WIND_ESTIMATE(self.run_cmd_int)

def tests(self):
'''return list of all tests'''
ret = super(AutoTestPlane, self).tests()
Expand Down Expand Up @@ -6183,6 +6220,7 @@ def tests(self):
self.GPSPreArms,
self.SetHomeAltChange,
self.ForceArm,
self.MAV_CMD_EXTERNAL_WIND_ESTIMATE,
])
return ret

Expand Down

0 comments on commit d802b0e

Please sign in to comment.