mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-08 17:08:28 -04:00
autotest: create and use a wait_sensor_state method
This commit is contained in:
parent
7c7fb67829
commit
2b06ae9aa0
@ -978,14 +978,23 @@ class AutoTestPlane(AutoTest):
|
||||
|
||||
self.set_parameter("FENCE_CHANNEL", 7)
|
||||
self.set_parameter("FENCE_ACTION", 4)
|
||||
self.set_rc(3, 1000)
|
||||
self.set_rc(7, 2000)
|
||||
|
||||
self.wait_sensor_state(mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE,
|
||||
present=True,
|
||||
enabled=False,
|
||||
healthy=True)
|
||||
self.set_rc_from_map({
|
||||
3: 1000,
|
||||
7: 2000,
|
||||
})
|
||||
|
||||
self.progress("Checking fence is initially OK")
|
||||
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
||||
print("%s" % str(m))
|
||||
if (not (m.onboard_control_sensors_enabled & fence_bit)):
|
||||
raise NotAchievedException("Fence not initially enabled")
|
||||
self.wait_sensor_state(mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE,
|
||||
present=True,
|
||||
enabled=True,
|
||||
healthy=True,
|
||||
verbose=True,
|
||||
timeout=30)
|
||||
|
||||
self.set_parameter("THR_FS_VALUE", 960)
|
||||
self.progress("Failing receiver (throttle-to-950)")
|
||||
|
@ -4398,11 +4398,12 @@ class AutoTest(ABC):
|
||||
def assert_sensor_state(self, sensor, present=True, enabled=True, healthy=True):
|
||||
return self.sensor_has_state(sensor, present, enabled, healthy, do_assert=True)
|
||||
|
||||
def sensor_has_state(self, sensor, present=True, enabled=True, healthy=True, do_assert=False):
|
||||
def sensor_has_state(self, sensor, present=True, enabled=True, healthy=True, do_assert=False, verbose=False):
|
||||
m = self.mav.recv_match(type='SYS_STATUS', blocking=True, timeout=5)
|
||||
if m is None:
|
||||
raise NotAchievedException("Did not receive SYS_STATUS")
|
||||
# self.progress("Status: %s" % str(mavutil.dump_message_verbose(sys.stdout, m)))
|
||||
if verbose:
|
||||
self.progress("Status: %s" % str(mavutil.dump_message_verbose(sys.stdout, m)))
|
||||
reported_present = m.onboard_control_sensors_present & sensor
|
||||
reported_enabled = m.onboard_control_sensors_enabled & sensor
|
||||
reported_healthy = m.onboard_control_sensors_health & sensor
|
||||
@ -4440,6 +4441,14 @@ class AutoTest(ABC):
|
||||
return False
|
||||
return True
|
||||
|
||||
def wait_sensor_state(self, sensor, present=True, enabled=True, healthy=True, timeout=5, verbose=False):
|
||||
tstart = self.get_sim_time()
|
||||
while True:
|
||||
if self.get_sim_time_cached() - tstart > timeout:
|
||||
raise NotAchievedException("Sensor did not achieve state")
|
||||
if self.sensor_has_state(sensor, present=present, enabled=enabled, healthy=healthy, verbose=verbose):
|
||||
break
|
||||
|
||||
def wait_prearm_sys_status_healthy(self, timeout=60):
|
||||
self.do_timesync_roundtrip()
|
||||
tstart = self.get_sim_time()
|
||||
|
Loading…
Reference in New Issue
Block a user