Browse Source

autotest: raise exception for arm/disarm failures on switch/rc

Users were calling these without checking the return values. Make that
a non-issue
gps-1.3.1
Peter Barker 4 years ago committed by Peter Barker
parent
commit
8fc6e98900
  1. 77
      Tools/autotest/common.py
  2. 6
      Tools/autotest/quadplane.py
  3. 24
      Tools/autotest/rover.py

77
Tools/autotest/common.py

@ -3992,13 +3992,12 @@ class AutoTest(ABC):
self.progress("MOTORS ARMED OK WITH RADIO") self.progress("MOTORS ARMED OK WITH RADIO")
self.set_output_to_trim(self.get_stick_arming_channel()) self.set_output_to_trim(self.get_stick_arming_channel())
self.progress("Arm in %ss" % tdelta) # TODO check arming time self.progress("Arm in %ss" % tdelta) # TODO check arming time
return True return
print("Not armed after %f seconds" % (tdelta)) print("Not armed after %f seconds" % (tdelta))
if tdelta > timeout: if tdelta > timeout:
break break
self.progress("Failed to ARM with radio")
self.set_output_to_trim(self.get_stick_arming_channel()) self.set_output_to_trim(self.get_stick_arming_channel())
return False raise NotAchievedException("Failed to ARM with radio")
def disarm_motors_with_rc_input(self, timeout=20, watch_for_disabled=False): def disarm_motors_with_rc_input(self, timeout=20, watch_for_disabled=False):
"""Disarm motors with radio.""" """Disarm motors with radio."""
@ -4020,11 +4019,10 @@ class AutoTest(ABC):
self.progress("Found 'Rudder disarm: disabled' in statustext") self.progress("Found 'Rudder disarm: disabled' in statustext")
break break
self.context_clear_collection('STATUSTEXT') self.context_clear_collection('STATUSTEXT')
if not ret:
self.progress("Failed to DISARM with RC input")
self.set_output_to_trim(self.get_stick_arming_channel()) self.set_output_to_trim(self.get_stick_arming_channel())
self.context_pop() self.context_pop()
return ret if not ret:
raise NotAchievedException("Failed to DISARM with RC input")
def arm_motors_with_switch(self, switch_chan, timeout=20): def arm_motors_with_switch(self, switch_chan, timeout=20):
"""Arm motors with switch.""" """Arm motors with switch."""
@ -4035,9 +4033,8 @@ class AutoTest(ABC):
self.wait_heartbeat() self.wait_heartbeat()
if self.mav.motors_armed(): if self.mav.motors_armed():
self.progress("MOTORS ARMED OK WITH SWITCH") self.progress("MOTORS ARMED OK WITH SWITCH")
return True return
self.progress("Failed to ARM with switch") raise NotAchievedException("Failed to ARM with switch")
return False
def disarm_motors_with_switch(self, switch_chan, timeout=20): def disarm_motors_with_switch(self, switch_chan, timeout=20):
"""Disarm motors with switch.""" """Disarm motors with switch."""
@ -4048,9 +4045,8 @@ class AutoTest(ABC):
self.wait_heartbeat() self.wait_heartbeat()
if not self.mav.motors_armed(): if not self.mav.motors_armed():
self.progress("MOTORS DISARMED OK WITH SWITCH") self.progress("MOTORS DISARMED OK WITH SWITCH")
return True return
self.progress("Failed to DISARM with switch") raise NotAchievedException("Failed to DISARM with switch")
return False
def disarm_wait(self, timeout=10): def disarm_wait(self, timeout=10):
tstart = self.get_sim_time() tstart = self.get_sim_time()
@ -7491,15 +7487,13 @@ Also, ignores heartbeats not from our target system'''
if not self.is_sub(): if not self.is_sub():
self.start_subtest("Test arm with rc input") self.start_subtest("Test arm with rc input")
if not self.arm_motors_with_rc_input(): self.arm_motors_with_rc_input()
raise NotAchievedException("Failed to arm with RC input")
self.progress("disarm with rc input") self.progress("disarm with rc input")
if self.is_balancebot(): if self.is_balancebot():
self.progress("balancebot can't disarm with RC input") self.progress("balancebot can't disarm with RC input")
self.disarm_vehicle() self.disarm_vehicle()
else: else:
if not self.disarm_motors_with_rc_input(): self.disarm_motors_with_rc_input()
raise NotAchievedException("Failed to disarm with RC input")
self.start_subtest("Test arm and disarm with switch") self.start_subtest("Test arm and disarm with switch")
arming_switch = 7 arming_switch = 7
@ -7507,10 +7501,8 @@ Also, ignores heartbeats not from our target system'''
self.set_rc(arming_switch, 1000) self.set_rc(arming_switch, 1000)
# delay so a transition is seen by the RC switch code: # delay so a transition is seen by the RC switch code:
self.delay_sim_time(0.5) self.delay_sim_time(0.5)
if not self.arm_motors_with_switch(arming_switch): self.arm_motors_with_switch(arming_switch)
raise NotAchievedException("Failed to arm with switch") self.disarm_motors_with_switch(arming_switch)
if not self.disarm_motors_with_switch(arming_switch):
raise NotAchievedException("Failed to disarm with switch")
self.set_rc(arming_switch, 1000) self.set_rc(arming_switch, 1000)
if self.is_copter(): if self.is_copter():
@ -7521,10 +7513,18 @@ Also, ignores heartbeats not from our target system'''
raise NotAchievedException("Armed when throttle too high") raise NotAchievedException("Armed when throttle too high")
except ValueError: except ValueError:
pass pass
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed via RC when throttle too high") "Armed via RC when throttle too high")
if self.arm_motors_with_switch(arming_switch): try:
self.arm_motors_with_switch(arming_switch)
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException("Armed via RC when switch too high") raise NotAchievedException("Armed via RC when switch too high")
self.zero_throttle() self.zero_throttle()
self.set_rc(arming_switch, 1000) self.set_rc(arming_switch, 1000)
@ -7532,12 +7532,20 @@ Also, ignores heartbeats not from our target system'''
# Sub doesn't have 'stick commands' # Sub doesn't have 'stick commands'
self.start_subtest("Test arming failure with ARMING_RUDDER=0") self.start_subtest("Test arming failure with ARMING_RUDDER=0")
self.set_parameter("ARMING_RUDDER", 0) self.set_parameter("ARMING_RUDDER", 0)
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed with rudder when ARMING_RUDDER=0") "Armed with rudder when ARMING_RUDDER=0")
self.start_subtest("Test disarming failure with ARMING_RUDDER=0") self.start_subtest("Test disarming failure with ARMING_RUDDER=0")
self.arm_vehicle() self.arm_vehicle()
if self.disarm_motors_with_rc_input(watch_for_disabled=True): try:
self.disarm_motors_with_rc_input(watch_for_disabled=True)
except NotAchievedException:
pass
if not self.armed():
raise NotAchievedException( raise NotAchievedException(
"Disarmed with rudder when ARMING_RUDDER=0") "Disarmed with rudder when ARMING_RUDDER=0")
self.disarm_vehicle() self.disarm_vehicle()
@ -7545,7 +7553,11 @@ Also, ignores heartbeats not from our target system'''
self.start_subtest("Test disarming failure with ARMING_RUDDER=1") self.start_subtest("Test disarming failure with ARMING_RUDDER=1")
self.set_parameter("ARMING_RUDDER", 1) self.set_parameter("ARMING_RUDDER", 1)
self.arm_vehicle() self.arm_vehicle()
if self.disarm_motors_with_rc_input(): try:
self.disarm_motors_with_rc_input()
except NotAchievedException:
pass
if not self.armed():
raise NotAchievedException( raise NotAchievedException(
"Disarmed with rudder with ARMING_RUDDER=1") "Disarmed with rudder with ARMING_RUDDER=1")
self.disarm_vehicle() self.disarm_vehicle()
@ -7555,12 +7567,19 @@ Also, ignores heartbeats not from our target system'''
if self.is_copter(): if self.is_copter():
self.start_subtest("Test arming failure with interlock enabled") self.start_subtest("Test arming failure with interlock enabled")
self.set_rc(interlock_channel, 2000) self.set_rc(interlock_channel, 2000)
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed with RC input when interlock enabled") "Armed with RC input when interlock enabled")
if self.arm_motors_with_switch(arming_switch): try:
raise NotAchievedException( self.arm_motors_with_switch(arming_switch)
"Armed with switch when interlock enabled") except NotAchievedException:
pass
if self.armed():
raise NotAchievedException("Armed with switch when interlock enabled")
self.disarm_vehicle() self.disarm_vehicle()
self.wait_heartbeat() self.wait_heartbeat()
self.set_rc(arming_switch, 1000) self.set_rc(arming_switch, 1000)

