AP_Terrain: added terrain lookahead API

this allows for predicting altitude needed to climb over upcoming
terrain
This commit is contained in:
Andrew Tridgell 2014-08-07 09:30:35 +10:00
parent b92873cab1
commit dc72dfb70a
2 changed files with 49 additions and 0 deletions

View File

@ -241,6 +241,49 @@ bool AP_Terrain::height_relative_home_equivalent(float terrain_altitude,
return true;
}
/*
calculate lookahead rise in terrain. This returns extra altitude
needed to clear upcoming terrain in meters
*/
float AP_Terrain::lookahead(float bearing, float distance, float climb_ratio)
{
if (!enable || grid_spacing <= 0) {
return 0;
}
Location loc;
if (!ahrs.get_position(loc)) {
// we don't know where we are
return 0;
}
float base_height;
if (!height_amsl(loc, base_height)) {
// we don't know our current terrain height
return 0;
}
float climb = 0;
float lookahead_estimate = 0;
// check for terrain at grid spacing intervals
while (distance > 0) {
location_update(loc, bearing, grid_spacing);
climb += climb_ratio * grid_spacing;
distance -= grid_spacing;
float height;
if (height_amsl(loc, height)) {
float rise = (height - base_height) - climb;
if (rise > lookahead_estimate) {
lookahead_estimate = rise;
}
}
}
return lookahead_estimate;
}
/*
1hz update function. This is here to ensure progress is made on disk
IO even if no MAVLink send_request() operations are called for a

View File

@ -154,6 +154,12 @@ public:
*/
bool height_above_terrain(float &terrain_altitude, bool extrapolate = false);
/*
calculate lookahead rise in terrain. This returns extra altitude
needed to clear upcoming terrain in meters
*/
float lookahead(float bearing, float distance, float climb_ratio);
/*
log terrain status to DataFlash
*/