mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 02:36:37 +08:00
HomePos: check corresponding validity before using data
This commit is contained in:
@@ -295,9 +295,11 @@ build_gps_response(uint8_t *buffer, size_t *size)
|
|||||||
memset(&home, 0, sizeof(home));
|
memset(&home, 0, sizeof(home));
|
||||||
orb_copy(ORB_ID(home_position), _home_sub, &home);
|
orb_copy(ORB_ID(home_position), _home_sub, &home);
|
||||||
|
|
||||||
_home_lat = home.lat;
|
if (home.valid_hpos) {
|
||||||
_home_lon = home.lon;
|
_home_lat = home.lat;
|
||||||
_home_position_set = true;
|
_home_lon = home.lon;
|
||||||
|
_home_position_set = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Distance from home */
|
/* Distance from home */
|
||||||
|
|||||||
@@ -329,14 +329,14 @@ void FlightTaskAuto::_set_heading_from_mode()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // Heading points towards home.
|
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);
|
v = Vector2f(&_sub_home_position.get().x) - Vector2f(_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // Heading point away from home.
|
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);
|
v = Vector2f(_position) - Vector2f(&_sub_home_position.get().x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public:
|
|||||||
void reset_vroi() { _vroi = {}; }
|
void reset_vroi() { _vroi = {}; }
|
||||||
|
|
||||||
bool home_alt_valid() { return (_home_pos.timestamp > 0 && _home_pos.valid_alt); }
|
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; }
|
Geofence &get_geofence() { return _geofence; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user