diff --git a/MAVProxy/modules/mavproxy_console.py b/MAVProxy/modules/mavproxy_console.py index 86c2aa90e0..a531959c5a 100644 --- a/MAVProxy/modules/mavproxy_console.py +++ b/MAVProxy/modules/mavproxy_console.py @@ -97,6 +97,8 @@ def __init__(self, mpstate): self.vehicle_menu = MPMenuSubMenu('Vehicle', items=[]) self.add_menu(self.vehicle_menu) + self.shown_agl = False + def cmd_console(self, args): usage = 'usage: console ' if len(args) < 1: @@ -389,28 +391,35 @@ def handle_vfr_hud(self, msg): lng = master.field('GLOBAL_POSITION_INT', 'lon', 0) * 1.0e-7 rel_alt = master.field('GLOBAL_POSITION_INT', 'relative_alt', 0) * 1.0e-3 agl_alt = None - if self.settings.basealt != 0: - agl_alt = self.module('terrain').ElevationModel.GetElevation(lat, lng) - if agl_alt is not None: - agl_alt = self.settings.basealt - agl_alt - else: - try: - agl_alt_home = self.module('terrain').ElevationModel.GetElevation(home_lat, home_lng) - except Exception as ex: - print(ex) - agl_alt_home = None - if agl_alt_home is not None: - agl_alt = self.module('terrain').ElevationModel.GetElevation(lat, lng) + if self.module('terrain') is not None: + elevation_model = self.module('terrain').ElevationModel + if self.settings.basealt != 0: + agl_alt = elevation_model.GetElevation(lat, lng) + if agl_alt is not None: + agl_alt = self.settings.basealt - agl_alt + else: + try: + agl_alt_home = elevation_model.GetElevation(home_lat, home_lng) + except Exception as ex: + print(ex) + agl_alt_home = None + if agl_alt_home is not None: + agl_alt = elevation_model.GetElevation(lat, lng) + if agl_alt is not None: + agl_alt = agl_alt_home - agl_alt + vehicle_agl = master.field('TERRAIN_REPORT', 'current_height', None) + if agl_alt is not None or vehicle_agl is not None or self.shown_agl: + self.shown_agl = True if agl_alt is not None: - agl_alt = agl_alt_home - agl_alt - if agl_alt is not None: - agl_alt += rel_alt - vehicle_agl = master.field('TERRAIN_REPORT', 'current_height', None) + agl_alt += rel_alt + agl_alt = self.height_string(agl_alt) + else: + agl_alt = "---" if vehicle_agl is None: vehicle_agl = '---' else: vehicle_agl = self.height_string(vehicle_agl) - self.console.set_status('AGL', 'AGL %s/%s' % (self.height_string(agl_alt), vehicle_agl)) + self.console.set_status('AGL', 'AGL %s/%s' % (agl_alt, vehicle_agl)) self.console.set_status('Alt', 'Alt %s' % self.height_string(rel_alt)) self.console.set_status('AirSpeed', 'AirSpeed %s' % self.speed_string(msg.airspeed)) self.console.set_status('GPSSpeed', 'GPSSpeed %s' % self.speed_string(msg.groundspeed))