Skip to content

Commit dd54484

Browse files
committed
Tools: autotest: copter: add max alt fence avoidance test
1 parent c9dc0a8 commit dd54484

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Tools/autotest/arducopter.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,58 @@ def MaxAltFence(self):
16031603

16041604
self.zero_throttle()
16051605

1606+
# MaxAltFence - fly up and make sure fence action does not trigger
1607+
# Also check that the vehicle will not try and descend too fast when trying to backup from a max alt fence due to avoidance
1608+
def MaxAltFenceAvoid(self):
1609+
'''Test Max Alt Fence'''
1610+
self.takeoff(10, mode="LOITER")
1611+
"""Hold loiter position."""
1612+
1613+
# enable fence, only max altitude, defualt is 100m
1614+
# No action, rely on avoidance to prevent the breach
1615+
self.set_parameters({
1616+
"FENCE_ENABLE": 1,
1617+
"FENCE_TYPE": 1,
1618+
"FENCE_ACTION": 0,
1619+
})
1620+
1621+
# Try and fly past the fence
1622+
self.set_rc(3, 1920)
1623+
1624+
# Avoid should prevent the vehicle flying past the fence, so the altitude wait should timeouts
1625+
try:
1626+
self.wait_altitude(140, 150, timeout=90, relative=True)
1627+
raise NotAchievedException("Avoid should prevent reaching altitude")
1628+
except AutoTestTimeoutException:
1629+
pass
1630+
except Exception as e:
1631+
raise e
1632+
1633+
# Check descent is not too fast, allow 10% above the configured backup speed
1634+
max_descent_rate = -self.get_parameter("AVOID_BACKUP_SPD") * 1.1
1635+
1636+
def get_climb_rate(mav, m):
1637+
m_type = m.get_type()
1638+
if m_type != 'VFR_HUD':
1639+
return
1640+
if m.climb < max_descent_rate:
1641+
raise NotAchievedException("Decending too fast want %f got %f" % (max_descent_rate, m.climb))
1642+
1643+
self.context_push()
1644+
self.install_message_hook_context(get_climb_rate)
1645+
1646+
# Reduce fence alt, this will result in a fence breach, but there is no action.
1647+
# Avoid should then backup the vehicle to be under the new fence alt.
1648+
self.set_parameters({
1649+
"FENCE_ALT_MAX": 50,
1650+
})
1651+
self.wait_altitude(40, 50, timeout=90, relative=True)
1652+
1653+
self.context_pop()
1654+
1655+
self.set_rc(3, 1500)
1656+
self.do_RTL()
1657+
16061658
# fly_alt_min_fence_test - fly down until you hit the fence floor
16071659
def MinAltFence(self):
16081660
'''Test Min Alt Fence'''
@@ -10187,6 +10239,7 @@ def tests1d(self):
1018710239
self.HorizontalFence,
1018810240
self.HorizontalAvoidFence,
1018910241
self.MaxAltFence,
10242+
self.MaxAltFenceAvoid,
1019010243
self.MinAltFence,
1019110244
self.FenceFloorEnabledLanding,
1019210245
self.AutoTuneSwitch,

0 commit comments

Comments
 (0)