mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
fix(vision_target_estimator): respect vehicle GNSS quality (#29304)
Co-authored-by: jonas <jonas.perolini@rigi.tech>
This commit is contained in:
1 parent
cd7f0c8901
commit
ddcaad6601
4 files changed
+63
-49
No files matched your search
@@ -388,56 +388,14 @@ bool VTEPosition::isVisionDataValid(const fiducial_marker_pos_report_s &fiducial
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VTEPosition::isUavGpsPositionValid()
|
||||
{
|
||||
if (!isMeasRecent(_uav_gps_position.timestamp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isLatLonAltValid(_uav_gps_position.lat_deg, _uav_gps_position.lon_deg,
|
||||
_uav_gps_position.alt_m, "UAV GPS ", &_uav_gps_pos_warn_last)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_gps_pos_is_offset && !_gps_pos_offset_ned.valid) {
|
||||
PX4_DEBUG("Uav Gps position invalid offset!"); // Debug because this message can spam
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VTEPosition::isUavGpsVelocityValid()
|
||||
{
|
||||
// Check freshness first to early-out on stale samples before touching the payload.
|
||||
if (!isMeasRecent(_uav_gps_vel.timestamp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_uav_gps_vel.xyz.isAllFinite()) {
|
||||
if (shouldEmitWarning(_uav_gps_vel_warn_last)) {
|
||||
PX4_WARN("UAV GPS velocity not finite! vx: %.1f, vy: %.1f, vz: %.1f",
|
||||
(double)_uav_gps_vel.xyz(vtest::Axis::x), (double)_uav_gps_vel.xyz(vtest::Axis::y),
|
||||
(double)_uav_gps_vel.xyz(vtest::Axis::z));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_gps_pos_is_offset && !_velocity_offset_ned.valid) {
|
||||
PX4_DEBUG("Uav Gps velocity invalid offset!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VTEPosition::updateUavGnssData()
|
||||
{
|
||||
vehicle_gnss_s vehicle_gnss;
|
||||
const bool vehicle_gnss_updated = _vehicle_gnss_sub.update(&vehicle_gnss);
|
||||
|
||||
if (vehicle_gnss_updated) {
|
||||
const bool sample_usable = vehicle_gnss.usable && isMeasRecent(vehicle_gnss.timestamp_sample);
|
||||
|
||||
// Position
|
||||
_uav_gps_position.lat_deg = vehicle_gnss.receiver.latitude;
|
||||
_uav_gps_position.lon_deg = vehicle_gnss.receiver.longitude;
|
||||
@@ -445,7 +403,12 @@ bool VTEPosition::updateUavGnssData()
|
||||
_uav_gps_position.timestamp = vehicle_gnss.timestamp_sample;
|
||||
_uav_gps_position.eph = vehicle_gnss.receiver.eph;
|
||||
_uav_gps_position.epv = vehicle_gnss.receiver.epv;
|
||||
_uav_gps_position.valid = isUavGpsPositionValid();
|
||||
_uav_gps_position.valid = sample_usable
|
||||
&& PX4_ISFINITE(_uav_gps_position.eph) && _uav_gps_position.eph >= 0.f
|
||||
&& PX4_ISFINITE(_uav_gps_position.epv) && _uav_gps_position.epv >= 0.f
|
||||
&& isLatLonAltValid(_uav_gps_position.lat_deg, _uav_gps_position.lon_deg,
|
||||
_uav_gps_position.alt_m, "UAV GPS ", &_uav_gps_pos_warn_last)
|
||||
&& (!_gps_pos_is_offset || _gps_pos_offset_ned.valid);
|
||||
|
||||
// Velocity
|
||||
_uav_gps_vel.timestamp = vehicle_gnss.timestamp_sample;
|
||||
@@ -453,7 +416,19 @@ bool VTEPosition::updateUavGnssData()
|
||||
_uav_gps_vel.xyz(vtest::Axis::y) = vehicle_gnss.receiver.vel_east;
|
||||
_uav_gps_vel.xyz(vtest::Axis::z) = vehicle_gnss.receiver.vel_down;
|
||||
_uav_gps_vel.uncertainty = vehicle_gnss.receiver.speed_accuracy;
|
||||
_uav_gps_vel.valid = vehicle_gnss.receiver.vel_ned_valid && isUavGpsVelocityValid();
|
||||
_uav_gps_vel.valid = sample_usable && vehicle_gnss.receiver.vel_ned_valid
|
||||
&& PX4_ISFINITE(_uav_gps_vel.uncertainty) && _uav_gps_vel.uncertainty >= 0.f
|
||||
&& (!_gps_pos_is_offset || _velocity_offset_ned.valid);
|
||||
|
||||
if (_uav_gps_vel.valid && !_uav_gps_vel.xyz.isAllFinite()) {
|
||||
if (shouldEmitWarning(_uav_gps_vel_warn_last)) {
|
||||
PX4_WARN("UAV GPS velocity not finite! vx: %.1f, vy: %.1f, vz: %.1f",
|
||||
(double)_uav_gps_vel.xyz(vtest::Axis::x), (double)_uav_gps_vel.xyz(vtest::Axis::y),
|
||||
(double)_uav_gps_vel.xyz(vtest::Axis::z));
|
||||
}
|
||||
|
||||
_uav_gps_vel.valid = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Check if stored data is still valid
|
||||
|
||||
@@ -351,8 +351,6 @@ private:
|
||||
|
||||
/* UAV GPS data */
|
||||
bool updateUavGnssData();
|
||||
bool isUavGpsPositionValid();
|
||||
bool isUavGpsVelocityValid();
|
||||
bool processObsGNSSPosMission(TargetObs &obs);
|
||||
bool processObsGNSSVelUav(TargetObs &obs) const;
|
||||
|
||||
|
||||
@@ -1599,6 +1599,45 @@ TEST_F(VTEPositionTest, MissionPositionRejectsInvalidGpsTimestamps)
|
||||
EXPECT_TRUE(_vte_state_sub->get().rel_pos_valid);
|
||||
}
|
||||
|
||||
// A selected receiver is published even when its checks fail. It must not aid VTE.
|
||||
TEST_F(VTEPositionTest, RejectsUnusableVehicleGnssAndRecovers)
|
||||
{
|
||||
enableMask({FusionMaskOption::kMissionPos, FusionMaskOption::kUavGpsVel});
|
||||
initializeFromMissionGnss(kZeroVec);
|
||||
ASSERT_TRUE(_aid_gps_mission_sub->update());
|
||||
ASSERT_TRUE(_aid_gps_vel_uav_sub->update());
|
||||
|
||||
for (const bool usable : {false, true}) {
|
||||
const hrt_abstime now = vte_test::advanceMicroseconds(kStepUs);
|
||||
ASSERT_TRUE(vte_test::publishUavGnss(*_uav_gnss_pub, kUavLat, kUavLon, kUavAltM, 0.2f, 0.2f,
|
||||
kZeroVec, 0.1f, true, now, kZeroVec, usable));
|
||||
_vte->update(kZeroVec);
|
||||
EXPECT_EQ(_aid_gps_mission_sub->update(), usable);
|
||||
EXPECT_EQ(_aid_gps_vel_uav_sub->update(), usable);
|
||||
}
|
||||
}
|
||||
|
||||
// Noise floors apply to known finite accuracies, not to corrupt/unknown receiver uncertainty.
|
||||
TEST_F(VTEPositionTest, RejectsInvalidVehicleGnssAccuracy)
|
||||
{
|
||||
enableMask({FusionMaskOption::kMissionPos, FusionMaskOption::kUavGpsVel});
|
||||
initializeFromMissionGnss(kZeroVec);
|
||||
ASSERT_TRUE(_aid_gps_mission_sub->update());
|
||||
ASSERT_TRUE(_aid_gps_vel_uav_sub->update());
|
||||
|
||||
for (const float invalid : {NAN, INFINITY, -1.f}) {
|
||||
for (int field = 0; field < 3; ++field) {
|
||||
matrix::Vector3f accuracy(0.2f, 0.2f, 0.1f); // eph, epv, speed accuracy
|
||||
accuracy(field) = invalid;
|
||||
const hrt_abstime now = vte_test::advanceMicroseconds(kStepUs);
|
||||
publishUavGnss(kUavLat, kUavLon, kUavAltM, accuracy(0), accuracy(1), kZeroVec, accuracy(2), true, now);
|
||||
_vte->update(kZeroVec);
|
||||
EXPECT_EQ(_aid_gps_mission_sub->update(), field == 2);
|
||||
EXPECT_EQ(_aid_gps_vel_uav_sub->update(), field != 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WHY: GPS offset should expire if it becomes stale.
|
||||
// WHAT: Force an offset timeout and ensure the mission GPS measurement is
|
||||
// rejected.
|
||||
|
||||
@@ -262,11 +262,13 @@ inline bool publishVisionPos(uORB::Publication<fiducial_marker_pos_report_s> &pu
|
||||
inline bool publishUavGnss(uORB::Publication<vehicle_gnss_s> &pub, double lat, double lon, float alt,
|
||||
float eph, float epv, const matrix::Vector3f &vel_ned, float vel_var,
|
||||
bool vel_valid, hrt_abstime timestamp,
|
||||
const matrix::Vector3f &antenna_offset = matrix::Vector3f{})
|
||||
const matrix::Vector3f &antenna_offset = matrix::Vector3f{}, bool usable = true)
|
||||
{
|
||||
vehicle_gnss_s msg{};
|
||||
msg.timestamp = timestamp;
|
||||
msg.timestamp_sample = timestamp;
|
||||
msg.usable = usable;
|
||||
msg.receiver.fix_type = sensor_gnss_s::FIX_TYPE_3D;
|
||||
msg.receiver.latitude = static_cast<decltype(msg.receiver.latitude)>(lat);
|
||||
msg.receiver.longitude = static_cast<decltype(msg.receiver.longitude)>(lon);
|
||||
msg.receiver.altitude_msl = static_cast<decltype(msg.receiver.altitude_msl)>(alt);
|
||||
|
||||
Reference in new issue
Block a user