@@ -680,12 +680,25 @@ def fly_fence_test(self, timeout=180):
680680 self .wait_heading (160 )
681681 self .set_rc (4 , 1500 )
682682
683- # fly forward (east) at least 20m
683+ fence_radius = self .get_parameter ("FENCE_RADIUS" )
684+
685+ self .progress ("flying forward (east) until we hit fence" )
684686 pitching_forward = True
685687 self .set_rc (2 , 1100 )
686- self .wait_distance (20 )
687688
688- # start timer
689+ self .progress ("Waiting for fence breach" )
690+ tstart = self .get_sim_time ()
691+ while not self .mode_is ("RTL" ):
692+ if self .get_sim_time_cached () - tstart > 30 :
693+ self .NotAchievedException ("Did not breach fence" )
694+
695+ m = self .mav .recv_match (type = 'GLOBAL_POSITION_INT' , blocking = True )
696+ alt = m .relative_alt / 1000.0 # mm -> m
697+ home_distance = self .distance_to_home (use_cached_home = True )
698+ self .progress ("Alt: %.02f HomeDistance: %.02f (fence radius=%f)" %
699+ (alt , home_distance , fence_radius ))
700+
701+ self .progress ("Waiting until we get home and disarm" )
689702 tstart = self .get_sim_time ()
690703 while self .get_sim_time_cached () < tstart + timeout :
691704 m = self .mav .recv_match (type = 'GLOBAL_POSITION_INT' , blocking = True )
@@ -694,7 +707,7 @@ def fly_fence_test(self, timeout=180):
694707 self .progress ("Alt: %.02f HomeDistance: %.02f" %
695708 (alt , home_distance ))
696709 # recenter pitch sticks once we're home so we don't fly off again
697- if pitching_forward and home_distance < 10 :
710+ if pitching_forward and home_distance < 50 :
698711 pitching_forward = False
699712 self .set_rc (2 , 1475 )
700713 # disable fence
@@ -723,8 +736,8 @@ def fly_fence_test(self, timeout=180):
723736 # give we're testing RTL, doing one here probably doesn't make sense
724737 home_distance = self .distance_to_home (use_cached_home = True )
725738 raise AutoTestTimeoutException (
726- ( "Fence test failed to reach home - "
727- "timed out after %u seconds" % timeout ))
739+ "Fence test failed to reach home (%fm distance) - "
740+ "timed out after %u seconds" % ( home_distance , timeout , ))
728741
729742 # fly_alt_fence_test - fly up until you hit the fence
730743 def fly_alt_max_fence_test (self ):
@@ -2920,7 +2933,7 @@ def tests(self):
29202933
29212934 ("HorizontalFence" ,
29222935 "Test horizontal fence" ,
2923- lambda : self .fly_fence_test ( 180 ) ),
2936+ self .fly_fence_test ),
29242937
29252938 ("MaxAltFence" ,
29262939 "Test Max Alt Fence" ,
0 commit comments