Skip to content

Commit 5c6c678

Browse files
committed
AP_GPS: create real AP_GPS_Blended backend
1 parent c08d982 commit 5c6c678

File tree

5 files changed

+226
-159
lines changed

5 files changed

+226
-159
lines changed

libraries/AP_Arming/AP_Arming.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,6 @@ bool AP_Arming::gps_checks(bool report)
649649
(double)distance_m);
650650
return false;
651651
}
652-
#if AP_GPS_BLENDED_ENABLED
653-
if (!gps.blend_health_check()) {
654-
check_failed(ARMING_CHECK_GPS, report, "GPS blending unhealthy");
655-
return false;
656-
}
657-
#endif
658652

659653
// check AHRS and GPS are within 10m of each other
660654
if (gps.num_sensors() > 0) {

libraries/AP_GPS/AP_GPS.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <AP_SerialManager/AP_SerialManager.h>
3030

3131
#include "AP_GPS_NOVA.h"
32+
#include "AP_GPS_Blended.h"
3233
#include "AP_GPS_ERB.h"
3334
#include "AP_GPS_GSOF.h"
3435
#include "AP_GPS_NMEA.h"
@@ -66,8 +67,6 @@
6667
#define GPS_BAUD_TIME_MS 1200
6768
#define GPS_TIMEOUT_MS 4000u
6869

69-
#define BLEND_COUNTER_FAILURE_INCREMENT 10
70-
7170
extern const AP_HAL::HAL &hal;
7271

7372
// baudrates to try to detect GPSes with
@@ -347,6 +346,11 @@ void AP_GPS::init()
347346
rate_ms.set(GPS_MAX_RATE_MS);
348347
}
349348
}
349+
350+
// create the blended instance if appropriate:
351+
#if AP_GPS_BLENDED_ENABLED
352+
drivers[GPS_BLENDED_INSTANCE] = new AP_GPS_Blended(*this, params[GPS_BLENDED_INSTANCE], state[GPS_BLENDED_INSTANCE], timing[GPS_BLENDED_INSTANCE]);
353+
#endif
350354
}
351355

352356
void AP_GPS::convert_parameters()
@@ -1084,25 +1088,15 @@ void AP_GPS::update_primary(void)
10841088
*/
10851089
const bool using_moving_base = is_rtk_base(0) || is_rtk_base(1);
10861090
if ((GPSAutoSwitch)_auto_switch.get() == GPSAutoSwitch::BLEND && !using_moving_base) {
1087-
_output_is_blended = calc_blend_weights();
1088-
// adjust blend health counter
1089-
if (!_output_is_blended) {
1090-
_blend_health_counter = MIN(_blend_health_counter+BLEND_COUNTER_FAILURE_INCREMENT, 100);
1091-
} else if (_blend_health_counter > 0) {
1092-
_blend_health_counter--;
1093-
}
1094-
// stop blending if unhealthy
1095-
if (_blend_health_counter >= 50) {
1096-
_output_is_blended = false;
1097-
}
1091+
_output_is_blended = ((AP_GPS_Blended*)drivers[GPS_BLENDED_INSTANCE])->calc_weights();
10981092
} else {
10991093
_output_is_blended = false;
1100-
_blend_health_counter = 0;
1094+
((AP_GPS_Blended*)drivers[GPS_BLENDED_INSTANCE])->zero_health_counter();
11011095
}
11021096

11031097
if (_output_is_blended) {
11041098
// Use the weighting to calculate blended GPS states
1105-
calc_blended_state();
1099+
((AP_GPS_Blended*)drivers[GPS_BLENDED_INSTANCE])->calc_state();
11061100
// set primary to the virtual instance
11071101
primary_instance = GPS_BLENDED_INSTANCE;
11081102
return;
@@ -1695,10 +1689,7 @@ bool AP_GPS::get_lag(uint8_t instance, float &lag_sec) const
16951689
#if AP_GPS_BLENDED_ENABLED
16961690
// return lag of blended GPS
16971691
if (instance == GPS_BLENDED_INSTANCE) {
1698-
lag_sec = _blended_lag_sec;
1699-
// auto switching uses all GPS receivers, so all must be configured
1700-
uint8_t inst; // we don't actually care what the number is, but must pass it
1701-
return first_unconfigured_gps(inst);
1692+
return drivers[instance]->get_lag(lag_sec);
17021693
}
17031694
#endif
17041695

@@ -1732,7 +1723,7 @@ const Vector3f &AP_GPS::get_antenna_offset(uint8_t instance) const
17321723
#if AP_GPS_BLENDED_ENABLED
17331724
if (instance == GPS_BLENDED_INSTANCE) {
17341725
// return an offset for the blended GPS solution
1735-
return _blended_antenna_offset;
1726+
return ((AP_GPS_Blended*)drivers[instance])->get_antenna_offset();
17361727
}
17371728
#endif
17381729

@@ -1788,12 +1779,6 @@ bool AP_GPS::is_healthy(uint8_t instance) const
17881779
}
17891780
#endif // HAL_BUILD_AP_PERIPH
17901781

