Skip to content

Commit

Permalink
AP_GPS: broaden the acceptance criteria for GPS Yaw measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
bugobliterator authored and magicrub committed Feb 8, 2024
1 parent c259d11 commit 4bcac07
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
41 changes: 24 additions & 17 deletions libraries/AP_GPS/GPS_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ bool AP_GPS_Backend::calculate_moving_base_yaw(float reported_heading_deg, const
bool AP_GPS_Backend::calculate_moving_base_yaw(AP_GPS::GPS_State &interim_state, const float reported_heading_deg, const float reported_distance, const float reported_D) {
constexpr float minimum_antenna_seperation = 0.05; // meters
constexpr float permitted_error_length_pct = 0.2; // percentage

#if HAL_LOGGING_ENABLED || AP_AHRS_ENABLED
float min_D = 0.0f;
float max_D = 0.0f;
#endif
bool selectedOffset = false;
Vector3f offset;
switch (MovingBase::Type(gps.mb_params[interim_state.instance].type.get())) {
Expand Down Expand Up @@ -373,10 +376,6 @@ bool AP_GPS_Backend::calculate_moving_base_yaw(AP_GPS::GPS_State &interim_state,

#if AP_AHRS_ENABLED
{
// get lag
float lag = 0.1;
get_lag(lag);

// get vehicle rotation, projected back in time using the gyro
// this is not 100% accurate, but it is good enough for
// this test. To do it completely accurately we'd need an
Expand All @@ -385,17 +384,21 @@ bool AP_GPS_Backend::calculate_moving_base_yaw(AP_GPS::GPS_State &interim_state,
// for this use case
const auto &ahrs = AP::ahrs();
const Vector3f &gyro = ahrs.get_gyro();
Matrix3f rot_body_to_ned = ahrs.get_rotation_body_to_ned();
rot_body_to_ned.rotate(gyro * (-lag));
Matrix3f rot_body_to_ned_min_lag = ahrs.get_rotation_body_to_ned();
rot_body_to_ned_min_lag.rotate(gyro * -AP_GPS_MB_MIN_LAG);
Matrix3f rot_body_to_ned_max_lag = ahrs.get_rotation_body_to_ned();
rot_body_to_ned_max_lag.rotate(gyro * -AP_GPS_MB_MAX_LAG);

// apply rotation to the offset to get the Z offset in NED
const Vector3f antenna_tilt = rot_body_to_ned * offset;
const float alt_error = reported_D + antenna_tilt.z;

if (fabsf(alt_error) > permitted_error_length_pct * min_dist) {
const Vector3f antenna_tilt_min_lag = rot_body_to_ned_min_lag * offset;
const Vector3f antenna_tilt_max_lag = rot_body_to_ned_max_lag * offset;
min_D = MIN(-antenna_tilt_min_lag.z, -antenna_tilt_max_lag.z);
max_D = MAX(-antenna_tilt_min_lag.z, -antenna_tilt_max_lag.z);
min_D -= permitted_error_length_pct * min_dist;
max_D += permitted_error_length_pct * min_dist;
if (reported_D < min_D || reported_D > max_D) {
// the vertical component is out of range, reject it
Debug("bad alt_err %.1f > %.1f\n",
alt_error, permitted_error_length_pct * min_dist);
Debug("bad alt_err %f < %f < %f", (double)min_D, (double)reported_D, (double)max_D);
goto bad_yaw;
}
}
Expand Down Expand Up @@ -425,16 +428,20 @@ bool AP_GPS_Backend::calculate_moving_base_yaw(AP_GPS::GPS_State &interim_state,
// @Field: RHD: reported heading,deg
// @Field: RDist: antenna separation,m
// @Field: RDown: vertical antenna separation,m
// @Field: MinCDown: minimum tolerable vertical antenna separation,m
// @Field: MaxCDown: maximum tolerable vertical antenna separation,m
// @Field: OK: 1 if have yaw
AP::logger().WriteStreaming("GPYW", "TimeUS,Id,RHD,RDist,RDown,OK",
"s#dmm-",
"F-----",
"QBfffB",
AP::logger().WriteStreaming("GPYW", "TimeUS,Id,RHD,RDist,RDown,MinCDown,MaxCDown,OK",
"s#dmmmm-",
"F-------",
"QBfffffB",
AP_HAL::micros64(),
state.instance,
reported_heading_deg,
reported_distance,
reported_D,
min_D,
max_D,
interim_state.have_gps_yaw);
#endif

Expand Down
8 changes: 8 additions & 0 deletions libraries/AP_GPS/GPS_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#define AP_GPS_DEBUG_LOGGING_ENABLED 0
#endif

#ifndef AP_GPS_MB_MIN_LAG
#define AP_GPS_MB_MIN_LAG 0.05f
#endif

#ifndef AP_GPS_MB_MAX_LAG
#define AP_GPS_MB_MAX_LAG 0.25f
#endif

#if AP_GPS_DEBUG_LOGGING_ENABLED
#include <AP_HAL/utility/RingBuffer.h>
#endif
Expand Down

0 comments on commit 4bcac07

Please sign in to comment.