mirror of https://github.com/ArduPilot/ardupilot
AP_Terrain: cache status
instead of computing the terrain status on-demand, assign it in update() and cache the result. Then external tasks that check the status won't be doing terrain intensive calculations in their thread. All the calculations needed for the status were being performed in update already so this is an optimization.
This commit is contained in:
parent
3d8211696c
commit
73c5234633
|
@ -302,7 +302,9 @@ void AP_Terrain::update(void)
|
|||
|
||||
// update the cached current location height
|
||||
Location loc;
|
||||
if (ahrs.get_position(loc) && height_amsl(loc, height)) {
|
||||
bool pos_valid = ahrs.get_position(loc);
|
||||
bool terrain_valid = height_amsl(loc, height);
|
||||
if (pos_valid && terrain_valid) {
|
||||
last_current_loc_height = height;
|
||||
have_current_loc_height = true;
|
||||
}
|
||||
|
@ -313,33 +315,23 @@ void AP_Terrain::update(void)
|
|||
// check for pending rally data
|
||||
update_rally_data();
|
||||
|
||||
// update capabilities
|
||||
// update capabilities and status
|
||||
if (enable) {
|
||||
hal.util->set_capabilities(MAV_PROTOCOL_CAPABILITY_TERRAIN);
|
||||
if (!pos_valid) {
|
||||
// we don't know where we are
|
||||
system_status = TerrainStatusUnhealthy;
|
||||
} else if (!terrain_valid) {
|
||||
// we don't have terrain data at current location
|
||||
system_status = TerrainStatusUnhealthy;
|
||||
} else {
|
||||
system_status = TerrainStatusOK;
|
||||
}
|
||||
} else {
|
||||
hal.util->clear_capabilities(MAV_PROTOCOL_CAPABILITY_TERRAIN);
|
||||
system_status = TerrainStatusDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
return status enum for health reporting
|
||||
*/
|
||||
enum AP_Terrain::TerrainStatus AP_Terrain::status(void)
|
||||
{
|
||||
if (!enable) {
|
||||
return TerrainStatusDisabled;
|
||||
}
|
||||
Location loc;
|
||||
if (!ahrs.get_position(loc)) {
|
||||
// we don't know where we are
|
||||
return TerrainStatusUnhealthy;
|
||||
}
|
||||
float height;
|
||||
if (!height_amsl(loc, height)) {
|
||||
// we don't have terrain data at current location
|
||||
return TerrainStatusUnhealthy;
|
||||
}
|
||||
return TerrainStatusOK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
void update(void);
|
||||
|
||||
// return status enum for health reporting
|
||||
enum TerrainStatus status(void);
|
||||
enum TerrainStatus status(void) const { return system_status; }
|
||||
|
||||
// send any pending terrain request message
|
||||
void send_request(mavlink_channel_t chan);
|
||||
|
@ -405,6 +405,9 @@ private:
|
|||
uint16_t last_rally_spacing;
|
||||
|
||||
char *file_path = NULL;
|
||||
|
||||
// status
|
||||
enum TerrainStatus system_status = TerrainStatusDisabled;
|
||||
};
|
||||
#endif // AP_TERRAIN_AVAILABLE
|
||||
#endif // __AP_TERRAIN_H__
|
||||
|
|
Loading…
Reference in New Issue