1791-
#if AP_GPS_BLENDED_ENABLED
1792-
if (instance == GPS_BLENDED_INSTANCE) {
1793-
return blend_health_check();
1794-
}
1795-
#endif
1796-
17971782
return drivers[instance] != nullptr &&
17981783
drivers[instance]->is_healthy();
17991784
}
@@ -1827,6 +1812,14 @@ bool AP_GPS::backends_healthy(char failure_msg[], uint16_t failure_msg_len) {
18271812
}
18281813
}
18291814
}
1815+
1816+
#if defined(GPS_BLENDED_INSTANCE)
1817+
if (!drivers[GPS_BLENDED_INSTANCE]->is_healthy()) {
1818+
hal.util->snprintf(failure_msg, failure_msg_len, "GPS blending unhealthy");
1819+
return false;
1820+
}
1821+
#endif
1822+
18301823
return true;
18311824
}
18321825

libraries/AP_GPS/AP_GPS.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class RTCM3_Parser;
5252
/// GPS driver main class
5353
class AP_GPS
5454
{
55+
friend class AP_GPS_Blended;
5556
friend class AP_GPS_ERB;
5657
friend class AP_GPS_GSOF;
5758
friend class AP_GPS_MAV;
@@ -512,9 +513,6 @@ class AP_GPS
512513
// pre-arm check that all GPSs are close to each other. farthest distance between GPSs (in meters) is returned
513514
bool all_consistent(float &distance) const;
514515

515-
// pre-arm check of GPS blending. False if blending is unhealthy, True if healthy or blending is not being used
516-
bool blend_health_check() const;
517-
518516
// handle sending of initialisation strings to the GPS - only used by backends
519517
void send_blob_start(uint8_t instance);
520518
void send_blob_start(uint8_t instance, const char *_blob, uint16_t size);
@@ -606,7 +604,7 @@ class AP_GPS
606604
protected:
607605

608606
// configuration parameters
609-
Params params[GPS_MAX_RECEIVERS];
607+
Params params[GPS_MAX_INSTANCES];
610608
AP_Int8 _navfilter;
611609
AP_Int8 _auto_switch;
612610
AP_Int16 _sbp_logmask;
@@ -668,7 +666,7 @@ class AP_GPS
668666
// Note allowance for an additional instance to contain blended data
669667
GPS_timing timing[GPS_MAX_INSTANCES];
670668
GPS_State state[GPS_MAX_INSTANCES];
671-
AP_GPS_Backend *drivers[GPS_MAX_RECEIVERS];
669+
AP_GPS_Backend *drivers[GPS_MAX_INSTANCES];
672670
AP_HAL::UARTDriver *_port[GPS_MAX_RECEIVERS];
673671

674672
/// primary GPS instance
@@ -756,18 +754,7 @@ class AP_GPS
756754
void inject_data(uint8_t instance, const uint8_t *data, uint16_t len);
757755

758756
#if AP_GPS_BLENDED_ENABLED
759-
// GPS blending and switching
760-
Vector3f _blended_antenna_offset; // blended antenna offset
761-
float _blended_lag_sec; // blended receiver lag in seconds
762-
float _blend_weights[GPS_MAX_RECEIVERS]; // blend weight for each GPS. The blend weights must sum to 1.0 across all instances.
763757
bool _output_is_blended; // true when a blended GPS solution being output
764-
uint8_t _blend_health_counter; // 0 = perfectly health, 100 = very unhealthy
765-
766-
// calculate the blend weight. Returns true if blend could be calculated, false if not
767-
bool calc_blend_weights(void);
768-
769-
// calculate the blended state
770-
void calc_blended_state(void);
771758
#endif
772759

773760
bool should_log() const;

0 commit comments

Comments
 (0)