Checking for climb rate

This commit is contained in:
Jason Short 2011-11-19 14:03:08 -08:00
parent 014204409a
commit fe9705adbc
1 changed files with 7 additions and 1 deletions

View File

@ -63,12 +63,18 @@ def current_location(mav):
mav.messages['VFR_HUD'].alt) mav.messages['VFR_HUD'].alt)
def wait_altitude(mav, alt_min, alt_max, timeout=30): def wait_altitude(mav, alt_min, alt_max, timeout=30):
climb_rate = 0
previous_alt = 0
'''wait for a given altitude range''' '''wait for a given altitude range'''
tstart = time.time() tstart = time.time()
print("Waiting for altitude between %u and %u" % (alt_min, alt_max)) print("Waiting for altitude between %u and %u" % (alt_min, alt_max))
while time.time() < tstart + timeout: while time.time() < tstart + timeout:
m = mav.recv_match(type='VFR_HUD', blocking=True) m = mav.recv_match(type='VFR_HUD', blocking=True)
print("Altitude %u" % m.alt) climb_rate = m.alt - previous_alt
previous_alt = m.alt
print("Altitude %u, rate: %u" % (m.alt, climb_rate))
if abs(climb_rate) > 0:
tstart = time.time();
if m.alt >= alt_min and m.alt <= alt_max: if m.alt >= alt_min and m.alt <= alt_max:
return True return True
print("Failed to attain altitude range") print("Failed to attain altitude range")