6
Tools/autotest/quadplane.py

@ -159,7 +159,11 @@ class AutoTestQuadPlane(AutoTest):
self.wait_servo_channel_value(5, spin_min_pwm, comparator=operator.ge) self.wait_servo_channel_value(5, spin_min_pwm, comparator=operator.ge)
self.progress("Verify that rudder disarm is disabled") self.progress("Verify that rudder disarm is disabled")
if self.disarm_motors_with_rc_input(): try:
self.disarm_motors_with_rc_input()
except NotAchievedException:
pass
if not self.armed():
raise NotAchievedException("Rudder disarm not disabled") raise NotAchievedException("Rudder disarm not disabled")
self.progress("Disarming with switch") self.progress("Disarming with switch")

24
Tools/autotest/rover.py

@ -3878,7 +3878,11 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz
self.drain_mav() self.drain_mav()
self.assert_fence_breached() self.assert_fence_breached()
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed when within exclusion zone") "Armed when within exclusion zone")
@ -3930,7 +3934,11 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz
self.drain_mav() self.drain_mav()
self.assert_fence_breached() self.assert_fence_breached()
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed when outside an inclusion zone") "Armed when outside an inclusion zone")
@ -3962,7 +3970,11 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz
self.drain_mav() self.drain_mav()
self.assert_fence_breached() self.assert_fence_breached()
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed when within polygon exclusion zone") "Armed when within polygon exclusion zone")
@ -3994,7 +4006,11 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz self.delay_sim_time(5) # ArduPilot only checks for breaches @1Hz
self.drain_mav() self.drain_mav()
self.assert_fence_breached() self.assert_fence_breached()
if self.arm_motors_with_rc_input(): try:
self.arm_motors_with_rc_input()
except NotAchievedException:
pass
if self.armed():
raise NotAchievedException( raise NotAchievedException(
"Armed when outside polygon inclusion zone") "Armed when outside polygon inclusion zone")

Loading…
Cancel
Save