From 4eb78aefdce50326d260a79e400b40405f50c091 Mon Sep 17 00:00:00 2001 From: Rustom Jehangir Date: Tue, 3 May 2016 18:57:47 -0700 Subject: [PATCH] Sub: Add missing terrain.cpp file --- ArduSub/terrain.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ArduSub/terrain.cpp diff --git a/ArduSub/terrain.cpp b/ArduSub/terrain.cpp new file mode 100644 index 0000000000..b40c8ce4fd --- /dev/null +++ b/ArduSub/terrain.cpp @@ -0,0 +1,40 @@ +/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- + +#include "Sub.h" + +// update terrain data +void Sub::terrain_update() +{ +#if AP_TERRAIN_AVAILABLE && AC_TERRAIN + terrain.update(); + + // tell the rangefinder our height, so it can go into power saving + // mode if available +#if CONFIG_SONAR == ENABLED + float height; + if (terrain.height_above_terrain(height, true)) { + sonar.set_estimated_terrain_height(height); + } +#endif +#endif +} + +// log terrain data - should be called at 1hz +void Sub::terrain_logging() +{ +#if AP_TERRAIN_AVAILABLE && AC_TERRAIN + if (should_log(MASK_LOG_GPS)) { + terrain.log_terrain_data(DataFlash); + } +#endif +} + +// should we use terrain data for things including the home altitude +bool Sub::terrain_use() +{ +#if AP_TERRAIN_AVAILABLE && AC_TERRAIN + return (g.terrain_follow > 0); +#else + return false; +#endif +}