@@ -99,6 +99,8 @@ def __init__(self, mpstate):
99
99
self .vehicle_menu = MPMenuSubMenu ('Vehicle' , items = [])
100
100
self .add_menu (self .vehicle_menu )
101
101
102
+ self .shown_agl = False
103
+
102
104
def cmd_console (self , args ):
103
105
usage = 'usage: console <add|list|remove|menu|set>'
104
106
if len (args ) < 1 :
@@ -391,28 +393,35 @@ def handle_vfr_hud(self, msg):
391
393
lng = master .field ('GLOBAL_POSITION_INT' , 'lon' , 0 ) * 1.0e-7
392
394
rel_alt = master .field ('GLOBAL_POSITION_INT' , 'relative_alt' , 0 ) * 1.0e-3
393
395
agl_alt = None
394
- if self .settings .basealt != 0 :
395
- agl_alt = self .module ('terrain' ).ElevationModel .GetElevation (lat , lng )
396
- if agl_alt is not None :
397
- agl_alt = self .settings .basealt - agl_alt
398
- else :
399
- try :
400
- agl_alt_home = self .module ('terrain' ).ElevationModel .GetElevation (home_lat , home_lng )
401
- except Exception as ex :
402
- print (ex )
403
- agl_alt_home = None
404
- if agl_alt_home is not None :
405
- agl_alt = self .module ('terrain' ).ElevationModel .GetElevation (lat , lng )
396
+ if self .module ('terrain' ) is not None :
397
+ elevation_model = self .module ('terrain' ).ElevationModel
398
+ if self .settings .basealt != 0 :
399
+ agl_alt = elevation_model .GetElevation (lat , lng )
400
+ if agl_alt is not None :
401
+ agl_alt = self .settings .basealt - agl_alt
402
+ else :
403
+ try :
404
+ agl_alt_home = elevation_model .GetElevation (home_lat , home_lng )
405
+ except Exception as ex :
406
+ print (ex )
407
+ agl_alt_home = None
408
+ if agl_alt_home is not None :
409
+ agl_alt = elevation_model .GetElevation (lat , lng )
410
+ if agl_alt is not None :
411
+ agl_alt = agl_alt_home - agl_alt
412
+ vehicle_agl = master .field ('TERRAIN_REPORT' , 'current_height' , None )
413
+ if agl_alt is not None or vehicle_agl is not None or self .shown_agl :
414
+ self .shown_agl = True
406
415
if agl_alt is not None :
407
- agl_alt = agl_alt_home - agl_alt
408
- if agl_alt is not None :
409
- agl_alt += rel_alt
410
- vehicle_agl = master . field ( 'TERRAIN_REPORT' , 'current_height' , None )
416
+ agl_alt += rel_alt
417
+ agl_alt = self . height_string ( agl_alt )
418
+ else :
419
+ agl_alt = "---"
411
420
if vehicle_agl is None :
412
421
vehicle_agl = '---'
413
422
else :
414
423
vehicle_agl = self .height_string (vehicle_agl )
415
- self .console .set_status ('AGL' , 'AGL %s/%s' % (self . height_string ( agl_alt ) , vehicle_agl ))
424
+ self .console .set_status ('AGL' , 'AGL %s/%s' % (agl_alt , vehicle_agl ))
416
425
self .console .set_status ('Alt' , 'Alt %s' % self .height_string (rel_alt ))
417
426
self .console .set_status ('AirSpeed' , 'AirSpeed %s' % self .speed_string (msg .airspeed ))
418
427
self .console .set_status ('GPSSpeed' , 'GPSSpeed %s' % self .speed_string (msg .groundspeed ))
0 commit comments