diff --git a/src/main/config/config.c b/src/main/config/config.c index 413b753fb5..3b33359206 100755 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -134,7 +134,7 @@ static uint32_t activeFeaturesLatch = 0; static uint8_t currentControlRateProfileIndex = 0; controlRateConfig_t *currentControlRateProfile; -static const uint8_t EEPROM_CONF_VERSION = 111; +static const uint8_t EEPROM_CONF_VERSION = 112; static void resetAccelerometerTrims(flightDynamicsTrims_t * accZero, flightDynamicsTrims_t * accGain) { @@ -521,6 +521,7 @@ static void resetConf(void) masterConfig.gpsConfig.sbasMode = SBAS_AUTO; masterConfig.gpsConfig.autoConfig = GPS_AUTOCONFIG_ON; masterConfig.gpsConfig.autoBaud = GPS_AUTOBAUD_ON; + masterConfig.gpsConfig.navModel = GPS_MODEL_LOW_G; #endif #ifdef NAV diff --git a/src/main/io/gps.h b/src/main/io/gps.h index 427e494487..ea629d50db 100644 --- a/src/main/io/gps.h +++ b/src/main/io/gps.h @@ -64,6 +64,11 @@ typedef enum { GPS_AUTOBAUD_ON } gpsAutoBaud_e; +typedef enum { + GPS_MODEL_LOW_G = 0, + GPS_MODEL_HIGH_G, +} gpsNavModel_e; + #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600 typedef struct gpsConfig_s { @@ -71,6 +76,7 @@ typedef struct gpsConfig_s { sbasMode_e sbasMode; gpsAutoConfig_e autoConfig; gpsAutoBaud_e autoBaud; + gpsNavModel_e navModel; } gpsConfig_t; typedef struct gpsCoordinateDDDMMmmmm_s { diff --git a/src/main/io/gps_ublox.c b/src/main/io/gps_ublox.c index 5937a1aa2c..949244d359 100755 --- a/src/main/io/gps_ublox.c +++ b/src/main/io/gps_ublox.c @@ -46,7 +46,7 @@ #if defined(GPS) && defined(GPS_PROTO_UBLOX) #define GPS_PROTO_UBLOX_NEO7PLUS -#define GPS_VERSION_DETECTION_TIMEOUT_MS (300) +#define GPS_VERSION_DETECTION_TIMEOUT_MS 300 static const char * baudInitData[GPS_BAUDRATE_COUNT] = { "$PUBX,41,1,0003,0001,115200,0*1E\r\n", // GPS_BAUDRATE_115200 @@ -62,72 +62,61 @@ static const uint8_t ubloxVerPoll[] = { }; #endif -static const uint8_t ubloxInit6[] = { - //0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, // CFG-NAV5 - Set engine settings - //0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, // Airborne <1G - //0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x3C, 0x00, 0x00, 0x00, - //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0xE8, - - //0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x02, 0x00, // CFG-NAV5 - Set engine settings - //0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, // Airborne <1G 3D fix only - //0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x3C, 0x00, 0x00, 0x00, - //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0xC7, - - //0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x08, 0x03, 0x00, // CFG-NAV5 - Set engine settings - //0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, // Airborne <4G - //0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - //0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x20, +static const uint8_t ubloxInit_NAV5_Pedestrian[] = { + 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x03, 0x03, 0x00, // CFG-NAV5 - Set engine settings (original MWII code) + 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, // Collected by resetting a GPS unit to defaults. Changing mode to Pedistrian and + 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x3C, 0x00, 0x00, 0x00, // capturing the data from the U-Center binary console. + 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xC2 +}; +static const uint8_t ubloxInit_NAV5_Airborne4G[] = { 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x08, 0x02, 0x00, // CFG-NAV5 - Set engine settings 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, // Airborne <4G 3D fix only 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xFF +}; - // 0xB5, 0x62, 0x06, 0x23, 0x28, 0x00, 0x00, 0x00, 0x4C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // CFG-NAVX5 min 5 SV - // 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xCD, +static const uint8_t ubloxInit_NAVX5[] = { + 0xB5, 0x62, 0x06, 0x23, 0x28, 0x00, 0x00, 0x00, 0x4C, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // CFG-NAVX5 min 5 SV + 0x05, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0xCD, +}; +static const uint8_t ubloxInit_MSG_NMEA[] = { // DISABLE NMEA messages 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x05, 0x00, 0xFF, 0x19, // VGS: Course over ground and Ground speed 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x03, 0x00, 0xFD, 0x15, // GSV: GNSS Satellites in View 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x01, 0x00, 0xFB, 0x11, // GLL: Latitude and longitude, with time of position fix and status 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x00, 0x00, 0xFA, 0x0F, // GGA: Global positioning system fix data 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x02, 0x00, 0xFC, 0x13, // GSA: GNSS DOP and Active Satellites - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x04, 0x00, 0xFE, 0x17, // RMC: Recommended Minimum data + 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x04, 0x00, 0xFE, 0x17 // RMC: Recommended Minimum data +}; - // Enable UBLOX messages +static const uint8_t ubloxInit_MSG_UBX_POSLLH[] = { 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x02, 0x01, 0x0E, 0x47, // set POSLLH MSG rate 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x03, 0x01, 0x0F, 0x49, // set STATUS MSG rate 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x06, 0x01, 0x12, 0x4F, // set SOL MSG rate 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x30, 0x05, 0x40, 0xA7, // set SVINFO MSG rate (evey 5 cycles - low bandwidth) - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x12, 0x01, 0x1E, 0x67, // set VELNED MSG rate - - 0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xC8, 0x00, 0x01, 0x00, 0x01, 0x00, 0xDE, 0x6A, // set rate to 5Hz (measurement period: 200ms, navigation rate: 1 cycle) + 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x12, 0x01, 0x1E, 0x67 // set VELNED MSG rate }; #ifdef GPS_PROTO_UBLOX_NEO7PLUS -static const uint8_t ubloxInit[] = { - 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x08, 0x02, 0x00, // CFG-NAV5 - Set engine settings - 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA, 0x00, // Airborne <4G 3D fix only - 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xFF, - - // DISABLE NMEA messages - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x00, 0x00, 0xFA, 0x0F, // GGA: Global positioning system fix data - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x01, 0x00, 0xFB, 0x11, // GLL: Latitude and longitude, with time of position fix and status - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x02, 0x00, 0xFC, 0x13, // GSA: GNSS DOP and Active Satellites - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x03, 0x00, 0xFD, 0x15, // GSV: GNSS Satellites in View - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x04, 0x00, 0xFE, 0x17, // RMC: Recommended Minimum data - 0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x05, 0x00, 0xFF, 0x19, // VGS: Course over ground and Ground speed - - // Enable UBLOX messages +static const uint8_t ubloxInit_MSG_UBX_PVT[] = { 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xB9, // disable POSLLH 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xC0, // disable STATUS 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xD5, // disable SOL 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x30, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x4A, 0x2D, // enable SVINFO 10 cycle 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x29, // disable VELNED - 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x18, 0xE1, // enable PVT 1 cycle + 0xB5, 0x62, 0x06, 0x01, 0x08, 0x00, 0x01, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x18, 0xE1 // enable PVT 1 cycle +}; +#endif +static const uint8_t ubloxInit_RATE_5Hz[] = { + 0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xC8, 0x00, 0x01, 0x00, 0x01, 0x00, 0xDE, 0x6A // set rate to 5Hz (measurement period: 200ms, navigation rate: 1 cycle) +}; + +#ifdef GPS_PROTO_UBLOX_NEO7PLUS +static const uint8_t ubloxInit_RATE_10Hz[] = { 0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0x64, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7A, 0x12, // set rate to 10Hz (measurement period: 100ms, navigation rate: 1 cycle) }; #endif @@ -544,55 +533,68 @@ static bool gpsNewFrameUBLOX(uint8_t data) return parsed; } +// Send UBLOX binary command data and wait until it is completely transmitted +static bool ubxTransmitAutoConfigCommands(const uint8_t * ubxCmdBuf, uint8_t ubxCmdSize) { + while (serialTxBytesFree(gpsState.gpsPort) > 0) { + if (gpsState.autoConfigPosition < ubxCmdSize) { + serialWrite(gpsState.gpsPort, ubxCmdBuf[gpsState.autoConfigPosition]); + gpsState.autoConfigPosition++; + } + else if (isSerialTransmitBufferEmpty(gpsState.gpsPort)) { + gpsState.autoConfigStep++; + gpsState.autoConfigPosition = 0; + return true; + } + else { + return false; + } + } + + return false; +} + static bool gpsConfigure(void) { switch (gpsState.autoConfigStep) { - case 0: // Config - while (serialTxBytesFree(gpsState.gpsPort) > 0) { -#ifdef GPS_PROTO_UBLOX_NEO7PLUS - if (gpsState.hwVersion < 70000) { -#endif - if (gpsState.autoConfigPosition < sizeof(ubloxInit6)) { - serialWrite(gpsState.gpsPort, ubloxInit6[gpsState.autoConfigPosition]); - gpsState.autoConfigPosition++; - } - else { - gpsState.autoConfigPosition = 0; - gpsState.autoConfigStep++; - break; - } -#ifdef GPS_PROTO_UBLOX_NEO7PLUS - } - else { - if (gpsState.autoConfigPosition < sizeof(ubloxInit)) { - serialWrite(gpsState.gpsPort, ubloxInit[gpsState.autoConfigPosition]); - gpsState.autoConfigPosition++; - } - else { - gpsState.autoConfigPosition = 0; - gpsState.autoConfigStep++; - break; - } - } -#endif - } + case 0: // NAV5 + if (gpsState.gpsConfig->navModel == GPS_MODEL_HIGH_G) + ubxTransmitAutoConfigCommands(ubloxInit_NAV5_Airborne4G, sizeof(ubloxInit_NAV5_Airborne4G)); + else + ubxTransmitAutoConfigCommands(ubloxInit_NAV5_Pedestrian, sizeof(ubloxInit_NAV5_Pedestrian)); + break; - case 1: // SBAS - while (serialTxBytesFree(gpsState.gpsPort) > 0) { - if (gpsState.autoConfigPosition < UBLOX_SBAS_MESSAGE_LENGTH) { - serialWrite(gpsState.gpsPort, ubloxSbas[gpsState.gpsConfig->sbasMode].message[gpsState.autoConfigPosition]); - gpsState.autoConfigPosition++; - } else { - gpsState.autoConfigPosition = 0; - gpsState.autoConfigStep++; - break; - } + case 1: // NAVX5 - skip + //ubxTransmitAutoConfigCommands(ubloxInit_NAVX5, sizeof(ubloxInit_NAVX5)); + gpsState.autoConfigStep++; + break; + + case 2: // Disable NMEA messages + ubxTransmitAutoConfigCommands(ubloxInit_MSG_NMEA, sizeof(ubloxInit_MSG_NMEA)); + break; + + case 3: // Enable UBX messages +#ifdef GPS_PROTO_UBLOX_NEO7PLUS + if (gpsState.hwVersion < 70000) { +#endif + ubxTransmitAutoConfigCommands(ubloxInit_MSG_UBX_POSLLH, sizeof(ubloxInit_MSG_UBX_POSLLH)); +#ifdef GPS_PROTO_UBLOX_NEO7PLUS } + else { + ubxTransmitAutoConfigCommands(ubloxInit_MSG_UBX_PVT, sizeof(ubloxInit_MSG_UBX_PVT)); + } +#endif + break; + + case 4: // Configure RATE + ubxTransmitAutoConfigCommands(ubloxInit_RATE_5Hz, sizeof(ubloxInit_RATE_5Hz)); + break; + + case 5: // SBAS + ubxTransmitAutoConfigCommands(ubloxSbas[gpsState.gpsConfig->sbasMode].message, UBLOX_SBAS_MESSAGE_LENGTH); break; default: - case 2: // ublox should be initialised, try receiving gpsSetState(GPS_RECEIVING_DATA); break; @@ -605,10 +607,7 @@ static bool gpsCheckVersion(void) { #ifdef GPS_PROTO_UBLOX_NEO7PLUS if (gpsState.autoConfigStep == 0) { - for(uint16_t i = 0; i < sizeof(ubloxVerPoll); i++) { - serialWrite(gpsState.gpsPort, ubloxVerPoll[i]); - } - gpsState.autoConfigStep++; + ubxTransmitAutoConfigCommands(ubloxVerPoll, sizeof(ubloxVerPoll)); } else { // Wait until version found diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 23f8e2c980..2febd1d205 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -386,6 +386,10 @@ static const char * const lookupTableNavControlMode[] = { static const char * const lookupTableNavRthAltMode[] = { "CURRENT", "EXTRA", "FIXED", "MAX", "AT_LEAST" }; + +static const char * const lookupTableGpsModel[] = { + "LOW_G", "HIGH_G" +}; #endif typedef struct lookupTableEntry_s { @@ -400,6 +404,7 @@ typedef enum { #ifdef GPS TABLE_GPS_PROVIDER, TABLE_GPS_SBAS_MODE, + TABLE_GPS_NAV_MODEL, #endif #ifdef BLACKBOX TABLE_BLACKBOX_DEVICE, @@ -424,6 +429,7 @@ static const lookupTableEntry_t lookupTables[] = { #ifdef GPS { lookupTableGPSProvider, sizeof(lookupTableGPSProvider) / sizeof(char *) }, { lookupTableGPSSBASMode, sizeof(lookupTableGPSSBASMode) / sizeof(char *) }, + { lookupTableGpsModel, sizeof(lookupTableGpsModel) / sizeof(char *) }, #endif #ifdef BLACKBOX { lookupTableBlackboxDevice, sizeof(lookupTableBlackboxDevice) / sizeof(char *) }, @@ -529,6 +535,7 @@ const clivalue_t valueTable[] = { #ifdef GPS { "gps_provider", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.provider, .config.lookup = { TABLE_GPS_PROVIDER }, 0 }, { "gps_sbas_mode", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.sbasMode, .config.lookup = { TABLE_GPS_SBAS_MODE }, 0 }, + { "gps_nav_model", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.navModel, .config.lookup = { TABLE_GPS_NAV_MODEL }, 0 }, { "gps_auto_config", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.autoConfig, .config.lookup = { TABLE_OFF_ON }, 0 }, { "gps_auto_baud", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.gpsConfig.autoBaud, .config.lookup = { TABLE_OFF_ON }, 0 }, #endif