Skip to content

Commit

Permalink
mavproxy_console: avoid exceptions when terrain module unloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Nov 10, 2024
1 parent 1524e25 commit 3d29489
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions MAVProxy/modules/mavproxy_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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 <add|list|remove|menu|set>'
if len(args) < 1:
Expand Down Expand Up @@ -391,28 +393,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))
Expand Down

0 comments on commit 3d29489

Please sign in to comment.