@@ -3661,7 +3661,7 @@ def FenceMinAltAutoEnableAbort(self):
3661
3661
def FenceAutoEnableDisableSwitch (self ):
3662
3662
'''Tests autoenablement of regular fences and manual disablement'''
3663
3663
self .set_parameters ({
3664
- "FENCE_TYPE" : 11 , # Set fence type to min alt
3664
+ "FENCE_TYPE" : 9 , # Set fence type to min alt, max alt
3665
3665
"FENCE_ACTION" : 1 , # Set action to RTL
3666
3666
"FENCE_ALT_MIN" : 50 ,
3667
3667
"FENCE_ALT_MAX" : 100 ,
@@ -3672,35 +3672,60 @@ def FenceAutoEnableDisableSwitch(self):
3672
3672
"FENCE_RET_ALT" : 0 ,
3673
3673
"FENCE_RET_RALLY" : 0 ,
3674
3674
"FENCE_TOTAL" : 0 ,
3675
+ "RTL_ALTITUDE" : 75 ,
3675
3676
"TKOFF_ALT" : 75 ,
3676
3677
"RC7_OPTION" : 11 , # AC_Fence uses Aux switch functionality
3677
3678
})
3679
+ self .reboot_sitl ()
3680
+ self .context_collect ("STATUSTEXT" )
3681
+
3678
3682
fence_bit = mavutil .mavlink .MAV_SYS_STATUS_GEOFENCE
3679
3683
# Grab Home Position
3680
3684
self .mav .recv_match (type = 'HOME_POSITION' , blocking = True )
3681
- self .set_rc_from_map ({ 7 : 1000 } ) # Turn fence off with aux function
3685
+ self .set_rc ( 7 , 1000 ) # Turn fence off with aux function, does not impact later auto-enable
3682
3686
3683
3687
self .wait_ready_to_arm ()
3688
+
3689
+ self .progress ("Check fence disabled at boot" )
3690
+ m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3691
+ if (m .onboard_control_sensors_enabled & fence_bit ):
3692
+ raise NotAchievedException ("Fence is enabled at boot" )
3693
+
3684
3694
cruise_alt = 75
3685
3695
self .takeoff (cruise_alt , mode = 'TAKEOFF' )
3686
3696
3687
- self .progress ("Fly above ceiling and check there is no breach" )
3697
+ self .progress ("Fly above ceiling and check there is a breach" )
3698
+ self .change_mode ('FBWA' )
3688
3699
self .set_rc (3 , 2000 )
3689
- self .change_altitude (cruise_alt + 80 , relative = True )
3700
+ self .set_rc (2 , 1000 )
3701
+
3702
+ self .wait_statustext ("Max Alt fence breached" , timeout = 10 , check_context = True )
3703
+ self .wait_mode ('RTL' )
3704
+
3690
3705
m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3691
- self .progress ("Got (%s)" % str (m ))
3692
- if (not (m .onboard_control_sensors_health & fence_bit )):
3693
- raise NotAchievedException ("Fence Ceiling breached" )
3706
+ if (m .onboard_control_sensors_health & fence_bit ):
3707
+ raise NotAchievedException ("Fence ceiling not breached" )
3708
+
3709
+ self .set_rc (3 , 1500 )
3710
+ self .set_rc (2 , 1500 )
3711
+
3712
+ self .progress ("Wait for RTL alt reached" )
3713
+ self .wait_altitude (cruise_alt - 5 , cruise_alt + 5 , relative = True , timeout = 30 )
3694
3714
3695
3715
self .progress ("Return to cruise alt" )
3696
3716
self .set_rc (3 , 1500 )
3697
3717
self .change_altitude (cruise_alt , relative = True )
3698
3718
3719
+ self .progress ("Check fence breach cleared" )
3720
+ m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3721
+ if (not (m .onboard_control_sensors_health & fence_bit )):
3722
+ raise NotAchievedException ("Fence breach not cleared" )
3723
+
3699
3724
self .progress ("Fly below floor and check for breach" )
3700
3725
self .set_rc (2 , 2000 )
3726
+ self .wait_statustext ("Min Alt fence breached" , timeout = 10 , check_context = True )
3701
3727
self .wait_mode ("RTL" )
3702
3728
m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3703
- self .progress ("Got (%s)" % str (m ))
3704
3729
if (m .onboard_control_sensors_health & fence_bit ):
3705
3730
raise NotAchievedException ("Fence floor not breached" )
3706
3731
@@ -3710,10 +3735,26 @@ def FenceAutoEnableDisableSwitch(self):
3710
3735
self .set_rc (3 , 2000 )
3711
3736
self .change_altitude (75 , relative = True )
3712
3737
m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3713
- self .progress ("Got (%s)" % str (m ))
3714
3738
if (not (m .onboard_control_sensors_enabled & fence_bit )):
3715
3739
raise NotAchievedException ("Fence Floor not enabled" )
3716
3740
3741
+ self .progress ("Toggle fence enable/disable" )
3742
+ self .set_rc (7 , 2000 )
3743
+ self .delay_sim_time (2 )
3744
+ self .set_rc (7 , 1000 )
3745
+ self .delay_sim_time (2 )
3746
+
3747
+ self .progress ("Check fence is disabled" )
3748
+ m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3749
+ if (m .onboard_control_sensors_enabled & fence_bit ):
3750
+ raise NotAchievedException ("Fence disable with switch failed" )
3751
+
3752
+ self .progress ("Fly below floor and check for no breach" )
3753
+ self .change_altitude (40 , relative = True )
3754
+ m = self .mav .recv_match (type = 'SYS_STATUS' , blocking = True )
3755
+ if (not (m .onboard_control_sensors_health & fence_bit )):
3756
+ raise NotAchievedException ("Fence floor breached" )
3757
+
3717
3758
self .progress ("Return to cruise alt" )
3718
3759
self .set_rc (3 , 1500 )
3719
3760
self .change_altitude (cruise_alt , relative = True )
0 commit comments