HomePos: check corresponding validity before using data

This commit is contained in:
bresch 2020-10-23 16:12:36 +02:00 committed by Daniel Agar
parent 711bd2ce87
commit 3276916df9
3 changed files with 8 additions and 6 deletions

View File

@ -295,9 +295,11 @@ build_gps_response(uint8_t *buffer, size_t *size)
memset(&home, 0, sizeof(home));
orb_copy(ORB_ID(home_position), _home_sub, &home);
_home_lat = home.lat;
_home_lon = home.lon;
_home_position_set = true;
if (home.valid_hpos) {
_home_lat = home.lat;
_home_lon = home.lon;
_home_position_set = true;
}
}
/* Distance from home */

View File

@ -329,14 +329,14 @@ void FlightTaskAuto::_set_heading_from_mode()
break;
case 1: // Heading points towards home.
if (_sub_home_position.get().valid_hpos) {
if (_sub_home_position.get().valid_lpos) {
v = Vector2f(&_sub_home_position.get().x) - Vector2f(_position);
}
break;
case 2: // Heading point away from home.
if (_sub_home_position.get().valid_hpos) {
if (_sub_home_position.get().valid_lpos) {
v = Vector2f(_position) - Vector2f(&_sub_home_position.get().x);
}

View File

@ -162,7 +162,7 @@ public:
void reset_vroi() { _vroi = {}; }
bool home_alt_valid() { return (_home_pos.timestamp > 0 && _home_pos.valid_alt); }
bool home_position_valid() { return (_home_pos.timestamp > 0 && _home_pos.valid_alt && _home_pos.valid_hpos); }
bool home_position_valid() { return (_home_pos.timestamp > 0 && _home_pos.valid_alt && _home_pos.valid_hpos && _home_pos.valid_lpos); }
Geofence &get_geofence() { return _geofence; }