Skip to content

Commit

Permalink
AP_ExternalAHRS: Default to no GPS week data
Browse files Browse the repository at this point in the history
* If a driver publishes time before it has gotten packets to set the
  value, default to no data value

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Mar 23, 2024
1 parent 85d25b2 commit fa18b2e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 46 deletions.
4 changes: 3 additions & 1 deletion libraries/AP_ExternalAHRS/AP_ExternalAHRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ class AP_ExternalAHRS {
Vector3f field;
} mag_data_message_t;

// A value to indicate the time is not yet available.
static constexpr uint32_t GPS_WEEK_NOT_AVAILABLE {0xFFFF};
typedef struct {
uint16_t gps_week; // GPS week, 0xFFFF if not available
uint16_t gps_week = GPS_WEEK_NOT_AVAILABLE; // GPS week
uint32_t ms_tow;
uint8_t fix_type;
uint8_t satellites_in_view;
Expand Down
41 changes: 20 additions & 21 deletions libraries/AP_ExternalAHRS/AP_ExternalAHRS_MicroStrain5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,26 @@ void AP_ExternalAHRS_MicroStrain5::post_filter() const
state.last_location_update_us = AP_HAL::micros();
}

AP_ExternalAHRS::gps_data_message_t gps {
gps_week: filter_data.week,
ms_tow: filter_data.tow_ms,
fix_type: (uint8_t) gnss_data[gnss_instance].fix_type,
satellites_in_view: gnss_data[gnss_instance].satellites,

horizontal_pos_accuracy: gnss_data[gnss_instance].horizontal_position_accuracy,
vertical_pos_accuracy: gnss_data[gnss_instance].vertical_position_accuracy,
horizontal_vel_accuracy: gnss_data[gnss_instance].speed_accuracy,

hdop: gnss_data[gnss_instance].hdop,
vdop: gnss_data[gnss_instance].vdop,

longitude: filter_data.lon,
latitude: filter_data.lat,
msl_altitude: gnss_data[gnss_instance].msl_altitude,

ned_vel_north: filter_data.ned_velocity_north,
ned_vel_east: filter_data.ned_velocity_east,
ned_vel_down: filter_data.ned_velocity_down,
};
AP_ExternalAHRS::gps_data_message_t gps;
gps.gps_week = filter_data.week;
gps.ms_tow = filter_data.tow_ms;
gps.fix_type = (uint8_t) gnss_data[gnss_instance].fix_type;
gps.satellites_in_view = gnss_data[gnss_instance].satellites;

gps.horizontal_pos_accuracy = gnss_data[gnss_instance].horizontal_position_accuracy;
gps.vertical_pos_accuracy = gnss_data[gnss_instance].vertical_position_accuracy;
gps.horizontal_vel_accuracy = gnss_data[gnss_instance].speed_accuracy;

gps.hdop = gnss_data[gnss_instance].hdop;
gps.vdop = gnss_data[gnss_instance].vdop;

gps.longitude = filter_data.lon;
gps.latitude = filter_data.lat;
gps.msl_altitude = gnss_data[gnss_instance].msl_altitude;

gps.ned_vel_north = filter_data.ned_velocity_north;
gps.ned_vel_east = filter_data.ned_velocity_east;
gps.ned_vel_down = filter_data.ned_velocity_down;

if (gps.fix_type >= 3 && !state.have_origin) {
WITH_SEMAPHORE(state.sem);
Expand Down
43 changes: 20 additions & 23 deletions libraries/AP_ExternalAHRS/AP_ExternalAHRS_MicroStrain7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,26 @@ void AP_ExternalAHRS_MicroStrain7::post_filter() const
}

for (int instance = 0; instance < NUM_GNSS_INSTANCES; instance++) {
// *INDENT-OFF*
AP_ExternalAHRS::gps_data_message_t gps {
gps_week: filter_data.week,
ms_tow: filter_data.tow_ms,
fix_type: (uint8_t) gnss_data[instance].fix_type,
satellites_in_view: gnss_data[instance].satellites,

horizontal_pos_accuracy: gnss_data[instance].horizontal_position_accuracy,
vertical_pos_accuracy: gnss_data[instance].vertical_position_accuracy,
horizontal_vel_accuracy: gnss_data[instance].speed_accuracy,

hdop: gnss_data[instance].hdop,
vdop: gnss_data[instance].vdop,

longitude: filter_data.lon,
latitude: filter_data.lat,
msl_altitude: gnss_data[instance].msl_altitude,

ned_vel_north: filter_data.ned_velocity_north,
ned_vel_east: filter_data.ned_velocity_east,
ned_vel_down: filter_data.ned_velocity_down,
};
// *INDENT-ON*
AP_ExternalAHRS::gps_data_message_t gps;

gps.gps_week = filter_data.week;
gps.ms_tow = filter_data.tow_ms;
gps.fix_type = (uint8_t) gnss_data[instance].fix_type;
gps.satellites_in_view = gnss_data[instance].satellites;
gps.horizontal_pos_accuracy = gnss_data[instance].horizontal_position_accuracy;
gps.vertical_pos_accuracy = gnss_data[instance].vertical_position_accuracy;
gps.horizontal_vel_accuracy = gnss_data[instance].speed_accuracy;

gps.hdop = gnss_data[instance].hdop;
gps.vdop = gnss_data[instance].vdop;

gps.longitude = filter_data.lon;
gps.latitude = filter_data.lat;
gps.msl_altitude = gnss_data[instance].msl_altitude;

gps.ned_vel_north = filter_data.ned_velocity_north;
gps.ned_vel_east = filter_data.ned_velocity_east;
gps.ned_vel_down = filter_data.ned_velocity_down;

if (gps.fix_type >= 3 && !state.have_origin) {
WITH_SEMAPHORE(state.sem);
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_ExternalAHRS/MicroStrain_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AP_MicroStrain
} filter_status;

struct {
uint16_t week;
uint16_t week = 0xFFFF;
uint32_t tow_ms;
float horizontal_position_accuracy;
float vertical_position_accuracy;
Expand Down

0 comments on commit fa18b2e

Please sign in to comment.