mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-12-02 22:40:27 +08:00
Nothing checked the reported heading accuracy before GNSS yaw fusion started, and the reset always claimed the default heading noise, so a receiver still resolving its baseline could align yaw to a heading it reported with a 172 deg accuracy.
(cherry picked from commit c7db242da4)
Hand-ported: release/1.18 has no separate GNSS heading buffer (#27102), so the accuracy gate reads gnss_sample.yaw_acc, and the test sets it through the GPS simulator, which gains setYawAccuracy().
Assisted-by: Claude:claude-opus-5-5
This commit is contained in:
1 parent
42d3f1d151
commit
3d50ebba3b
4 files changed
+45
-2
No files matched your search
@@ -65,10 +65,17 @@ void Ekf::controlGnssYawFusion(const gnssSample &gnss_sample)
|
||||
const bool is_gnss_yaw_data_intermittent = !isNewestSampleRecent(_time_last_gnss_yaw_buffer_push,
|
||||
2 * GNSS_YAW_MAX_INTERVAL);
|
||||
|
||||
// A receiver still resolving its baseline can report a heading with an accuracy of tens of degrees. Starting may
|
||||
// reset yaw to it, so hold it to the bar the yaw estimator must meet before a reset. Not every receiver reports an
|
||||
// accuracy.
|
||||
const bool is_gnss_yaw_accurate = !PX4_ISFINITE(gnss_sample.yaw_acc)
|
||||
|| (gnss_sample.yaw_acc < _params.EKFGSF_yaw_err_max);
|
||||
|
||||
const bool starting_conditions_passing = continuing_conditions_passing
|
||||
&& _gnss_checks.passed()
|
||||
&& !is_gnss_yaw_data_intermittent
|
||||
&& !_gps_intermittent;
|
||||
&& !_gps_intermittent
|
||||
&& is_gnss_yaw_accurate;
|
||||
|
||||
if (_control_status.flags.gnss_yaw) {
|
||||
if (continuing_conditions_passing) {
|
||||
@@ -225,7 +232,9 @@ bool Ekf::resetYawToGnss(const float gnss_yaw, const float gnss_yaw_offset)
|
||||
// GNSS yaw measurement is already compensated for antenna offset in the driver
|
||||
const float measured_yaw = gnss_yaw;
|
||||
|
||||
const float yaw_variance = sq(fmaxf(_params.gnss_heading_noise, 1.e-2f));
|
||||
// Take the variance updateGnssYaw() derived from this sample's reported accuracy, so the reset is no more confident
|
||||
// than the measurement
|
||||
const float yaw_variance = fmaxf(_aid_src_gnss_yaw.observation_variance, sq(1.e-2f));
|
||||
resetQuatStateYaw(measured_yaw, yaw_variance);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -65,6 +65,11 @@ void Gps::setYawOffset(const float yaw_offset)
|
||||
_gps_data.yaw_offset = yaw_offset;
|
||||
}
|
||||
|
||||
void Gps::setYawAccuracy(const float yaw_acc)
|
||||
{
|
||||
_gps_data.yaw_acc = yaw_acc;
|
||||
}
|
||||
|
||||
void Gps::setFixType(const int fix_type)
|
||||
{
|
||||
_gps_data.fix_type = fix_type;
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
void setVelocity(const Vector3f &vel);
|
||||
void setYaw(const float yaw);
|
||||
void setYawOffset(const float yaw);
|
||||
void setYawAccuracy(const float yaw_acc);
|
||||
void setFixType(const int fix_type);
|
||||
void setNumberOfSatellites(const int num_satellites);
|
||||
void setPdop(const float pdop);
|
||||
|
||||
@@ -341,3 +341,31 @@ TEST_F(EkfGpsHeadingTest, stopOnGround)
|
||||
// THEN: the yaw variance increases
|
||||
EXPECT_GT(_ekf->getYawVar(), yaw_variance_before);
|
||||
}
|
||||
|
||||
TEST_F(EkfGpsHeadingTest, inaccurateHeadingDoesNotReset)
|
||||
{
|
||||
// GIVEN: a receiver still resolving its baseline, reporting a heading 30 deg off with a 1 rad accuracy
|
||||
const float gps_heading = matrix::wrap_pi(_ekf_wrapper.getYawAngle() + math::radians(30.f));
|
||||
_sensor_simulator._gps.setYaw(gps_heading);
|
||||
_sensor_simulator._gps.setYawAccuracy(1.f);
|
||||
const int initial_quat_reset_counter = _ekf_wrapper.getQuaternionResetCounter();
|
||||
_sensor_simulator.runSeconds(4);
|
||||
|
||||
// THEN: GNSS yaw fusion doesn't start, so yaw isn't reset to it
|
||||
EXPECT_FALSE(_ekf_wrapper.isIntendingGpsHeadingFusion());
|
||||
EXPECT_EQ(_ekf_wrapper.getQuaternionResetCounter(), initial_quat_reset_counter);
|
||||
|
||||
// WHEN: the reported accuracy drops below 15 deg
|
||||
const float yaw_acc = math::radians(10.f);
|
||||
_sensor_simulator._gps.setYawAccuracy(yaw_acc);
|
||||
|
||||
for (int i = 0; (i < 100) && (_ekf_wrapper.getQuaternionResetCounter() == initial_quat_reset_counter); i++) {
|
||||
_sensor_simulator.runMicroseconds(10000);
|
||||
}
|
||||
|
||||
// THEN: fusion starts with a reset to the heading, as uncertain as the reported accuracy
|
||||
EXPECT_TRUE(_ekf_wrapper.isIntendingGpsHeadingFusion());
|
||||
EXPECT_EQ(_ekf_wrapper.getQuaternionResetCounter(), initial_quat_reset_counter + 1);
|
||||
checkConvergence(gps_heading, 0.5f);
|
||||
EXPECT_NEAR(_ekf->getYawVar(), yaw_acc * yaw_acc, 0.1f * yaw_acc * yaw_acc);
|
||||
}
|
||||
Reference in new issue
Block a user