Skip to content

Commit

Permalink
make format
Browse files Browse the repository at this point in the history
  • Loading branch information
dakejahl committed Mar 21, 2020
1 parent ccd9359 commit d4f89ca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion msg/vehicle_gps_position.msg
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ uint8 satellites_used # Number of satellites used
float32 heading # heading angle of XYZ body frame rel to NED. Set to NaN if not available and updated (used for dual antenna GPS), (rad, [-PI, PI])
float32 heading_offset # heading offset of dual antenna array in body frame. Set to NaN if not applicable. (rad, [-PI, PI])

uint8 selected # GPS selection: 0: GPS1, 1: GPS2. 2: GPS1+GPS2 blend
uint8 selected # GPS selection: 0: GPS1, 1: GPS2. 2: GPS3. 3. Blending multiple receivers
6 changes: 3 additions & 3 deletions platforms/common/include/px4_platform_common/i2c_spi_buses.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ class I2CSPIDriver : public I2CSPIDriverBase

virtual ~I2CSPIDriver() = default;

void Run() final
{
void Run() final {
static_cast<T *>(this)->RunImpl();

if (should_exit()) {
if (should_exit())
{
exit_and_cleanup();
}
}
Expand Down
54 changes: 28 additions & 26 deletions src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ VehicleGPSPosition::Start()
// needed to change the active sensor if the primary stops updating
bool anyGpsRegistered = false;
bool registered[GPS_MAX_RECEIVERS];

for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
registered[i] = _sensor_gps_sub[i].registerCallback();
anyGpsRegistered |= registered[i];
Expand Down Expand Up @@ -102,6 +103,7 @@ VehicleGPSPosition::Run()
// Check all GPS instance
bool any_gps_updated = false;
bool gps_updated[GPS_MAX_RECEIVERS];

for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {

gps_updated[i] = _sensor_gps_sub[i].updated();
Expand All @@ -121,41 +123,41 @@ VehicleGPSPosition::Run()
// blend multiple receivers if available

// calculate blending weights
if (!blend_gps_data()) {
// Only use selected receiver data if it has been updated
_gps_new_output_data = false;
_gps_select_index = 0;
if (!blend_gps_data()) {
// Only use selected receiver data if it has been updated
_gps_new_output_data = false;
_gps_select_index = 0;

// Find the single "best" GPS from the data we have
// First, find the GPS(s) with the best fix
uint8_t best_fix = 0;
// Find the single "best" GPS from the data we have
// First, find the GPS(s) with the best fix
uint8_t best_fix = 0;

for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
if (_gps_state[i].fix_type > best_fix) {
best_fix = _gps_state[i].fix_type;
}
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
if (_gps_state[i].fix_type > best_fix) {
best_fix = _gps_state[i].fix_type;
}
}

// Second, compare GPS's with best fix and take the one with most satellites
uint8_t max_sats = 0;
// Second, compare GPS's with best fix and take the one with most satellites
uint8_t max_sats = 0;

for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
if (_gps_state[i].fix_type == best_fix && _gps_state[i].satellites_used > max_sats) {
max_sats = _gps_state[i].satellites_used;
_gps_select_index = i;
}
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
if (_gps_state[i].fix_type == best_fix && _gps_state[i].satellites_used > max_sats) {
max_sats = _gps_state[i].satellites_used;
_gps_select_index = i;
}
}

// Check for new data on selected GPS, and clear blend offsets
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
if (gps_updated[i] && _gps_select_index == i) {
_gps_new_output_data = true;
}

_NE_pos_offset_m[i].zero();
_hgt_offset_mm[i] = 0.0f;
// Check for new data on selected GPS, and clear blend offsets
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
if (gps_updated[i] && _gps_select_index == i) {
_gps_new_output_data = true;
}

_NE_pos_offset_m[i].zero();
_hgt_offset_mm[i] = 0.0f;
}
}

if (_gps_new_output_data) {
// correct the _gps_state data for steady state offsets and write to _gps_output
Expand Down

0 comments on commit d4f89ca

Please sign in to comment.