2014-06-30 19:51:59 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-02-17 21:25:51 -04:00
|
|
|
#pragma once
|
2014-06-30 19:51:59 -03:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2019-04-05 03:11:27 -03:00
|
|
|
#include <AP_Common/Location.h>
|
2019-10-12 01:36:20 -03:00
|
|
|
#include <AP_Filesystem/AP_Filesystem_Available.h>
|
2014-07-21 19:23:35 -03:00
|
|
|
|
2019-08-01 02:13:49 -03:00
|
|
|
#if HAVE_FILESYSTEM_SUPPORT && defined(HAL_BOARD_TERRAIN_DIRECTORY)
|
2014-07-24 18:56:55 -03:00
|
|
|
#define AP_TERRAIN_AVAILABLE 1
|
2014-07-21 19:23:35 -03:00
|
|
|
#else
|
2014-07-24 18:56:55 -03:00
|
|
|
#define AP_TERRAIN_AVAILABLE 0
|
2014-07-21 19:23:35 -03:00
|
|
|
#endif
|
|
|
|
|
2014-07-24 18:56:55 -03:00
|
|
|
#if AP_TERRAIN_AVAILABLE
|
2014-07-21 19:23:35 -03:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Mission/AP_Mission.h>
|
2014-07-23 08:02:50 -03:00
|
|
|
|
|
|
|
#define TERRAIN_DEBUG 0
|
|
|
|
|
2014-06-30 19:51:59 -03:00
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// MAVLink sends 4x4 grids
|
|
|
|
#define TERRAIN_GRID_MAVLINK_SIZE 4
|
2014-07-01 00:56:18 -03:00
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// a 2k grid_block on disk contains 8x7 of the mavlink grids. Each
|
|
|
|
// grid block overlaps by one with its neighbour. This ensures that
|
|
|
|
// the altitude at any point can be calculated from a single grid
|
|
|
|
// block
|
|
|
|
#define TERRAIN_GRID_BLOCK_MUL_X 7
|
|
|
|
#define TERRAIN_GRID_BLOCK_MUL_Y 8
|
2014-07-01 00:56:18 -03:00
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// this is the spacing between 32x28 grid blocks, in grid_spacing units
|
|
|
|
#define TERRAIN_GRID_BLOCK_SPACING_X ((TERRAIN_GRID_BLOCK_MUL_X-1)*TERRAIN_GRID_MAVLINK_SIZE)
|
|
|
|
#define TERRAIN_GRID_BLOCK_SPACING_Y ((TERRAIN_GRID_BLOCK_MUL_Y-1)*TERRAIN_GRID_MAVLINK_SIZE)
|
|
|
|
|
|
|
|
// giving a total grid size of a disk grid_block of 32x28
|
|
|
|
#define TERRAIN_GRID_BLOCK_SIZE_X (TERRAIN_GRID_MAVLINK_SIZE*TERRAIN_GRID_BLOCK_MUL_X)
|
|
|
|
#define TERRAIN_GRID_BLOCK_SIZE_Y (TERRAIN_GRID_MAVLINK_SIZE*TERRAIN_GRID_BLOCK_MUL_Y)
|
2014-07-01 00:56:18 -03:00
|
|
|
|
|
|
|
// number of grid_blocks in the LRU memory cache
|
2014-07-21 19:23:35 -03:00
|
|
|
#define TERRAIN_GRID_BLOCK_CACHE_SIZE 12
|
|
|
|
|
|
|
|
// format of grid on disk
|
|
|
|
#define TERRAIN_GRID_FORMAT_VERSION 1
|
|
|
|
|
2020-05-01 22:52:00 -03:00
|
|
|
// we allow for a 2cm discrepancy in the grid corners. This is to
|
|
|
|
// account for different rounding in terrain DAT file generators using
|
|
|
|
// different programming languages
|
|
|
|
#define TERRAIN_LATLON_EQUAL(v1, v2) (labs((v1)-(v2)) <= 2)
|
|
|
|
|
2014-07-23 08:02:50 -03:00
|
|
|
#if TERRAIN_DEBUG
|
2020-05-01 22:52:00 -03:00
|
|
|
#include <assert.h>
|
2014-07-23 08:02:50 -03:00
|
|
|
#define ASSERT_RANGE(v,minv,maxv) assert((v)<=(maxv)&&(v)>=(minv))
|
|
|
|
#else
|
|
|
|
#define ASSERT_RANGE(v,minv,maxv)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
/*
|
|
|
|
Data conventions in this library:
|
|
|
|
|
|
|
|
array[x][y]: x is increasing north, y is increasing east
|
|
|
|
array[x]: low order bits increase east first
|
|
|
|
bitmap: low order bits increase east first
|
2014-07-21 22:28:54 -03:00
|
|
|
file: first entries increase east, then north
|
2014-07-21 19:23:35 -03:00
|
|
|
*/
|
2014-07-01 00:56:18 -03:00
|
|
|
|
2017-08-29 21:02:24 -03:00
|
|
|
class AP_Terrain {
|
2014-06-30 19:51:59 -03:00
|
|
|
public:
|
2019-01-08 07:42:29 -04:00
|
|
|
AP_Terrain(const AP_Mission &_mission);
|
2017-12-12 21:06:14 -04:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_Terrain(const AP_Terrain &other) = delete;
|
|
|
|
AP_Terrain &operator=(const AP_Terrain&) = delete;
|
|
|
|
|
2019-04-24 00:19:53 -03:00
|
|
|
static AP_Terrain *get_singleton(void) { return singleton; }
|
|
|
|
|
2014-07-24 07:16:03 -03:00
|
|
|
enum TerrainStatus {
|
|
|
|
TerrainStatusDisabled = 0, // not enabled
|
|
|
|
TerrainStatusUnhealthy = 1, // no terrain data for current location
|
|
|
|
TerrainStatusOK = 2 // terrain data available
|
|
|
|
};
|
|
|
|
|
2014-06-30 19:51:59 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2017-08-29 21:02:24 -03:00
|
|
|
|
2014-06-30 19:51:59 -03:00
|
|
|
// update terrain state. Should be called at 1Hz or more
|
|
|
|
void update(void);
|
|
|
|
|
2018-03-28 22:04:27 -03:00
|
|
|
bool enabled() const { return enable; }
|
|
|
|
|
2014-07-24 07:16:03 -03:00
|
|
|
// return status enum for health reporting
|
2015-10-15 14:23:31 -03:00
|
|
|
enum TerrainStatus status(void) const { return system_status; }
|
2014-07-24 07:16:03 -03:00
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// send any pending terrain request message
|
|
|
|
void send_request(mavlink_channel_t chan);
|
|
|
|
|
2014-07-22 05:06:14 -03:00
|
|
|
// handle terrain data and reports from GCS
|
2014-08-05 22:43:37 -03:00
|
|
|
void send_terrain_report(mavlink_channel_t chan, const Location &loc, bool extrapolate);
|
2019-04-30 07:22:49 -03:00
|
|
|
void handle_data(mavlink_channel_t chan, const mavlink_message_t &msg);
|
|
|
|
void handle_terrain_check(mavlink_channel_t chan, const mavlink_message_t &msg);
|
|
|
|
void handle_terrain_data(const mavlink_message_t &msg);
|
2014-07-21 19:23:35 -03:00
|
|
|
|
2016-03-28 21:30:57 -03:00
|
|
|
/*
|
|
|
|
find the terrain height in meters above sea level for a location
|
|
|
|
|
|
|
|
return false if not available
|
|
|
|
|
|
|
|
if corrected is true then terrain alt is adjusted so that
|
|
|
|
the terrain altitude matches the home altitude at the home location
|
|
|
|
(i.e. we assume home is at the terrain altitude)
|
|
|
|
*/
|
|
|
|
bool height_amsl(const Location &loc, float &height, bool corrected);
|
2014-06-30 21:55:00 -03:00
|
|
|
|
2014-07-23 08:41:56 -03:00
|
|
|
/*
|
|
|
|
find difference between home terrain height and the terrain
|
2014-08-05 22:43:37 -03:00
|
|
|
height at the current location in meters. A positive result
|
|
|
|
means the terrain is higher than home.
|
2014-07-23 08:41:56 -03:00
|
|
|
|
2014-08-05 22:43:37 -03:00
|
|
|
return false is terrain at the current location or at home
|
2014-07-23 08:41:56 -03:00
|
|
|
location is not available
|
2014-08-05 22:43:37 -03:00
|
|
|
|
|
|
|
If extrapolate is true then allow return of an extrapolated
|
|
|
|
terrain altitude based on the last available data
|
2014-07-23 08:41:56 -03:00
|
|
|
*/
|
2014-08-05 22:43:37 -03:00
|
|
|
bool height_terrain_difference_home(float &terrain_difference,
|
|
|
|
bool extrapolate = false);
|
2014-07-23 08:41:56 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
return estimated equivalent relative-to-home altitude in meters
|
2014-08-05 22:43:37 -03:00
|
|
|
of a given height above the terrain at the current location
|
2014-07-23 08:41:56 -03:00
|
|
|
|
|
|
|
This function allows existing height controllers which work on
|
|
|
|
barometric altitude (relative to home) to be used with terrain
|
|
|
|
based target altitude, by translating the "above terrain" altitude
|
|
|
|
into an equivalent barometric relative height.
|
|
|
|
|
|
|
|
return false if terrain data is not available either at the given
|
|
|
|
location or at the home location.
|
|
|
|
|
2014-08-05 22:43:37 -03:00
|
|
|
If extrapolate is true then allow return of an extrapolated
|
|
|
|
terrain altitude based on the last available data
|
2014-07-23 08:41:56 -03:00
|
|
|
*/
|
2014-08-05 22:43:37 -03:00
|
|
|
bool height_relative_home_equivalent(float terrain_altitude,
|
|
|
|
float &relative_altitude,
|
|
|
|
bool extrapolate = false);
|
2014-07-24 03:28:40 -03:00
|
|
|
|
|
|
|
/*
|
2019-11-10 22:36:12 -04:00
|
|
|
return current height above terrain at current AHRS position.
|
2014-07-23 08:41:56 -03:00
|
|
|
|
2014-08-05 22:43:37 -03:00
|
|
|
If extrapolate is true then extrapolate from most recently
|
2019-11-10 22:36:12 -04:00
|
|
|
available terrain data if terrain data is not available for the
|
2014-08-05 22:43:37 -03:00
|
|
|
current location.
|
|
|
|
|
|
|
|
Return true if height is available, otherwise false.
|
2014-07-24 05:34:21 -03:00
|
|
|
*/
|
2014-08-05 22:43:37 -03:00
|
|
|
bool height_above_terrain(float &terrain_altitude, bool extrapolate = false);
|
2014-07-24 05:34:21 -03:00
|
|
|
|
2014-08-06 20:30:35 -03:00
|
|
|
/*
|
|
|
|
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);
|
|
|
|
|
2014-08-05 23:16:29 -03:00
|
|
|
/*
|
2019-01-18 00:23:42 -04:00
|
|
|
log terrain status to AP_Logger
|
2014-08-05 23:16:29 -03:00
|
|
|
*/
|
2019-01-17 19:17:17 -04:00
|
|
|
void log_terrain_data();
|
2014-08-05 23:16:29 -03:00
|
|
|
|
2016-03-16 21:21:01 -03:00
|
|
|
/*
|
|
|
|
get some statistics for TERRAIN_REPORT
|
|
|
|
*/
|
2019-11-06 22:02:23 -04:00
|
|
|
void get_statistics(uint16_t &pending, uint16_t &loaded) const;
|
2016-03-16 21:21:01 -03:00
|
|
|
|
2019-11-06 22:03:40 -04:00
|
|
|
/*
|
|
|
|
returns true if initialisation failed because out-of-memory
|
|
|
|
*/
|
|
|
|
bool init_failed() const { return memory_alloc_failed; }
|
|
|
|
|
2014-06-30 19:51:59 -03:00
|
|
|
private:
|
|
|
|
// allocate the terrain subsystem data
|
2015-09-22 19:31:17 -03:00
|
|
|
bool allocate(void);
|
2014-06-30 19:51:59 -03:00
|
|
|
|
2014-07-01 00:56:18 -03:00
|
|
|
/*
|
|
|
|
a grid block is a structure in a local file containing height
|
|
|
|
information. Each grid block is 2048 in size, to keep file IO to
|
|
|
|
block oriented SD cards efficient
|
|
|
|
*/
|
|
|
|
struct PACKED grid_block {
|
2014-07-21 22:28:54 -03:00
|
|
|
// bitmap of 4x4 grids filled in from GCS (56 bits are used)
|
|
|
|
uint64_t bitmap;
|
|
|
|
|
|
|
|
// south west corner of block in degrees*10^7
|
|
|
|
int32_t lat;
|
|
|
|
int32_t lon;
|
|
|
|
|
2014-07-01 00:56:18 -03:00
|
|
|
// crc of whole block, taken with crc=0
|
|
|
|
uint16_t crc;
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// format version number
|
|
|
|
uint16_t version;
|
|
|
|
|
2014-07-01 00:56:18 -03:00
|
|
|
// grid spacing in meters
|
|
|
|
uint16_t spacing;
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// heights in meters over a 32*28 grid
|
|
|
|
int16_t height[TERRAIN_GRID_BLOCK_SIZE_X][TERRAIN_GRID_BLOCK_SIZE_Y];
|
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
// indices info 32x28 grids for this degree reference
|
|
|
|
uint16_t grid_idx_x;
|
|
|
|
uint16_t grid_idx_y;
|
2014-07-01 00:56:18 -03:00
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
// rounded latitude/longitude in degrees.
|
|
|
|
int16_t lon_degrees;
|
|
|
|
int8_t lat_degrees;
|
2014-07-21 19:23:35 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
grid_block for disk IO, aligned on 2048 byte boundaries
|
|
|
|
*/
|
|
|
|
union grid_io_block {
|
2014-07-21 22:28:54 -03:00
|
|
|
struct grid_block block;
|
2014-07-21 19:23:35 -03:00
|
|
|
uint8_t buffer[2048];
|
|
|
|
};
|
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
enum GridCacheState {
|
|
|
|
GRID_CACHE_INVALID=0, // when first initialised
|
|
|
|
GRID_CACHE_DISKWAIT=1, // when waiting for disk read
|
|
|
|
GRID_CACHE_VALID=2, // when at least partially valid
|
|
|
|
GRID_CACHE_DIRTY=3 // when updates have been made, and
|
|
|
|
// disk write needed
|
|
|
|
};
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
/*
|
|
|
|
a grid_block plus some meta data used for requesting new blocks
|
|
|
|
*/
|
|
|
|
struct grid_cache {
|
|
|
|
struct grid_block grid;
|
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
volatile enum GridCacheState state;
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// the last time access was requested to this block, used for LRU
|
|
|
|
uint32_t last_access_ms;
|
2014-07-01 00:56:18 -03:00
|
|
|
};
|
|
|
|
|
2014-06-30 21:55:00 -03:00
|
|
|
/*
|
|
|
|
grid_info is a broken down representation of a Location, giving
|
|
|
|
the index terms for finding the right grid
|
|
|
|
*/
|
|
|
|
struct grid_info {
|
|
|
|
// rounded latitude/longitude in degrees.
|
|
|
|
int8_t lat_degrees;
|
2014-07-21 19:23:35 -03:00
|
|
|
int16_t lon_degrees;
|
2014-06-30 21:55:00 -03:00
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// lat and lon of SW corner of this 32*28 grid, *10^7 degrees
|
2014-06-30 21:55:00 -03:00
|
|
|
int32_t grid_lat;
|
|
|
|
int32_t grid_lon;
|
2014-07-01 00:56:18 -03:00
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
// indices info 32x28 grids for this degree reference
|
|
|
|
uint16_t grid_idx_x;
|
|
|
|
uint16_t grid_idx_y;
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// indexes into 32x28 grid
|
|
|
|
uint8_t idx_x; // north (0..27)
|
|
|
|
uint8_t idx_y; // east (0..31)
|
2014-07-01 00:56:18 -03:00
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
// fraction within the grid square
|
|
|
|
float frac_x; // north (0..1)
|
|
|
|
float frac_y; // east (0..1)
|
2014-07-21 22:28:54 -03:00
|
|
|
|
|
|
|
// file offset of this grid
|
|
|
|
uint32_t file_offset;
|
2014-06-30 21:55:00 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// given a location, fill a grid_info structure
|
|
|
|
void calculate_grid_info(const Location &loc, struct grid_info &info) const;
|
|
|
|
|
2014-07-21 19:23:35 -03:00
|
|
|
/*
|
|
|
|
find a grid structure given a grid_info
|
|
|
|
*/
|
2014-07-24 20:52:20 -03:00
|
|
|
struct grid_cache &find_grid_cache(const struct grid_info &info);
|
2014-07-21 19:23:35 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
calculate bit number in grid_block bitmap. This corresponds to a
|
|
|
|
bit representing a 4x4 mavlink transmitted block
|
|
|
|
*/
|
|
|
|
uint8_t grid_bitnum(uint8_t idx_x, uint8_t idx_y);
|
|
|
|
|
|
|
|
/*
|
|
|
|
given a grid_info check that a given idx_x/idx_y is available (set
|
|
|
|
in the bitmap)
|
|
|
|
*/
|
|
|
|
bool check_bitmap(const struct grid_block &grid, uint8_t idx_x, uint8_t idx_y);
|
|
|
|
|
|
|
|
/*
|
|
|
|
request any missing 4x4 grids from a block
|
|
|
|
*/
|
2014-07-22 05:06:14 -03:00
|
|
|
bool request_missing(mavlink_channel_t chan, struct grid_cache &gcache);
|
2014-07-21 19:23:35 -03:00
|
|
|
bool request_missing(mavlink_channel_t chan, const struct grid_info &info);
|
2014-06-30 21:55:00 -03:00
|
|
|
|
2014-07-22 23:19:29 -03:00
|
|
|
/*
|
|
|
|
look for blocks that need to be read/written to disk
|
|
|
|
*/
|
|
|
|
void schedule_disk_io(void);
|
|
|
|
|
2014-07-22 05:06:14 -03:00
|
|
|
/*
|
|
|
|
get some statistics for TERRAIN_REPORT
|
|
|
|
*/
|
2019-11-06 22:02:23 -04:00
|
|
|
uint8_t bitcount64(uint64_t b) const;
|
2014-07-22 05:06:14 -03:00
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
/*
|
|
|
|
disk IO functions
|
|
|
|
*/
|
2014-07-22 06:38:20 -03:00
|
|
|
int16_t find_io_idx(enum GridCacheState state);
|
2014-07-22 06:23:04 -03:00
|
|
|
uint16_t get_block_crc(struct grid_block &block);
|
2014-07-21 22:28:54 -03:00
|
|
|
void check_disk_read(void);
|
|
|
|
void check_disk_write(void);
|
|
|
|
void io_timer(void);
|
|
|
|
void open_file(void);
|
|
|
|
void seek_offset(void);
|
2020-05-01 22:52:00 -03:00
|
|
|
uint32_t east_blocks(struct grid_block &block) const;
|
2014-07-21 22:28:54 -03:00
|
|
|
void write_block(void);
|
|
|
|
void read_block(void);
|
|
|
|
|
2014-08-06 03:17:39 -03:00
|
|
|
/*
|
2014-08-06 03:36:02 -03:00
|
|
|
check for missing mission terrain data
|
2014-08-06 03:17:39 -03:00
|
|
|
*/
|
|
|
|
void update_mission_data(void);
|
|
|
|
|
2014-08-06 03:36:02 -03:00
|
|
|
/*
|
|
|
|
check for missing rally data
|
|
|
|
*/
|
|
|
|
void update_rally_data(void);
|
|
|
|
|
|
|
|
|
2014-07-24 20:45:28 -03:00
|
|
|
// parameters
|
|
|
|
AP_Int8 enable;
|
|
|
|
AP_Int16 grid_spacing; // meters between grid points
|
2020-05-01 22:52:00 -03:00
|
|
|
AP_Int16 options; // option bits
|
|
|
|
|
|
|
|
enum class Options {
|
|
|
|
DisableDownload = (1U<<0),
|
|
|
|
};
|
2014-07-24 20:45:28 -03:00
|
|
|
|
2014-08-06 03:17:39 -03:00
|
|
|
// reference to AP_Mission, so we can ask preload terrain data for
|
|
|
|
// all waypoints
|
|
|
|
const AP_Mission &mission;
|
|
|
|
|
2014-07-01 00:56:18 -03:00
|
|
|
// cache of grids in memory, LRU
|
2015-09-22 19:31:17 -03:00
|
|
|
uint8_t cache_size = 0;
|
|
|
|
struct grid_cache *cache = nullptr;
|
2014-06-30 19:51:59 -03:00
|
|
|
|
2014-07-21 22:28:54 -03:00
|
|
|
// a grid_cache block waiting for disk IO
|
|
|
|
enum DiskIoState {
|
|
|
|
DiskIoIdle = 0,
|
|
|
|
DiskIoWaitWrite = 1,
|
|
|
|
DiskIoWaitRead = 2,
|
|
|
|
DiskIoDoneRead = 3,
|
|
|
|
DiskIoDoneWrite = 4
|
|
|
|
};
|
|
|
|
volatile enum DiskIoState disk_io_state;
|
|
|
|
union grid_io_block disk_block;
|
|
|
|
|
2014-06-30 19:51:59 -03:00
|
|
|
// last time we asked for more grids
|
2015-05-26 04:27:51 -03:00
|
|
|
uint32_t last_request_time_ms[MAVLINK_COMM_NUM_BUFFERS];
|
2014-06-30 19:51:59 -03:00
|
|
|
|
2014-07-21 20:10:38 -03:00
|
|
|
static const uint64_t bitmap_mask = (((uint64_t)1U)<<(TERRAIN_GRID_BLOCK_MUL_X*TERRAIN_GRID_BLOCK_MUL_Y)) - 1;
|
2014-07-21 22:28:54 -03:00
|
|
|
|
|
|
|
// open file handle on degree file
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
// has the timer been setup?
|
|
|
|
bool timer_setup;
|
|
|
|
|
|
|
|
// degrees lat and lon of file
|
|
|
|
int8_t file_lat_degrees;
|
|
|
|
int16_t file_lon_degrees;
|
|
|
|
|
|
|
|
// do we have an IO failure
|
|
|
|
volatile bool io_failure;
|
|
|
|
|
|
|
|
// have we created the terrain directory?
|
|
|
|
bool directory_created;
|
2014-07-22 23:18:37 -03:00
|
|
|
|
|
|
|
// cache the home altitude, as it is needed so often
|
|
|
|
float home_height;
|
|
|
|
Location home_loc;
|
2014-08-05 22:43:37 -03:00
|
|
|
|
|
|
|
// cache the last terrain height (AMSL) of the AHRS current
|
|
|
|
// location. This is used for extrapolation when terrain data is
|
|
|
|
// temporarily unavailable
|
|
|
|
bool have_current_loc_height;
|
|
|
|
float last_current_loc_height;
|
2014-08-06 03:17:39 -03:00
|
|
|
|
|
|
|
// next mission command to check
|
|
|
|
uint16_t next_mission_index;
|
|
|
|
|
2014-08-25 01:55:15 -03:00
|
|
|
// next mission position to check
|
|
|
|
uint8_t next_mission_pos;
|
|
|
|
|
2014-08-06 03:17:39 -03:00
|
|
|
// last time the mission changed
|
|
|
|
uint32_t last_mission_change_ms;
|
|
|
|
|
|
|
|
// grid spacing during mission check
|
|
|
|
uint16_t last_mission_spacing;
|
2014-08-06 03:36:02 -03:00
|
|
|
|
|
|
|
// next rally command to check
|
|
|
|
uint16_t next_rally_index;
|
|
|
|
|
|
|
|
// last time the rally points changed
|
|
|
|
uint32_t last_rally_change_ms;
|
|
|
|
|
|
|
|
// grid spacing during rally check
|
|
|
|
uint16_t last_rally_spacing;
|
2015-06-30 01:35:52 -03:00
|
|
|
|
2016-10-30 02:24:21 -03:00
|
|
|
char *file_path = nullptr;
|
2015-10-15 14:23:31 -03:00
|
|
|
|
|
|
|
// status
|
|
|
|
enum TerrainStatus system_status = TerrainStatusDisabled;
|
2019-04-24 00:19:53 -03:00
|
|
|
|
2019-11-06 22:03:40 -04:00
|
|
|
// memory allocation status
|
|
|
|
bool memory_alloc_failed;
|
|
|
|
|
2019-04-24 00:19:53 -03:00
|
|
|
static AP_Terrain *singleton;
|
2014-06-30 19:51:59 -03:00
|
|
|
};
|
2014-07-24 18:56:55 -03:00
|
|
|
#endif // AP_TERRAIN_AVAILABLE
|