Skip to content

Commit

Permalink
Tools: autotest: copter: add test for RTL_ALT_FINAL
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed Feb 9, 2025
1 parent 762ae2f commit db946ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9869,6 +9869,47 @@ def PositionWhenGPSIsZero(self):
self.wait_disarmed()
self.reboot_sitl()

def RTL_ALT_FINAL(self):
'''Test RTL with RTL_ALT_FINAL'''
self.progress("arm the vehicle and takeoff in Guided")
self.takeoff(20, mode='GUIDED')

# Set home current location, this gives a large home vs orgin difference
self.set_home(self.mav.location())

self.progress("fly 50m North (or whatever)")
self.fly_guided_move_local(50, 0, 50)
target_alt = 10
self.set_parameter('RTL_ALT_FINAL', target_alt * 100)

self.progress("Waiting RTL to reach Home and hold")
self.change_mode('RTL')

# Expecting to return and hold 10m above home
tstart = self.get_sim_time()
reachedHome = False
while self.get_sim_time_cached() < tstart + 250:
m = self.mav.recv_match(type='GLOBAL_POSITION_INT', blocking=True)
alt = m.relative_alt / 1000.0 # mm -> m
home_distance = self.distance_to_home(use_cached_home=True)
home = math.sqrt((alt-target_alt)**2 + home_distance**2) < 2
if home and not reachedHome:
reachedHome = True
self.progress("Reached home - holding")
self.delay_sim_time(20)
continue

if reachedHome:
if not home:
raise NotAchievedException("Should still be at home")
if not self.armed():
raise NotAchievedException("Should still be armed")
break

self.progress("Hold at home successful - landing")
self.change_mode("LAND")
self.wait_landed_and_disarmed()

def SMART_RTL(self):
'''Check SMART_RTL'''
self.progress("arm the vehicle and takeoff in Guided")
Expand Down Expand Up @@ -12684,6 +12725,7 @@ def tests2b(self): # this block currently around 9.5mins here
self.GSF,
self.GSF_reset,
self.AP_Avoidance,
self.RTL_ALT_FINAL,
self.SMART_RTL,
self.SMART_RTL_EnterLeave,
self.SMART_RTL_Repeat,
Expand Down

0 comments on commit db946ef

Please sign in to comment.