From c32595e6eda8ba4fb1e89c47931d1dda460d5633 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 24 Jul 2014 20:16:03 +1000 Subject: [PATCH] AP_Terrain: added status() interface for reporting --- libraries/AP_Terrain/AP_Terrain.cpp | 21 +++++++++++++++++++++ libraries/AP_Terrain/AP_Terrain.h | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/libraries/AP_Terrain/AP_Terrain.cpp b/libraries/AP_Terrain/AP_Terrain.cpp index b8c05c87f7..2c14fb05fb 100644 --- a/libraries/AP_Terrain/AP_Terrain.cpp +++ b/libraries/AP_Terrain/AP_Terrain.cpp @@ -262,4 +262,25 @@ void AP_Terrain::update(void) height_amsl(ahrs.get_home(), height); } +/* + 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; +} + #endif // HAVE_AP_TERRAIN diff --git a/libraries/AP_Terrain/AP_Terrain.h b/libraries/AP_Terrain/AP_Terrain.h index 7d4202e313..a55566d4ae 100644 --- a/libraries/AP_Terrain/AP_Terrain.h +++ b/libraries/AP_Terrain/AP_Terrain.h @@ -83,11 +83,20 @@ public: AP_Int8 enable; AP_Int16 grid_spacing; // meters between grid points + enum TerrainStatus { + TerrainStatusDisabled = 0, // not enabled + TerrainStatusUnhealthy = 1, // no terrain data for current location + TerrainStatusOK = 2 // terrain data available + }; + static const struct AP_Param::GroupInfo var_info[]; // update terrain state. Should be called at 1Hz or more void update(void); + // return status enum for health reporting + enum TerrainStatus status(void); + // send any pending terrain request message void send_request(mavlink_channel_t chan);