|
29 | 29 | #include <AP_SerialManager/AP_SerialManager.h>
|
30 | 30 |
|
31 | 31 | #include "AP_GPS_NOVA.h"
|
| 32 | +#include "AP_GPS_Blended.h" |
32 | 33 | #include "AP_GPS_ERB.h"
|
33 | 34 | #include "AP_GPS_GSOF.h"
|
34 | 35 | #include "AP_GPS_NMEA.h"
|
|
66 | 67 | #define GPS_BAUD_TIME_MS 1200
|
67 | 68 | #define GPS_TIMEOUT_MS 4000u
|
68 | 69 |
|
69 |
| -#define BLEND_COUNTER_FAILURE_INCREMENT 10 |
70 |
| - |
71 | 70 | extern const AP_HAL::HAL &hal;
|
72 | 71 |
|
73 | 72 | // baudrates to try to detect GPSes with
|
@@ -347,6 +346,11 @@ void AP_GPS::init()
|
347 | 346 | rate_ms.set(GPS_MAX_RATE_MS);
|
348 | 347 | }
|
349 | 348 | }
|
| 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 |
350 | 354 | }
|
351 | 355 |
|
352 | 356 | void AP_GPS::convert_parameters()
|
@@ -1084,25 +1088,15 @@ void AP_GPS::update_primary(void)
|
1084 | 1088 | */
|
1085 | 1089 | const bool using_moving_base = is_rtk_base(0) || is_rtk_base(1);
|
1086 | 1090 | 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(); |
1098 | 1092 | } else {
|
1099 | 1093 | _output_is_blended = false;
|
1100 |
| - _blend_health_counter = 0; |
| 1094 | + ((AP_GPS_Blended*)drivers[GPS_BLENDED_INSTANCE])->zero_health_counter(); |
1101 | 1095 | }
|
1102 | 1096 |
|
1103 | 1097 | if (_output_is_blended) {
|
1104 | 1098 | // Use the weighting to calculate blended GPS states
|
1105 |
| - calc_blended_state(); |
| 1099 | + ((AP_GPS_Blended*)drivers[GPS_BLENDED_INSTANCE])->calc_state(); |
1106 | 1100 | // set primary to the virtual instance
|
1107 | 1101 | primary_instance = GPS_BLENDED_INSTANCE;
|
1108 | 1102 | return;
|
@@ -1695,10 +1689,7 @@ bool AP_GPS::get_lag(uint8_t instance, float &lag_sec) const
|
1695 | 1689 | #if AP_GPS_BLENDED_ENABLED
|
1696 | 1690 | // return lag of blended GPS
|
1697 | 1691 | 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); |
1702 | 1693 | }
|
1703 | 1694 | #endif
|
1704 | 1695 |
|
@@ -1732,7 +1723,7 @@ const Vector3f &AP_GPS::get_antenna_offset(uint8_t instance) const
|
1732 | 1723 | #if AP_GPS_BLENDED_ENABLED
|
1733 | 1724 | if (instance == GPS_BLENDED_INSTANCE) {
|
1734 | 1725 | // return an offset for the blended GPS solution
|
1735 |
| - return _blended_antenna_offset; |
| 1726 | + return ((AP_GPS_Blended*)drivers[instance])->get_antenna_offset(); |
1736 | 1727 | }
|
1737 | 1728 | #endif
|
1738 | 1729 |
|
@@ -1788,12 +1779,6 @@ bool AP_GPS::is_healthy(uint8_t instance) const
|
1788 | 1779 | }
|
1789 | 1780 | #endif // HAL_BUILD_AP_PERIPH
|
1790 | 1781 |
|
1791 |
| -#if AP_GPS_BLENDED_ENABLED |
1792 |
| - if (instance == GPS_BLENDED_INSTANCE) { |
1793 |
| - return blend_health_check(); |
1794 |
| - } |
1795 |
| -#endif |
1796 |
| - |
1797 | 1782 | return drivers[instance] != nullptr &&
|
1798 | 1783 | drivers[instance]->is_healthy();
|
1799 | 1784 | }
|
@@ -1827,6 +1812,14 @@ bool AP_GPS::backends_healthy(char failure_msg[], uint16_t failure_msg_len) {
|
1827 | 1812 | }
|
1828 | 1813 | }
|
1829 | 1814 | }
|
| 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 | + |
1830 | 1823 | return true;
|
1831 | 1824 | }
|
1832 | 1825 |
|
|
0 commit comments