Browse Source

AP_Terrain: hold home location as a special location

this ensures home altitude is always available
master
Andrew Tridgell 11 years ago
parent
commit
ee04c7de96
  1. 15
      libraries/AP_Terrain/AP_Terrain.cpp
  2. 4
      libraries/AP_Terrain/AP_Terrain.h

15
libraries/AP_Terrain/AP_Terrain.cpp

@ -201,6 +201,13 @@ bool AP_Terrain::height_amsl(const Location &loc, float &height)
return false; return false;
} }
// quick access for home altitude
if (loc.lat == home_loc.lat &&
loc.lng == home_loc.lng) {
height = home_height;
return true;
}
struct grid_info info; struct grid_info info;
calculate_grid_info(loc, info); calculate_grid_info(loc, info);
@ -237,6 +244,14 @@ bool AP_Terrain::height_amsl(const Location &loc, float &height)
float avg = (1.0f-info.frac_y) * avg1 + info.frac_y * avg2; float avg = (1.0f-info.frac_y) * avg1 + info.frac_y * avg2;
height = avg; height = avg;
if (loc.lat == ahrs.get_home().lat &&
loc.lng == ahrs.get_home().lng) {
// remember home altitude as a special case
home_height = height;
home_loc = loc;
}
return true; return true;
} }

4
libraries/AP_Terrain/AP_Terrain.h

@ -269,6 +269,10 @@ private:
// have we created the terrain directory? // have we created the terrain directory?
bool directory_created; bool directory_created;
// cache the home altitude, as it is needed so often
float home_height;
Location home_loc;
}; };
#endif // HAVE_AP_TERRAIN #endif // HAVE_AP_TERRAIN
#endif // __AP_TERRAIN_H__ #endif // __AP_TERRAIN_H__

Loading…
Cancel
Save