2014-03-28 16:52:27 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-09-08 02:06:56 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2010-09-08 02:06:56 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-02-17 21:25:23 -04:00
|
|
|
#pragma once
|
2012-12-18 20:40:18 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-03-28 16:52:27 -03:00
|
|
|
#include <inttypes.h>
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
2019-01-01 23:11:38 -04:00
|
|
|
#include <AP_Common/Location.h>
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
2014-03-28 16:52:27 -03:00
|
|
|
#include "GPS_detect_state.h"
|
2020-09-03 06:15:35 -03:00
|
|
|
#include <AP_MSP/msp.h>
|
2020-12-28 18:42:14 -04:00
|
|
|
#include <AP_ExternalAHRS/AP_ExternalAHRS.h>
|
2022-01-15 00:26:06 -04:00
|
|
|
#include <SITL/SIM_GPS.h>
|
2022-07-11 04:57:40 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2014-03-28 16:52:27 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
maximum number of GPS instances available on this platform. If more
|
2017-01-05 14:07:14 -04:00
|
|
|
than 1 then redundant sensors may be available
|
2014-03-28 16:52:27 -03:00
|
|
|
*/
|
2019-05-26 22:34:13 -03:00
|
|
|
#ifndef GPS_MAX_RECEIVERS
|
2017-01-29 19:02:57 -04:00
|
|
|
#define GPS_MAX_RECEIVERS 2 // maximum number of physical GPS sensors allowed - does not include virtual GPS created by blending receiver data
|
2019-05-26 22:34:13 -03:00
|
|
|
#endif
|
2021-09-30 02:16:55 -03:00
|
|
|
#if !defined(GPS_MAX_INSTANCES)
|
|
|
|
#if GPS_MAX_RECEIVERS > 1
|
2019-01-04 00:40:41 -04:00
|
|
|
#define GPS_MAX_INSTANCES (GPS_MAX_RECEIVERS + 1) // maximum number of GPS instances including the 'virtual' GPS created by blending receiver data
|
2021-09-30 02:16:55 -03:00
|
|
|
#else
|
|
|
|
#define GPS_MAX_INSTANCES 1
|
|
|
|
#endif // GPS_MAX_RECEIVERS > 1
|
|
|
|
#endif // GPS_MAX_INSTANCES
|
|
|
|
|
|
|
|
#if GPS_MAX_RECEIVERS <= 1 && GPS_MAX_INSTANCES > 1
|
|
|
|
#error "GPS_MAX_INSTANCES should be 1 for GPS_MAX_RECEIVERS <= 1"
|
2019-05-26 22:34:13 -03:00
|
|
|
#endif
|
2021-09-30 02:16:55 -03:00
|
|
|
|
2019-05-26 22:34:13 -03:00
|
|
|
#if GPS_MAX_INSTANCES > GPS_MAX_RECEIVERS
|
2017-03-10 02:46:16 -04:00
|
|
|
#define GPS_BLENDED_INSTANCE GPS_MAX_RECEIVERS // the virtual blended GPS is always the highest instance (2)
|
2019-05-26 22:34:13 -03:00
|
|
|
#endif
|
2017-05-24 16:19:10 -03:00
|
|
|
#define GPS_UNKNOWN_DOP UINT16_MAX // set unknown DOP's to maximum value, which is also correct for MAVLink
|
2015-06-27 04:26:25 -03:00
|
|
|
|
2021-10-12 20:16:03 -03:00
|
|
|
// the number of GPS leap seconds - copied into SIM_GPS.cpp
|
2017-01-10 05:58:42 -04:00
|
|
|
#define GPS_LEAPSECONDS_MILLIS 18000ULL
|
|
|
|
|
2017-05-05 07:09:29 -03:00
|
|
|
#define UNIX_OFFSET_MSEC (17000ULL * 86400ULL + 52ULL * 10ULL * AP_MSEC_PER_WEEK - GPS_LEAPSECONDS_MILLIS)
|
2017-02-03 18:51:15 -04:00
|
|
|
|
2020-09-29 16:47:37 -03:00
|
|
|
#ifndef GPS_MOVING_BASELINE
|
|
|
|
#define GPS_MOVING_BASELINE !HAL_MINIMIZE_FEATURES && GPS_MAX_RECEIVERS>1
|
2020-04-03 03:52:42 -03:00
|
|
|
#endif
|
|
|
|
|
2020-09-03 06:15:35 -03:00
|
|
|
#ifndef HAL_MSP_GPS_ENABLED
|
2020-09-14 00:40:07 -03:00
|
|
|
#define HAL_MSP_GPS_ENABLED HAL_MSP_SENSORS_ENABLED
|
2020-09-03 06:15:35 -03:00
|
|
|
#endif
|
|
|
|
|
2020-09-29 16:47:37 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
#include "MovingBase.h"
|
|
|
|
#endif // GPS_MOVING_BASELINE
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
class AP_GPS_Backend;
|
|
|
|
|
|
|
|
/// @class AP_GPS
|
|
|
|
/// GPS driver main class
|
|
|
|
class AP_GPS
|
|
|
|
{
|
2017-03-08 06:11:38 -04:00
|
|
|
friend class AP_GPS_ERB;
|
|
|
|
friend class AP_GPS_GSOF;
|
|
|
|
friend class AP_GPS_MAV;
|
2020-09-03 06:15:35 -03:00
|
|
|
friend class AP_GPS_MSP;
|
2020-12-28 18:42:14 -04:00
|
|
|
friend class AP_GPS_ExternalAHRS;
|
2017-03-08 06:11:38 -04:00
|
|
|
friend class AP_GPS_NMEA;
|
|
|
|
friend class AP_GPS_NOVA;
|
|
|
|
friend class AP_GPS_PX4;
|
|
|
|
friend class AP_GPS_SBF;
|
|
|
|
friend class AP_GPS_SBP;
|
2017-03-27 22:13:31 -03:00
|
|
|
friend class AP_GPS_SBP2;
|
2017-03-08 06:11:38 -04:00
|
|
|
friend class AP_GPS_SIRF;
|
|
|
|
friend class AP_GPS_UBLOX;
|
|
|
|
friend class AP_GPS_Backend;
|
2020-12-28 10:30:41 -04:00
|
|
|
friend class AP_GPS_UAVCAN;
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2017-08-08 12:34:13 -03:00
|
|
|
public:
|
2017-12-12 21:06:12 -04:00
|
|
|
AP_GPS();
|
2017-08-08 12:34:13 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_GPS);
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2019-04-05 03:21:03 -03:00
|
|
|
static AP_GPS *get_singleton() {
|
|
|
|
return _singleton;
|
2017-10-24 22:30:10 -03:00
|
|
|
}
|
|
|
|
|
2020-01-03 20:06:05 -04:00
|
|
|
// allow threads to lock against GPS update
|
|
|
|
HAL_Semaphore &get_semaphore(void) {
|
|
|
|
return rsem;
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// GPS driver types
|
|
|
|
enum GPS_Type {
|
|
|
|
GPS_TYPE_NONE = 0,
|
|
|
|
GPS_TYPE_AUTO = 1,
|
|
|
|
GPS_TYPE_UBLOX = 2,
|
2021-09-27 22:12:31 -03:00
|
|
|
// GPS_TYPE_MTK = 3, // driver removed
|
|
|
|
// GPS_TYPE_MTK19 = 4, // driver removed
|
2014-03-28 16:52:27 -03:00
|
|
|
GPS_TYPE_NMEA = 5,
|
2014-04-01 03:25:15 -03:00
|
|
|
GPS_TYPE_SIRF = 6,
|
2014-04-04 20:05:54 -03:00
|
|
|
GPS_TYPE_HIL = 7,
|
2014-11-03 08:37:06 -04:00
|
|
|
GPS_TYPE_SBP = 8,
|
2017-04-02 11:56:26 -03:00
|
|
|
GPS_TYPE_UAVCAN = 9,
|
2015-09-02 06:13:38 -03:00
|
|
|
GPS_TYPE_SBF = 10,
|
2016-10-16 21:56:34 -03:00
|
|
|
GPS_TYPE_GSOF = 11,
|
2016-01-18 17:54:40 -04:00
|
|
|
GPS_TYPE_ERB = 13,
|
2016-05-19 20:24:08 -03:00
|
|
|
GPS_TYPE_MAV = 14,
|
2017-05-28 01:11:31 -03:00
|
|
|
GPS_TYPE_NOVA = 15,
|
|
|
|
GPS_TYPE_HEMI = 16, // hemisphere NMEA
|
2019-11-16 00:26:28 -04:00
|
|
|
GPS_TYPE_UBLOX_RTK_BASE = 17,
|
|
|
|
GPS_TYPE_UBLOX_RTK_ROVER = 18,
|
2020-09-03 06:15:35 -03:00
|
|
|
GPS_TYPE_MSP = 19,
|
2020-11-11 19:04:14 -04:00
|
|
|
GPS_TYPE_ALLYSTAR = 20, // AllyStar NMEA
|
2020-12-28 18:42:14 -04:00
|
|
|
GPS_TYPE_EXTERNAL_AHRS = 21,
|
2021-08-11 07:13:55 -03:00
|
|
|
GPS_TYPE_UAVCAN_RTK_BASE = 22,
|
|
|
|
GPS_TYPE_UAVCAN_RTK_ROVER = 23,
|
2022-01-15 00:26:06 -04:00
|
|
|
#if HAL_SIM_GPS_ENABLED
|
|
|
|
GPS_TYPE_SITL = 100,
|
|
|
|
#endif
|
2014-03-28 16:52:27 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// GPS status codes
|
|
|
|
enum GPS_Status {
|
2016-10-16 21:56:34 -03:00
|
|
|
NO_GPS = GPS_FIX_TYPE_NO_GPS, ///< No GPS connected/detected
|
|
|
|
NO_FIX = GPS_FIX_TYPE_NO_FIX, ///< Receiving valid GPS messages but no lock
|
|
|
|
GPS_OK_FIX_2D = GPS_FIX_TYPE_2D_FIX, ///< Receiving valid messages and 2D lock
|
|
|
|
GPS_OK_FIX_3D = GPS_FIX_TYPE_3D_FIX, ///< Receiving valid messages and 3D lock
|
|
|
|
GPS_OK_FIX_3D_DGPS = GPS_FIX_TYPE_DGPS, ///< Receiving valid messages and 3D lock with differential improvements
|
|
|
|
GPS_OK_FIX_3D_RTK_FLOAT = GPS_FIX_TYPE_RTK_FLOAT, ///< Receiving valid messages and 3D RTK Float
|
|
|
|
GPS_OK_FIX_3D_RTK_FIXED = GPS_FIX_TYPE_RTK_FIXED, ///< Receiving valid messages and 3D RTK Fixed
|
2014-03-28 16:52:27 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// GPS navigation engine settings. Not all GPS receivers support
|
|
|
|
// this
|
|
|
|
enum GPS_Engine_Setting {
|
|
|
|
GPS_ENGINE_NONE = -1,
|
|
|
|
GPS_ENGINE_PORTABLE = 0,
|
|
|
|
GPS_ENGINE_STATIONARY = 2,
|
|
|
|
GPS_ENGINE_PEDESTRIAN = 3,
|
|
|
|
GPS_ENGINE_AUTOMOTIVE = 4,
|
|
|
|
GPS_ENGINE_SEA = 5,
|
|
|
|
GPS_ENGINE_AIRBORNE_1G = 6,
|
|
|
|
GPS_ENGINE_AIRBORNE_2G = 7,
|
|
|
|
GPS_ENGINE_AIRBORNE_4G = 8
|
|
|
|
};
|
|
|
|
|
2019-11-16 00:26:28 -04:00
|
|
|
// role for auto-config
|
|
|
|
enum GPS_Role {
|
|
|
|
GPS_ROLE_NORMAL,
|
|
|
|
GPS_ROLE_MB_BASE,
|
|
|
|
GPS_ROLE_MB_ROVER,
|
|
|
|
};
|
2016-02-02 03:58:33 -04:00
|
|
|
|
2014-03-31 06:48:22 -03:00
|
|
|
/*
|
|
|
|
The GPS_State structure is filled in by the backend driver as it
|
|
|
|
parses each message from the GPS.
|
|
|
|
*/
|
2014-03-28 16:52:27 -03:00
|
|
|
struct GPS_State {
|
|
|
|
uint8_t instance; // the instance number of this GPS
|
|
|
|
|
|
|
|
// all the following fields must all be filled by the backend driver
|
|
|
|
GPS_Status status; ///< driver fix status
|
|
|
|
uint32_t time_week_ms; ///< GPS time (milliseconds from start of GPS week)
|
|
|
|
uint16_t time_week; ///< GPS week number
|
|
|
|
Location location; ///< last fix location
|
|
|
|
float ground_speed; ///< ground speed in m/sec
|
2016-05-04 22:28:35 -03:00
|
|
|
float ground_course; ///< ground course in degrees
|
2017-05-28 01:11:31 -03:00
|
|
|
float gps_yaw; ///< GPS derived yaw information, if available (degrees)
|
2021-07-20 04:36:45 -03:00
|
|
|
uint32_t gps_yaw_time_ms; ///< timestamp of last GPS yaw reading
|
2019-12-22 19:03:58 -04:00
|
|
|
bool gps_yaw_configured; ///< GPS is configured to provide yaw
|
2014-04-01 17:49:29 -03:00
|
|
|
uint16_t hdop; ///< horizontal dilution of precision in cm
|
2015-09-07 19:22:12 -03:00
|
|
|
uint16_t vdop; ///< vertical dilution of precision in cm
|
2017-03-27 22:13:31 -03:00
|
|
|
uint8_t num_sats; ///< Number of visible satellites
|
2017-05-02 11:52:05 -03:00
|
|
|
Vector3f velocity; ///< 3D velocity in m/s, in NED format
|
2017-07-01 15:17:24 -03:00
|
|
|
float speed_accuracy; ///< 3D velocity RMS accuracy estimate in m/s
|
|
|
|
float horizontal_accuracy; ///< horizontal RMS accuracy estimate in m
|
|
|
|
float vertical_accuracy; ///< vertical RMS accuracy estimate in m
|
2019-09-03 16:32:09 -03:00
|
|
|
float gps_yaw_accuracy; ///< heading accuracy of the GPS in degrees
|
2018-07-25 16:53:52 -03:00
|
|
|
bool have_vertical_velocity; ///< does GPS give vertical velocity? Set to true only once available.
|
|
|
|
bool have_speed_accuracy; ///< does GPS give speed accuracy? Set to true only once available.
|
|
|
|
bool have_horizontal_accuracy; ///< does GPS give horizontal position accuracy? Set to true only once available.
|
|
|
|
bool have_vertical_accuracy; ///< does GPS give vertical position accuracy? Set to true only once available.
|
2017-05-28 01:11:31 -03:00
|
|
|
bool have_gps_yaw; ///< does GPS give yaw? Set to true only once available.
|
2019-09-03 16:32:09 -03:00
|
|
|
bool have_gps_yaw_accuracy; ///< does the GPS give a heading accuracy estimate? Set to true only once available
|
2022-07-28 05:42:01 -03:00
|
|
|
float undulation; //<height that WGS84 is above AMSL at the current location
|
|
|
|
bool have_undulation; ///<do we have a value for the undulation
|
2014-03-28 16:52:27 -03:00
|
|
|
uint32_t last_gps_time_ms; ///< the system time we got the last GPS timestamp, milliseconds
|
2022-01-16 08:15:59 -04:00
|
|
|
uint64_t last_corrected_gps_time_us;///< the system time we got the last corrected GPS timestamp, microseconds
|
2022-01-18 06:42:57 -04:00
|
|
|
bool corrected_timestamp_updated; ///< true if the corrected timestamp has been updated
|
2020-08-21 02:05:14 -03:00
|
|
|
uint32_t lagged_sample_count; ///< number of samples with 50ms more lag than expected
|
2017-07-05 13:10:14 -03:00
|
|
|
|
|
|
|
// all the following fields must only all be filled by RTK capable backend drivers
|
2017-07-19 09:12:04 -03:00
|
|
|
uint32_t rtk_time_week_ms; ///< GPS Time of Week of last baseline in milliseconds
|
|
|
|
uint16_t rtk_week_number; ///< GPS Week Number of last baseline
|
2017-07-05 13:10:14 -03:00
|
|
|
uint32_t rtk_age_ms; ///< GPS age of last baseline correction in milliseconds (0 when no corrections, 0xFFFFFFFF indicates overflow)
|
|
|
|
uint8_t rtk_num_sats; ///< Current number of satellites used for RTK calculation
|
2017-07-19 09:12:04 -03:00
|
|
|
uint8_t rtk_baseline_coords_type; ///< Coordinate system of baseline. 0 == ECEF, 1 == NED
|
|
|
|
int32_t rtk_baseline_x_mm; ///< Current baseline in ECEF x or NED north component in mm
|
|
|
|
int32_t rtk_baseline_y_mm; ///< Current baseline in ECEF y or NED east component in mm
|
|
|
|
int32_t rtk_baseline_z_mm; ///< Current baseline in ECEF z or NED down component in mm
|
|
|
|
uint32_t rtk_accuracy; ///< Current estimate of 3D baseline accuracy (receiver dependent, typical 0 to 9999)
|
|
|
|
int32_t rtk_iar_num_hypotheses; ///< Current number of integer ambiguity hypotheses
|
2021-08-11 07:13:55 -03:00
|
|
|
|
|
|
|
// UBX Relative Position and Heading message information
|
|
|
|
float relPosHeading; ///< Reported Heading in degrees
|
|
|
|
float relPosLength; ///< Reported Position horizontal distance in meters
|
|
|
|
float relPosD; ///< Reported Vertical distance in meters
|
|
|
|
float accHeading; ///< Reported Heading Accuracy in degrees
|
|
|
|
uint32_t relposheading_ts; ///< True if new data has been received since last time it was false
|
2014-03-28 16:52:27 -03:00
|
|
|
};
|
|
|
|
|
2017-03-08 06:11:38 -04:00
|
|
|
/// Startup initialisation.
|
2022-02-25 01:06:28 -04:00
|
|
|
void init(const class AP_SerialManager& serial_manager);
|
2017-03-08 06:11:38 -04:00
|
|
|
|
|
|
|
/// Update GPS state based on possible bytes received from the module.
|
|
|
|
/// This routine must be called periodically (typically at 10Hz or
|
|
|
|
/// more) to process incoming data.
|
|
|
|
void update(void);
|
|
|
|
|
2016-05-19 20:24:08 -03:00
|
|
|
// Pass mavlink data to message handlers (for MAV type)
|
2019-04-30 07:22:48 -03:00
|
|
|
void handle_msg(const mavlink_message_t &msg);
|
2020-09-03 06:15:35 -03:00
|
|
|
#if HAL_MSP_GPS_ENABLED
|
|
|
|
void handle_msp(const MSP::msp_gps_data_message_t &pkt);
|
|
|
|
#endif
|
2020-12-28 18:42:14 -04:00
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
void handle_external(const AP_ExternalAHRS::gps_data_message_t &pkt);
|
|
|
|
#endif
|
2016-05-19 20:24:08 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// Accessor functions
|
|
|
|
|
2014-04-03 18:32:34 -03:00
|
|
|
// return number of active GPS sensors. Note that if the first GPS
|
2017-01-29 19:02:57 -04:00
|
|
|
// is not present but the 2nd is then we return 2. Note that a blended
|
2017-03-07 23:33:31 -04:00
|
|
|
// GPS solution is treated as an additional sensor.
|
2017-03-08 05:56:52 -04:00
|
|
|
uint8_t num_sensors(void) const;
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2017-01-29 19:02:57 -04:00
|
|
|
// Return the index of the primary sensor which is the index of the sensor contributing to
|
2017-03-07 23:33:31 -04:00
|
|
|
// the output. A blended solution is available as an additional instance
|
2014-06-06 18:58:11 -03:00
|
|
|
uint8_t primary_sensor(void) const {
|
|
|
|
return primary_instance;
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
/// Query GPS status
|
|
|
|
GPS_Status status(uint8_t instance) const {
|
2018-09-04 23:37:18 -03:00
|
|
|
if (_force_disable_gps && state[instance].status > NO_FIX) {
|
|
|
|
return NO_FIX;
|
|
|
|
}
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].status;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
GPS_Status status(void) const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return status(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:04:06 -03:00
|
|
|
// return a single human-presentable character representing the
|
|
|
|
// fix type. For space-constrained human-readable displays
|
|
|
|
char status_onechar(void) const {
|
|
|
|
switch (status()) {
|
|
|
|
case AP_GPS::NO_GPS:
|
|
|
|
return ' ';
|
|
|
|
case AP_GPS::NO_FIX:
|
|
|
|
return '-';
|
|
|
|
case AP_GPS::GPS_OK_FIX_2D:
|
|
|
|
return '2';
|
|
|
|
case AP_GPS::GPS_OK_FIX_3D:
|
|
|
|
return '3';
|
|
|
|
case AP_GPS::GPS_OK_FIX_3D_DGPS:
|
|
|
|
return '4';
|
|
|
|
case AP_GPS::GPS_OK_FIX_3D_RTK_FLOAT:
|
|
|
|
return '5';
|
|
|
|
case AP_GPS::GPS_OK_FIX_3D_RTK_FIXED:
|
|
|
|
return '6';
|
|
|
|
}
|
|
|
|
// should never reach here; compiler flags guarantees this.
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
|
2017-03-08 05:49:58 -04:00
|
|
|
// Query the highest status this GPS supports (always reports GPS_OK_FIX_3D for the blended GPS)
|
2014-06-06 18:58:11 -03:00
|
|
|
GPS_Status highest_supported_status(uint8_t instance) const;
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// location of last fix
|
|
|
|
const Location &location(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].location;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
const Location &location() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return location(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2022-07-28 05:42:01 -03:00
|
|
|
// get the difference between WGS84 and AMSL. A positive value means
|
|
|
|
// the AMSL height is higher than WGS84 ellipsoid height
|
|
|
|
bool get_undulation(uint8_t instance, float &undulation) const;
|
|
|
|
|
|
|
|
// get the difference between WGS84 and AMSL. A positive value means
|
|
|
|
// the AMSL height is higher than WGS84 ellipsoid height
|
|
|
|
bool get_undulation(float &undulation) const {
|
|
|
|
return get_undulation(primary_instance, undulation);
|
|
|
|
}
|
|
|
|
|
2017-03-08 05:56:52 -04:00
|
|
|
// report speed accuracy
|
|
|
|
bool speed_accuracy(uint8_t instance, float &sacc) const;
|
2014-10-28 16:44:07 -03:00
|
|
|
bool speed_accuracy(float &sacc) const {
|
|
|
|
return speed_accuracy(primary_instance, sacc);
|
|
|
|
}
|
|
|
|
|
2017-03-08 05:56:52 -04:00
|
|
|
bool horizontal_accuracy(uint8_t instance, float &hacc) const;
|
2014-10-28 16:44:07 -03:00
|
|
|
bool horizontal_accuracy(float &hacc) const {
|
|
|
|
return horizontal_accuracy(primary_instance, hacc);
|
|
|
|
}
|
|
|
|
|
2017-03-08 05:56:52 -04:00
|
|
|
bool vertical_accuracy(uint8_t instance, float &vacc) const;
|
2014-10-28 16:44:07 -03:00
|
|
|
bool vertical_accuracy(float &vacc) const {
|
|
|
|
return vertical_accuracy(primary_instance, vacc);
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// 3D velocity in NED format
|
|
|
|
const Vector3f &velocity(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].velocity;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
const Vector3f &velocity() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return velocity(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ground speed in m/s
|
|
|
|
float ground_speed(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].ground_speed;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
float ground_speed() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return ground_speed(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ground speed in cm/s
|
2021-02-01 12:26:28 -04:00
|
|
|
uint32_t ground_speed_cm(void) const {
|
2014-03-28 16:52:27 -03:00
|
|
|
return ground_speed() * 100;
|
|
|
|
}
|
|
|
|
|
2017-03-08 06:01:29 -04:00
|
|
|
// ground course in degrees
|
2016-05-04 22:28:35 -03:00
|
|
|
float ground_course(uint8_t instance) const {
|
|
|
|
return state[instance].ground_course;
|
|
|
|
}
|
|
|
|
float ground_course() const {
|
|
|
|
return ground_course(primary_instance);
|
|
|
|
}
|
2017-03-08 06:01:29 -04:00
|
|
|
// ground course in centi-degrees
|
2014-03-28 16:52:27 -03:00
|
|
|
int32_t ground_course_cd(uint8_t instance) const {
|
2016-05-04 22:28:35 -03:00
|
|
|
return ground_course(instance) * 100;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
int32_t ground_course_cd() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return ground_course_cd(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2017-05-28 01:11:31 -03:00
|
|
|
// yaw in degrees if available
|
2021-07-20 04:36:45 -03:00
|
|
|
bool gps_yaw_deg(uint8_t instance, float &yaw_deg, float &accuracy_deg, uint32_t &time_ms) const;
|
|
|
|
bool gps_yaw_deg(float &yaw_deg, float &accuracy_deg, uint32_t &time_ms) const {
|
|
|
|
return gps_yaw_deg(primary_instance, yaw_deg, accuracy_deg, time_ms);
|
2017-05-28 01:11:31 -03:00
|
|
|
}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// number of locked satellites
|
|
|
|
uint8_t num_sats(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].num_sats;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
uint8_t num_sats() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return num_sats(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GPS time of week in milliseconds
|
|
|
|
uint32_t time_week_ms(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].time_week_ms;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
uint32_t time_week_ms() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return time_week_ms(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GPS week
|
|
|
|
uint16_t time_week(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].time_week;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
uint16_t time_week() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return time_week(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// horizontal dilution of precision
|
2014-04-01 17:49:29 -03:00
|
|
|
uint16_t get_hdop(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].hdop;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
2014-04-01 17:49:29 -03:00
|
|
|
uint16_t get_hdop() const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return get_hdop(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2015-09-07 19:37:13 -03:00
|
|
|
// vertical dilution of precision
|
|
|
|
uint16_t get_vdop(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return state[instance].vdop;
|
2015-09-07 19:37:13 -03:00
|
|
|
}
|
|
|
|
uint16_t get_vdop() const {
|
|
|
|
return get_vdop(primary_instance);
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// the time we got our last fix in system milliseconds. This is
|
|
|
|
// used when calculating how far we might have moved since that fix
|
|
|
|
uint32_t last_fix_time_ms(uint8_t instance) const {
|
2015-11-03 09:17:25 -04:00
|
|
|
return timing[instance].last_fix_time_ms;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
uint32_t last_fix_time_ms(void) const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return last_fix_time_ms(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2015-11-03 09:17:25 -04:00
|
|
|
// the time we last processed a message in milliseconds. This is
|
|
|
|
// used to indicate that we have new GPS data to process
|
|
|
|
uint32_t last_message_time_ms(uint8_t instance) const {
|
|
|
|
return timing[instance].last_message_time_ms;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
uint32_t last_message_time_ms(void) const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return last_message_time_ms(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2017-07-08 20:06:19 -03:00
|
|
|
// system time delta between the last two reported positions
|
|
|
|
uint16_t last_message_delta_time_ms(uint8_t instance) const {
|
|
|
|
return timing[instance].delta_time_ms;
|
|
|
|
}
|
|
|
|
uint16_t last_message_delta_time_ms(void) const {
|
|
|
|
return last_message_delta_time_ms(primary_instance);
|
|
|
|
}
|
|
|
|
|
2017-07-01 15:17:24 -03:00
|
|
|
// return true if the GPS supports vertical velocity values
|
2017-03-27 22:13:31 -03:00
|
|
|
bool have_vertical_velocity(uint8_t instance) const {
|
|
|
|
return state[instance].have_vertical_velocity;
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
2017-03-27 22:13:31 -03:00
|
|
|
bool have_vertical_velocity(void) const {
|
2014-04-03 18:32:34 -03:00
|
|
|
return have_vertical_velocity(primary_instance);
|
2014-03-28 16:52:27 -03:00
|
|
|
}
|
|
|
|
|
2019-12-22 19:03:58 -04:00
|
|
|
// return true if the GPS currently has yaw available
|
2017-05-28 01:11:31 -03:00
|
|
|
bool have_gps_yaw(uint8_t instance) const {
|
2020-05-20 23:24:02 -03:00
|
|
|
return !_force_disable_gps_yaw && state[instance].have_gps_yaw;
|
2017-05-28 01:11:31 -03:00
|
|
|
}
|
|
|
|
bool have_gps_yaw(void) const {
|
|
|
|
return have_gps_yaw(primary_instance);
|
|
|
|
}
|
2019-12-22 19:03:58 -04:00
|
|
|
|
|
|
|
// return true if the GPS is configured to provide yaw. This will
|
|
|
|
// be true if we expect the GPS to provide yaw, even if it
|
|
|
|
// currently is not able to provide yaw
|
|
|
|
bool have_gps_yaw_configured(uint8_t instance) const {
|
|
|
|
return state[instance].gps_yaw_configured;
|
|
|
|
}
|
2017-05-28 01:11:31 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// the expected lag (in seconds) in the position and velocity readings from the gps
|
2017-05-21 22:07:26 -03:00
|
|
|
// return true if the GPS hardware configuration is known or the lag parameter has been set manually
|
|
|
|
bool get_lag(uint8_t instance, float &lag_sec) const;
|
|
|
|
bool get_lag(float &lag_sec) const {
|
|
|
|
return get_lag(primary_instance, lag_sec);
|
|
|
|
}
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2017-01-05 14:07:14 -04:00
|
|
|
// return a 3D vector defining the offset of the GPS antenna in meters relative to the body frame origin
|
2017-03-08 05:56:52 -04:00
|
|
|
const Vector3f &get_antenna_offset(uint8_t instance) const;
|
2016-10-07 19:04:14 -03:00
|
|
|
|
2017-03-08 06:11:38 -04:00
|
|
|
// lock out a GPS port, allowing another application to use the port
|
|
|
|
void lock_port(uint8_t instance, bool locked);
|
|
|
|
|
|
|
|
//MAVLink Status Sending
|
|
|
|
void send_mavlink_gps_raw(mavlink_channel_t chan);
|
|
|
|
void send_mavlink_gps2_raw(mavlink_channel_t chan);
|
|
|
|
|
2017-06-30 10:45:24 -03:00
|
|
|
void send_mavlink_gps_rtk(mavlink_channel_t chan, uint8_t inst);
|
2017-03-08 06:11:38 -04:00
|
|
|
|
2019-07-23 03:20:47 -03:00
|
|
|
// Returns true if there is an unconfigured GPS, and provides the instance number of the first non configured GPS
|
|
|
|
bool first_unconfigured_gps(uint8_t &instance) const WARN_IF_UNUSED;
|
2017-03-08 06:11:38 -04:00
|
|
|
void broadcast_first_configuration_failure_reason(void) const;
|
|
|
|
|
2017-03-08 20:47:40 -04:00
|
|
|
// pre-arm check that all GPSs are close to each other. farthest distance between GPSs (in meters) is returned
|
|
|
|
bool all_consistent(float &distance) const;
|
|
|
|
|
2017-03-10 04:12:20 -04:00
|
|
|
// pre-arm check of GPS blending. False if blending is unhealthy, True if healthy or blending is not being used
|
|
|
|
bool blend_health_check() const;
|
2017-03-08 20:47:40 -04:00
|
|
|
|
2017-03-08 06:11:38 -04:00
|
|
|
// handle sending of initialisation strings to the GPS - only used by backends
|
2022-04-09 21:29:43 -03:00
|
|
|
void send_blob_start(uint8_t instance);
|
2017-03-08 06:11:38 -04:00
|
|
|
void send_blob_start(uint8_t instance, const char *_blob, uint16_t size);
|
|
|
|
void send_blob_update(uint8_t instance);
|
|
|
|
|
|
|
|
// return last fix time since the 1/1/1970 in microseconds
|
2017-07-25 23:47:00 -03:00
|
|
|
uint64_t time_epoch_usec(uint8_t instance) const;
|
|
|
|
uint64_t time_epoch_usec(void) const {
|
2017-03-08 06:11:38 -04:00
|
|
|
return time_epoch_usec(primary_instance);
|
|
|
|
}
|
|
|
|
|
2022-01-16 08:15:59 -04:00
|
|
|
uint64_t last_message_epoch_usec(uint8_t instance) const;
|
|
|
|
uint64_t last_message_epoch_usec() const {
|
|
|
|
return last_message_epoch_usec(primary_instance);
|
|
|
|
}
|
|
|
|
|
2017-03-08 06:11:38 -04:00
|
|
|
// convert GPS week and millis to unix epoch in ms
|
2022-02-02 03:24:03 -04:00
|
|
|
static uint64_t istate_time_to_epoch_ms(uint16_t gps_week, uint32_t gps_ms);
|
2017-03-08 06:11:38 -04:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
void Write_AP_Logger_Log_Startup_messages();
|
2016-08-01 08:58:23 -03:00
|
|
|
|
2017-06-27 05:12:45 -03:00
|
|
|
// indicate which bit in LOG_BITMASK indicates gps logging enabled
|
|
|
|
void set_log_gps_bit(uint32_t bit) { _log_gps_bit = bit; }
|
2017-03-08 06:11:38 -04:00
|
|
|
|
2017-09-21 22:22:22 -03:00
|
|
|
// report if the gps is healthy (this is defined as existing, an update at a rate greater than 4Hz,
|
|
|
|
// as well as any driver specific behaviour)
|
|
|
|
bool is_healthy(uint8_t instance) const;
|
2017-07-08 20:06:19 -03:00
|
|
|
bool is_healthy(void) const { return is_healthy(primary_instance); }
|
|
|
|
|
2017-10-19 22:15:11 -03:00
|
|
|
// returns true if all GPS instances have passed all final arming checks/state changes
|
|
|
|
bool prepare_for_arming(void);
|
|
|
|
|
2020-12-28 10:30:41 -04:00
|
|
|
// returns true if all GPS backend drivers haven't seen any failure
|
|
|
|
// this is for backends to be able to spout pre arm error messages
|
|
|
|
bool backends_healthy(char failure_msg[], uint16_t failure_msg_len);
|
|
|
|
|
2019-11-12 02:16:26 -04:00
|
|
|
// returns false if any GPS drivers are not performing their logging appropriately
|
|
|
|
bool logging_failed(void) const;
|
|
|
|
|
|
|
|
bool logging_present(void) const { return _raw_data != 0; }
|
|
|
|
bool logging_enabled(void) const { return _raw_data != 0; }
|
|
|
|
|
2018-09-04 23:37:18 -03:00
|
|
|
// used to disable GPS for GPS failure testing in flight
|
|
|
|
void force_disable(bool disable) {
|
|
|
|
_force_disable_gps = disable;
|
|
|
|
}
|
|
|
|
|
2020-05-20 23:24:02 -03:00
|
|
|
// used to disable GPS yaw for GPS failure testing in flight
|
|
|
|
void set_force_disable_yaw(bool disable) {
|
|
|
|
_force_disable_gps_yaw = disable;
|
|
|
|
}
|
|
|
|
|
2019-10-21 08:11:26 -03:00
|
|
|
// handle possibly fragmented RTCM injection data
|
|
|
|
void handle_gps_rtcm_fragment(uint8_t flags, const uint8_t *data, uint8_t len);
|
|
|
|
|
2020-01-24 19:58:05 -04:00
|
|
|
// get configured type by instance
|
|
|
|
GPS_Type get_type(uint8_t instance) const {
|
|
|
|
return instance>=GPS_MAX_RECEIVERS? GPS_Type::GPS_TYPE_NONE : GPS_Type(_type[instance].get());
|
|
|
|
}
|
|
|
|
|
2020-09-03 08:48:47 -03:00
|
|
|
// get iTOW, if supported, zero otherwie
|
|
|
|
uint32_t get_itow(uint8_t instance) const;
|
|
|
|
|
2021-02-23 16:18:17 -04:00
|
|
|
bool get_error_codes(uint8_t instance, uint32_t &error_codes) const;
|
|
|
|
bool get_error_codes(uint32_t &error_codes) const { return get_error_codes(primary_instance, error_codes); }
|
|
|
|
|
2021-04-05 18:30:30 -03:00
|
|
|
enum class SBAS_Mode : int8_t {
|
|
|
|
Disabled = 0,
|
|
|
|
Enabled = 1,
|
|
|
|
DoNotChange = 2,
|
|
|
|
};
|
|
|
|
|
2021-08-11 07:13:55 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
// methods used by UAVCAN GPS driver and AP_Periph for moving baseline
|
|
|
|
void inject_MBL_data(uint8_t* data, uint16_t length);
|
|
|
|
void get_RelPosHeading(uint32_t ×tamp, float &relPosHeading, float &relPosLength, float &relPosD, float &accHeading);
|
|
|
|
bool get_RTCMV3(const uint8_t *&bytes, uint16_t &len);
|
|
|
|
void clear_RTCMV3();
|
|
|
|
#endif // GPS_MOVING_BASELINE
|
|
|
|
|
2017-06-27 05:12:45 -03:00
|
|
|
protected:
|
2014-03-28 16:52:27 -03:00
|
|
|
|
|
|
|
// configuration parameters
|
2017-01-29 19:02:57 -04:00
|
|
|
AP_Int8 _type[GPS_MAX_RECEIVERS];
|
2014-03-28 16:52:27 -03:00
|
|
|
AP_Int8 _navfilter;
|
2014-06-06 18:58:11 -03:00
|
|
|
AP_Int8 _auto_switch;
|
|
|
|
AP_Int8 _min_dgps;
|
2015-04-22 20:10:46 -03:00
|
|
|
AP_Int16 _sbp_logmask;
|
|
|
|
AP_Int8 _inject_to;
|
2015-05-21 18:07:59 -03:00
|
|
|
uint32_t _last_instance_swap_ms;
|
2021-04-05 18:30:30 -03:00
|
|
|
AP_Enum<SBAS_Mode> _sbas_mode;
|
2014-09-04 01:43:29 -03:00
|
|
|
AP_Int8 _min_elevation;
|
2015-05-04 05:18:34 -03:00
|
|
|
AP_Int8 _raw_data;
|
2017-01-29 19:02:57 -04:00
|
|
|
AP_Int8 _gnss_mode[GPS_MAX_RECEIVERS];
|
2017-03-10 02:46:16 -04:00
|
|
|
AP_Int16 _rate_ms[GPS_MAX_RECEIVERS]; // this parameter should always be accessed using get_rate_ms()
|
2015-10-28 21:40:50 -03:00
|
|
|
AP_Int8 _save_config;
|
2016-02-02 03:58:33 -04:00
|
|
|
AP_Int8 _auto_config;
|
2017-01-29 19:02:57 -04:00
|
|
|
AP_Vector3f _antenna_offset[GPS_MAX_RECEIVERS];
|
|
|
|
AP_Int16 _delay_ms[GPS_MAX_RECEIVERS];
|
2020-06-13 17:23:44 -03:00
|
|
|
AP_Int8 _com_port[GPS_MAX_RECEIVERS];
|
2017-01-29 19:02:57 -04:00
|
|
|
AP_Int8 _blend_mask;
|
|
|
|
AP_Float _blend_tc;
|
2020-04-03 00:54:15 -03:00
|
|
|
AP_Int16 _driver_options;
|
2020-10-29 19:56:09 -03:00
|
|
|
AP_Int8 _primary;
|
2021-09-30 02:16:55 -03:00
|
|
|
#if HAL_ENABLE_LIBUAVCAN_DRIVERS
|
2020-12-28 10:30:41 -04:00
|
|
|
AP_Int32 _node_id[GPS_MAX_RECEIVERS];
|
|
|
|
AP_Int32 _override_node_id[GPS_MAX_RECEIVERS];
|
|
|
|
#endif
|
2020-09-29 16:47:37 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
MovingBase mb_params[GPS_MAX_RECEIVERS];
|
|
|
|
#endif // GPS_MOVING_BASELINE
|
|
|
|
|
2017-06-27 05:12:45 -03:00
|
|
|
uint32_t _log_gps_bit = -1;
|
|
|
|
|
2022-06-14 17:43:04 -03:00
|
|
|
enum DriverOptions : int16_t {
|
|
|
|
UBX_MBUseUart2 = (1U << 0U),
|
|
|
|
SBF_UseBaseForYaw = (1U << 1U),
|
|
|
|
UBX_Use115200 = (1U << 2U),
|
|
|
|
UAVCAN_MBUseDedicatedBus = (1 << 3U),
|
2022-06-14 17:50:54 -03:00
|
|
|
HeightEllipsoid = (1U << 4),
|
2022-06-14 17:43:04 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// check if an option is set
|
|
|
|
bool option_set(const DriverOptions option) const {
|
|
|
|
return (uint8_t(_driver_options.get()) & uint8_t(option)) != 0;
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
private:
|
2017-10-24 22:30:10 -03:00
|
|
|
static AP_GPS *_singleton;
|
2020-01-18 17:57:24 -04:00
|
|
|
HAL_Semaphore rsem;
|
2017-10-24 22:30:10 -03:00
|
|
|
|
2017-06-11 04:38:11 -03:00
|
|
|
// returns the desired gps update rate in milliseconds
|
2017-07-01 15:17:24 -03:00
|
|
|
// this does not provide any guarantee that the GPS is updating at the requested
|
2017-06-11 04:38:11 -03:00
|
|
|
// rate it is simply a helper for use in the backends for determining what rate
|
|
|
|
// they should be configuring the GPS to run at
|
2017-03-08 06:11:38 -04:00
|
|
|
uint16_t get_rate_ms(uint8_t instance) const;
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
struct GPS_timing {
|
|
|
|
// the time we got our last fix in system milliseconds
|
|
|
|
uint32_t last_fix_time_ms;
|
|
|
|
|
2017-07-01 15:17:24 -03:00
|
|
|
// the time we got our last message in system milliseconds
|
2014-03-28 16:52:27 -03:00
|
|
|
uint32_t last_message_time_ms;
|
2017-07-08 20:06:19 -03:00
|
|
|
|
|
|
|
// delta time between the last pair of GPS updates in system milliseconds
|
|
|
|
uint16_t delta_time_ms;
|
2020-04-04 19:53:27 -03:00
|
|
|
|
|
|
|
// count of delayed frames
|
|
|
|
uint8_t delayed_count;
|
|
|
|
|
|
|
|
// the average time delta
|
|
|
|
float average_delta_ms;
|
2014-03-28 16:52:27 -03:00
|
|
|
};
|
2017-01-29 19:02:57 -04:00
|
|
|
// Note allowance for an additional instance to contain blended data
|
2019-03-07 17:30:37 -04:00
|
|
|
GPS_timing timing[GPS_MAX_INSTANCES];
|
|
|
|
GPS_State state[GPS_MAX_INSTANCES];
|
2017-01-29 19:02:57 -04:00
|
|
|
AP_GPS_Backend *drivers[GPS_MAX_RECEIVERS];
|
|
|
|
AP_HAL::UARTDriver *_port[GPS_MAX_RECEIVERS];
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2014-04-03 18:32:34 -03:00
|
|
|
/// primary GPS instance
|
2018-07-25 16:53:52 -03:00
|
|
|
uint8_t primary_instance;
|
2014-04-03 18:32:34 -03:00
|
|
|
|
|
|
|
/// number of GPS instances present
|
2018-07-25 16:53:52 -03:00
|
|
|
uint8_t num_instances;
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2014-04-04 17:33:34 -03:00
|
|
|
// which ports are locked
|
2018-07-25 16:53:52 -03:00
|
|
|
uint8_t locked_ports;
|
2014-04-04 17:33:34 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// state of auto-detection process, per instance
|
|
|
|
struct detect_state {
|
|
|
|
uint32_t last_baud_change_ms;
|
2016-09-24 03:16:40 -03:00
|
|
|
uint8_t current_baud;
|
2017-05-30 03:47:50 -03:00
|
|
|
bool auto_detected_baud;
|
2014-03-28 16:52:27 -03:00
|
|
|
struct UBLOX_detect_state ublox_detect_state;
|
|
|
|
struct SIRF_detect_state sirf_detect_state;
|
|
|
|
struct NMEA_detect_state nmea_detect_state;
|
2014-04-04 20:05:54 -03:00
|
|
|
struct SBP_detect_state sbp_detect_state;
|
2017-03-27 22:13:31 -03:00
|
|
|
struct SBP2_detect_state sbp2_detect_state;
|
2016-01-18 17:54:40 -04:00
|
|
|
struct ERB_detect_state erb_detect_state;
|
2017-01-29 19:02:57 -04:00
|
|
|
} detect_state[GPS_MAX_RECEIVERS];
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2014-03-31 06:48:22 -03:00
|
|
|
struct {
|
2015-10-26 08:25:44 -03:00
|
|
|
const char *blob;
|
2014-03-31 06:48:22 -03:00
|
|
|
uint16_t remaining;
|
2017-01-29 19:02:57 -04:00
|
|
|
} initblob_state[GPS_MAX_RECEIVERS];
|
2014-03-31 06:48:22 -03:00
|
|
|
|
2014-04-04 20:05:54 -03:00
|
|
|
static const uint32_t _baudrates[];
|
2015-10-26 08:25:44 -03:00
|
|
|
static const char _initialisation_blob[];
|
|
|
|
static const char _initialisation_raw_blob[];
|
2014-03-28 16:52:27 -03:00
|
|
|
|
|
|
|
void detect_instance(uint8_t instance);
|
2022-04-13 10:04:21 -03:00
|
|
|
// run detection step for one GPS instance. If this finds a GPS then it
|
|
|
|
// will return it - otherwise nullptr
|
|
|
|
AP_GPS_Backend *_detect_instance(uint8_t instance);
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
void update_instance(uint8_t instance);
|
2016-08-01 08:58:23 -03:00
|
|
|
|
2016-10-04 04:37:01 -03:00
|
|
|
/*
|
2017-03-27 22:13:31 -03:00
|
|
|
buffer for re-assembling RTCM data for GPS injection.
|
2016-10-04 04:37:01 -03:00
|
|
|
The 8 bit flags field in GPS_RTCM_DATA is interpreted as:
|
|
|
|
1 bit for "is fragmented"
|
|
|
|
2 bits for fragment number
|
|
|
|
5 bits for sequence number
|
|
|
|
|
|
|
|
The rtcm_buffer is allocated on first use. Once a block of data
|
|
|
|
is successfully reassembled it is injected into all active GPS
|
|
|
|
backends. This assumes we don't want more than 4*180=720 bytes
|
|
|
|
in a RTCM data block
|
|
|
|
*/
|
|
|
|
struct rtcm_buffer {
|
2018-07-25 16:53:52 -03:00
|
|
|
uint8_t fragments_received;
|
|
|
|
uint8_t sequence;
|
2016-10-04 04:37:01 -03:00
|
|
|
uint8_t fragment_count;
|
|
|
|
uint16_t total_length;
|
|
|
|
uint8_t buffer[MAVLINK_MSG_GPS_RTCM_DATA_FIELD_DATA_LEN*4];
|
|
|
|
} *rtcm_buffer;
|
|
|
|
|
|
|
|
// re-assemble GPS_RTCM_DATA message
|
2019-04-30 07:22:48 -03:00
|
|
|
void handle_gps_rtcm_data(const mavlink_message_t &msg);
|
|
|
|
void handle_gps_inject(const mavlink_message_t &msg);
|
2017-07-25 04:59:14 -03:00
|
|
|
|
|
|
|
//Inject a packet of raw binary to a GPS
|
2019-10-21 08:11:26 -03:00
|
|
|
void inject_data(const uint8_t *data, uint16_t len);
|
|
|
|
void inject_data(uint8_t instance, const uint8_t *data, uint16_t len);
|
2016-10-04 04:37:01 -03:00
|
|
|
|
2017-01-29 19:02:57 -04:00
|
|
|
// GPS blending and switching
|
|
|
|
Vector3f _blended_antenna_offset; // blended antenna offset
|
2019-04-04 07:47:33 -03:00
|
|
|
float _blended_lag_sec; // blended receiver lag in seconds
|
2017-01-29 19:02:57 -04:00
|
|
|
float _blend_weights[GPS_MAX_RECEIVERS]; // blend weight for each GPS. The blend weights must sum to 1.0 across all instances.
|
|
|
|
float _omega_lpf; // cutoff frequency in rad/sec of LPF applied to position offsets
|
|
|
|
bool _output_is_blended; // true when a blended GPS solution being output
|
2017-03-08 20:47:40 -04:00
|
|
|
uint8_t _blend_health_counter; // 0 = perfectly health, 100 = very unhealthy
|
2017-01-29 19:02:57 -04:00
|
|
|
|
|
|
|
// calculate the blend weight. Returns true if blend could be calculated, false if not
|
|
|
|
bool calc_blend_weights(void);
|
|
|
|
|
|
|
|
// calculate the blended state
|
|
|
|
void calc_blended_state(void);
|
2017-06-11 04:58:45 -03:00
|
|
|
|
2019-02-11 04:19:08 -04:00
|
|
|
bool should_log() const;
|
2018-04-11 09:16:23 -03:00
|
|
|
|
2019-10-23 22:46:26 -03:00
|
|
|
bool needs_uart(GPS_Type type) const;
|
|
|
|
|
2021-08-05 23:25:12 -03:00
|
|
|
#if GPS_MAX_RECEIVERS > 1
|
2019-11-17 06:04:41 -04:00
|
|
|
/// Update primary instance
|
|
|
|
void update_primary(void);
|
2021-08-05 23:25:12 -03:00
|
|
|
#endif
|
2019-12-22 19:03:58 -04:00
|
|
|
|
|
|
|
// helper function for mavlink gps yaw
|
|
|
|
uint16_t gps_yaw_cdeg(uint8_t instance) const;
|
|
|
|
|
2017-06-11 04:58:45 -03:00
|
|
|
// Auto configure types
|
|
|
|
enum GPS_AUTO_CONFIG {
|
|
|
|
GPS_AUTO_CONFIG_DISABLE = 0,
|
2021-07-16 13:21:01 -03:00
|
|
|
GPS_AUTO_CONFIG_ENABLE_SERIAL_ONLY = 1,
|
|
|
|
GPS_AUTO_CONFIG_ENABLE_ALL = 2,
|
2017-06-11 04:58:45 -03:00
|
|
|
};
|
2018-09-04 23:37:18 -03:00
|
|
|
|
2020-06-23 23:07:35 -03:00
|
|
|
enum class GPSAutoSwitch {
|
|
|
|
NONE = 0,
|
|
|
|
USE_BEST = 1,
|
|
|
|
BLEND = 2,
|
2020-10-29 19:54:05 -03:00
|
|
|
//USE_SECOND = 3, deprecated for new primary param
|
2020-10-29 19:56:09 -03:00
|
|
|
USE_PRIMARY_IF_3D_FIX = 4,
|
2020-06-23 23:07:35 -03:00
|
|
|
};
|
|
|
|
|
2018-09-04 23:37:18 -03:00
|
|
|
// used for flight testing with GPS loss
|
|
|
|
bool _force_disable_gps;
|
2019-10-28 14:14:52 -03:00
|
|
|
|
2020-05-20 23:24:02 -03:00
|
|
|
// used for flight testing with GPS yaw loss
|
|
|
|
bool _force_disable_gps_yaw;
|
2021-02-09 19:08:37 -04:00
|
|
|
|
|
|
|
// logging support
|
|
|
|
void Write_GPS(uint8_t instance);
|
|
|
|
|
2017-01-29 19:02:57 -04:00
|
|
|
};
|
2017-10-25 00:58:57 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_GPS &gps();
|
|
|
|
};
|