|
|
@ -83,7 +83,7 @@ AP_Terrain::AP_Terrain(AP_AHRS &_ahrs, const AP_Mission &_mission, const AP_Rall |
|
|
|
|
|
|
|
|
|
|
|
This function costs about 20 microseconds on Pixhawk |
|
|
|
This function costs about 20 microseconds on Pixhawk |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool AP_Terrain::height_amsl(const Location &loc, float &height) |
|
|
|
bool AP_Terrain::height_amsl(const Location &loc, float &height, bool corrected) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!enable || !allocate()) { |
|
|
|
if (!enable || !allocate()) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -93,6 +93,10 @@ bool AP_Terrain::height_amsl(const Location &loc, float &height) |
|
|
|
if (loc.lat == home_loc.lat && |
|
|
|
if (loc.lat == home_loc.lat && |
|
|
|
loc.lng == home_loc.lng) { |
|
|
|
loc.lng == home_loc.lng) { |
|
|
|
height = home_height; |
|
|
|
height = home_height; |
|
|
|
|
|
|
|
// apply correction which assumes home altitude is at terrain altitude
|
|
|
|
|
|
|
|
if (corrected) { |
|
|
|
|
|
|
|
height += (ahrs.get_home().alt * 0.01f) - home_height; |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -143,6 +147,11 @@ bool AP_Terrain::height_amsl(const Location &loc, float &height) |
|
|
|
home_loc = loc; |
|
|
|
home_loc = loc; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// apply correction which assumes home altitude is at terrain altitude
|
|
|
|
|
|
|
|
if (corrected) { |
|
|
|
|
|
|
|
height += (ahrs.get_home().alt * 0.01f) - home_height; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -158,7 +167,7 @@ bool AP_Terrain::height_amsl(const Location &loc, float &height) |
|
|
|
bool AP_Terrain::height_terrain_difference_home(float &terrain_difference, bool extrapolate) |
|
|
|
bool AP_Terrain::height_terrain_difference_home(float &terrain_difference, bool extrapolate) |
|
|
|
{ |
|
|
|
{ |
|
|
|
float height_home, height_loc; |
|
|
|
float height_home, height_loc; |
|
|
|
if (!height_amsl(ahrs.get_home(), height_home)) { |
|
|
|
if (!height_amsl(ahrs.get_home(), height_home, false)) { |
|
|
|
// we don't know the height of home
|
|
|
|
// we don't know the height of home
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -169,7 +178,7 @@ bool AP_Terrain::height_terrain_difference_home(float &terrain_difference, bool |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!height_amsl(loc, height_loc)) { |
|
|
|
if (!height_amsl(loc, height_loc, false)) { |
|
|
|
if (!extrapolate || !have_current_loc_height) { |
|
|
|
if (!extrapolate || !have_current_loc_height) { |
|
|
|
// we don't know the height of the given location
|
|
|
|
// we don't know the height of the given location
|
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -260,7 +269,7 @@ float AP_Terrain::lookahead(float bearing, float distance, float climb_ratio) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
float base_height; |
|
|
|
float base_height; |
|
|
|
if (!height_amsl(loc, base_height)) { |
|
|
|
if (!height_amsl(loc, base_height, false)) { |
|
|
|
// we don't know our current terrain height
|
|
|
|
// we don't know our current terrain height
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -274,7 +283,7 @@ float AP_Terrain::lookahead(float bearing, float distance, float climb_ratio) |
|
|
|
climb += climb_ratio * grid_spacing; |
|
|
|
climb += climb_ratio * grid_spacing; |
|
|
|
distance -= grid_spacing; |
|
|
|
distance -= grid_spacing; |
|
|
|
float height; |
|
|
|
float height; |
|
|
|
if (height_amsl(loc, height)) { |
|
|
|
if (height_amsl(loc, height, false)) { |
|
|
|
float rise = (height - base_height) - climb; |
|
|
|
float rise = (height - base_height) - climb; |
|
|
|
if (rise > lookahead_estimate) { |
|
|
|
if (rise > lookahead_estimate) { |
|
|
|
lookahead_estimate = rise; |
|
|
|
lookahead_estimate = rise; |
|
|
@ -298,12 +307,12 @@ void AP_Terrain::update(void) |
|
|
|
|
|
|
|
|
|
|
|
// try to ensure the home location is populated
|
|
|
|
// try to ensure the home location is populated
|
|
|
|
float height; |
|
|
|
float height; |
|
|
|
height_amsl(ahrs.get_home(), height); |
|
|
|
height_amsl(ahrs.get_home(), height, false); |
|
|
|
|
|
|
|
|
|
|
|
// update the cached current location height
|
|
|
|
// update the cached current location height
|
|
|
|
Location loc; |
|
|
|
Location loc; |
|
|
|
bool pos_valid = ahrs.get_position(loc); |
|
|
|
bool pos_valid = ahrs.get_position(loc); |
|
|
|
bool terrain_valid = height_amsl(loc, height); |
|
|
|
bool terrain_valid = height_amsl(loc, height, false); |
|
|
|
if (pos_valid && terrain_valid) { |
|
|
|
if (pos_valid && terrain_valid) { |
|
|
|
last_current_loc_height = height; |
|
|
|
last_current_loc_height = height; |
|
|
|
have_current_loc_height = true; |
|
|
|
have_current_loc_height = true; |
|
|
@ -351,7 +360,7 @@ void AP_Terrain::log_terrain_data(DataFlash_Class &dataflash) |
|
|
|
float current_height = 0; |
|
|
|
float current_height = 0; |
|
|
|
uint16_t pending, loaded; |
|
|
|
uint16_t pending, loaded; |
|
|
|
|
|
|
|
|
|
|
|
height_amsl(loc, terrain_height); |
|
|
|
height_amsl(loc, terrain_height, false); |
|
|
|
height_above_terrain(current_height, true); |
|
|
|
height_above_terrain(current_height, true); |
|
|
|
get_statistics(pending, loaded); |
|
|
|
get_statistics(pending, loaded); |
|
|
|
|
|
|
|
|
|
|
|