@@ -1603,6 +1603,58 @@ def MaxAltFence(self):
1603
1603
1604
1604
self .zero_throttle ()
1605
1605
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
+
1606
1658
# fly_alt_min_fence_test - fly down until you hit the fence floor
1607
1659
def MinAltFence (self ):
1608
1660
'''Test Min Alt Fence'''
@@ -10187,6 +10239,7 @@ def tests1d(self):
10187
10239
self .HorizontalFence ,
10188
10240
self .HorizontalAvoidFence ,
10189
10241
self .MaxAltFence ,
10242
+ self .MaxAltFenceAvoid ,
10190
10243
self .MinAltFence ,
10191
10244
self .FenceFloorEnabledLanding ,
10192
10245
self .AutoTuneSwitch ,
0 commit comments