Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavproxy_console: avoid exceptions when terrain module unloaded #1449

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions MAVProxy/modules/mavproxy_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <add|list|remove|menu|set>'
if len(args) < 1:
Expand Down Expand Up @@ -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))
Expand Down