Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Arming/AP_Terrain: pre-arm check if terrain allocation failed #12796

Merged
merged 5 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions libraries/AP_Arming/AP_Arming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <AP_AHRS/AP_AHRS.h>
#include <AP_Baro/AP_Baro.h>
#include <AP_RangeFinder/AP_RangeFinder.h>
#include <AP_Terrain/AP_Terrain.h>

#if HAL_WITH_UAVCAN
#include <AP_BoardConfig/AP_BoardConfig_CAN.h>
Expand Down Expand Up @@ -106,8 +107,8 @@ const AP_Param::GroupInfo AP_Arming::var_info[] = {
// @Param: CHECK
// @DisplayName: Arm Checks to Peform (bitmask)
// @Description: Checks prior to arming motor. This is a bitmask of checks that will be performed before allowing arming. The default is no checks, allowing arming at any time. You can select whatever checks you prefer by adding together the values of each check type to set this parameter. For example, to only allow arming when you have GPS lock and no RC failsafe you would set ARMING_CHECK to 72. For most users it is recommended that you set this to 1 to enable all checks.
// @Values: 0:None,1:All,2:Barometer,4:Compass,8:GPS Lock,16:INS(INertial Sensors - accels & gyros),32:Parameters(unused),64:RC Channels,128:Board voltage,256:Battery Level,1024:LoggingAvailable,2048:Hardware safety switch,4096:GPS configuration,8192:System
// @Values{Plane}: 0:None,1:All,2:Barometer,4:Compass,8:GPS Lock,16:INS(INertial Sensors - accels & gyros),32:Parameters(unused),64:RC Channels,128:Board voltage,256:Battery Level,512:Airspeed,1024:LoggingAvailable,2048:Hardware safety switch,4096:GPS configuration,8192:System
// @Values: 0:None,1:All,2:Barometer,4:Compass,8:GPS Lock,16:INS(INertial Sensors - accels & gyros),32:Parameters(unused),64:RC Channels,128:Board voltage,256:Battery Level,1024:LoggingAvailable,2048:Hardware safety switch,4096:GPS configuration,8192:System,16384:Mission,32768:RangeFinder
// @Values{Plane}: 0:None,1:All,2:Barometer,4:Compass,8:GPS Lock,16:INS(INertial Sensors - accels & gyros),32:Parameters(unused),64:RC Channels,128:Board voltage,256:Battery Level,512:Airspeed,1024:LoggingAvailable,2048:Hardware safety switch,4096:GPS configuration,8192:System,16384:Mission,32768:RangeFinder
// @Bitmask: 0:All,1:Barometer,2:Compass,3:GPS lock,4:INS,5:Parameters,6:RC Channels,7:Board voltage,8:Battery Level,10:Logging Available,11:Hardware safety switch,12:GPS Configuration,13:System,14:Mission,15:Rangefinder
// @Bitmask{Plane}: 0:All,1:Barometer,2:Compass,3:GPS lock,4:INS,5:Parameters,6:RC Channels,7:Board voltage,8:Battery Level,9:Airspeed,10:Logging Available,11:Hardware safety switch,12:GPS Configuration,13:System,14:Mission,15:Rangefinder
// @User: Standard
Expand Down Expand Up @@ -698,6 +699,13 @@ bool AP_Arming::system_checks(bool report)
check_failed(ARMING_CHECK_SYSTEM, report, "Param storage failed");
return false;
}
#if AP_TERRAIN_AVAILABLE
const AP_Terrain *terrain = AP_Terrain::get_singleton();
if ((terrain != nullptr) && terrain->init_failed()) {
check_failed(ARMING_CHECK_SYSTEM, report, "Terrain out of memory");
return false;
}
#endif
}
if (AP::internalerror().errors() != 0) {
check_failed(report, "Internal errors (0x%x)", (unsigned int)AP::internalerror().errors());
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_Terrain/AP_Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,16 @@ void AP_Terrain::log_terrain_data()
*/
bool AP_Terrain::allocate(void)
{
if (enable == 0) {
if (enable == 0 || memory_alloc_failed) {
return false;
}
if (cache != nullptr) {
return true;
}
cache = (struct grid_cache *)calloc(TERRAIN_GRID_BLOCK_CACHE_SIZE, sizeof(cache[0]));
if (cache == nullptr) {
enable.set(0);
gcs().send_text(MAV_SEVERITY_CRITICAL, "Terrain: Allocation failed");
memory_alloc_failed = true;
return false;
}
cache_size = TERRAIN_GRID_BLOCK_CACHE_SIZE;
Expand Down
12 changes: 10 additions & 2 deletions libraries/AP_Terrain/AP_Terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ class AP_Terrain {
/*
get some statistics for TERRAIN_REPORT
*/
void get_statistics(uint16_t &pending, uint16_t &loaded);
void get_statistics(uint16_t &pending, uint16_t &loaded) const;

/*
returns true if initialisation failed because out-of-memory
*/
bool init_failed() const { return memory_alloc_failed; }

private:
// allocate the terrain subsystem data
Expand Down Expand Up @@ -309,7 +314,7 @@ class AP_Terrain {
/*
get some statistics for TERRAIN_REPORT
*/
uint8_t bitcount64(uint64_t b);
uint8_t bitcount64(uint64_t b) const;

/*
disk IO functions
Expand Down Expand Up @@ -415,6 +420,9 @@ class AP_Terrain {
// status
enum TerrainStatus system_status = TerrainStatusDisabled;

// memory allocation status
bool memory_alloc_failed;

static AP_Terrain *singleton;
};
#endif // AP_TERRAIN_AVAILABLE
4 changes: 2 additions & 2 deletions libraries/AP_Terrain/TerrainGCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ void AP_Terrain::send_request(mavlink_channel_t chan)
/*
count bits in a uint64_t
*/
uint8_t AP_Terrain::bitcount64(uint64_t b)
uint8_t AP_Terrain::bitcount64(uint64_t b) const
{
return __builtin_popcount((unsigned)(b&0xFFFFFFFF)) + __builtin_popcount((unsigned)(b>>32));
}

/*
get some statistics for TERRAIN_REPORT
*/
void AP_Terrain::get_statistics(uint16_t &pending, uint16_t &loaded)
void AP_Terrain::get_statistics(uint16_t &pending, uint16_t &loaded) const
{
pending = 0;
loaded = 0;
Expand Down