|
| 1 | +/* |
| 2 | + Get the RTCM 1005 sentence using getLatestRTCM1005 |
| 3 | + By: Paul Clark |
| 4 | + SparkFun Electronics |
| 5 | + Date: May 4th, 2023 |
| 6 | + License: MIT. See license file for more information. |
| 7 | +
|
| 8 | + This example shows how to perform a survey-in and then enable RTCM sentences over I2C. |
| 9 | + It then demonstrates how to use the new getLatestRTCM1005 function to retrieve the latest RTCM 1005 message. |
| 10 | + getLatestRTCM1005 returns immediately - it is not blocking. |
| 11 | + It returns: |
| 12 | + 0 if no data is available |
| 13 | + 1 if the data is valid but is stale (you have read it before) |
| 14 | + 2 if the data is valid and fresh |
| 15 | +
|
| 16 | + Feel like supporting open source hardware? |
| 17 | + Buy a board from SparkFun! |
| 18 | + SparkFun GPS-RTK2 - ZED-F9P (GPS-15136) https://www.sparkfun.com/products/15136 |
| 19 | + SparkFun GPS-RTK-SMA - ZED-F9P (GPS-16481) https://www.sparkfun.com/products/16481 |
| 20 | +
|
| 21 | + Hardware Connections: |
| 22 | + Plug a Qwiic cable into the GNSS and a RedBoard |
| 23 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 24 | + Open the serial monitor at 115200 baud to see the output |
| 25 | +*/ |
| 26 | + |
| 27 | +#include <Wire.h> //Needed for I2C to GNSS |
| 28 | + |
| 29 | +#include <SparkFun_u-blox_GNSS_v3.h> //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS_v3 |
| 30 | +SFE_UBLOX_GNSS myGNSS; |
| 31 | + |
| 32 | +void setup() |
| 33 | +{ |
| 34 | + |
| 35 | + delay(1000); |
| 36 | + |
| 37 | + Serial.begin(115200); |
| 38 | + Serial.println(F("SparkFun u-blox GNSS Example")); |
| 39 | + |
| 40 | + Wire.begin(); |
| 41 | + |
| 42 | + //myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial |
| 43 | + |
| 44 | + while (myGNSS.begin() == false) |
| 45 | + { |
| 46 | + Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring.")); |
| 47 | + delay(1000); |
| 48 | + } |
| 49 | + |
| 50 | + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 51 | + |
| 52 | + //We need to do a survey-in before the ZED will generate RTCM 1005 |
| 53 | + |
| 54 | + //Check if Survey is in Progress before initiating one |
| 55 | + bool response = myGNSS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (request can take a long time) |
| 56 | + |
| 57 | + if (response == false) // Check if fresh data was received |
| 58 | + { |
| 59 | + Serial.println(F("Failed to get Survey In status. Freezing...")); |
| 60 | + while (1); //Freeze |
| 61 | + } |
| 62 | + |
| 63 | + if (myGNSS.getSurveyInActive() == true) // Use the helper function |
| 64 | + { |
| 65 | + Serial.print(F("Survey already in progress.")); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + //Start survey - define the minimum observationTime and requiredAccuracy |
| 70 | + uint32_t observationTime = 60; float requiredAccuracy = 5.0; // 60 seconds, 5.0m |
| 71 | + |
| 72 | + response = myGNSS.enableSurveyModeFull(observationTime, requiredAccuracy, VAL_LAYER_RAM); //Enable Survey in. Save setting in RAM layer only (not BBR) |
| 73 | + |
| 74 | + if (response == false) |
| 75 | + { |
| 76 | + Serial.println(F("Survey start failed. Freezing...")); |
| 77 | + while (1); //Freeze |
| 78 | + } |
| 79 | + |
| 80 | + Serial.println(F("Survey started.")); |
| 81 | + Serial.print(F("This will run until ")); |
| 82 | + Serial.print(observationTime); |
| 83 | + Serial.print(F("s have passed _and_ better than ")); |
| 84 | + Serial.print(requiredAccuracy, 2); |
| 85 | + Serial.println(F("m accuracy is achieved.")); |
| 86 | + Serial.println(); |
| 87 | + } |
| 88 | + |
| 89 | + while(Serial.available()) Serial.read(); //Clear buffer |
| 90 | + |
| 91 | + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 92 | + |
| 93 | + //Wait for survey to complete |
| 94 | + |
| 95 | + while (myGNSS.getSurveyInValid() == false) // Call the helper function |
| 96 | + { |
| 97 | + if(Serial.available()) |
| 98 | + { |
| 99 | + byte incoming = Serial.read(); |
| 100 | + if (incoming == 'x') |
| 101 | + { |
| 102 | + //Stop survey mode |
| 103 | + response = myGNSS.disableSurveyMode(); //Disable survey |
| 104 | + Serial.println(F("Survey stopped")); |
| 105 | + break; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + response = myGNSS.getSurveyStatus(2000); //Query module for SVIN status with 2000ms timeout (req can take a long time) |
| 110 | + |
| 111 | + if (response == true) // Check if fresh data was received |
| 112 | + { |
| 113 | + Serial.print(F("\r\nPress x to end survey - ")); |
| 114 | + Serial.print(F("Time elapsed: ")); |
| 115 | + Serial.print((String)myGNSS.getSurveyInObservationTimeFull()); // Call the helper function |
| 116 | + Serial.print(F(" (")); |
| 117 | + Serial.print((String)myGNSS.packetUBXNAVSVIN->data.dur); // Read the survey-in duration directly from packetUBXNAVSVIN |
| 118 | + |
| 119 | + Serial.print(F(") Accuracy: ")); |
| 120 | + Serial.print((String)myGNSS.getSurveyInMeanAccuracy()); // Call the helper function |
| 121 | + Serial.print(F(" (")); |
| 122 | + // Read the mean accuracy directly from packetUBXNAVSVIN and manually convert from mm*0.1 to m |
| 123 | + float meanAcc = ((float)myGNSS.packetUBXNAVSVIN->data.meanAcc) / 10000.0; |
| 124 | + Serial.print((String)meanAcc); |
| 125 | + Serial.println(F(")")); |
| 126 | + } |
| 127 | + else |
| 128 | + { |
| 129 | + Serial.println(F("\r\nSVIN request failed")); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + Serial.println(F("Base survey complete. Configuring RTCM.")); |
| 134 | + |
| 135 | + // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 136 | + |
| 137 | + //Disable or enable various RTCM sentences over the I2C interface |
| 138 | + |
| 139 | + myGNSS.setI2COutput(COM_TYPE_NMEA | COM_TYPE_UBX | COM_TYPE_RTCM3); // Turn on UBX, NMEA and RTCM sentences on I2C |
| 140 | + |
| 141 | + myGNSS.newCfgValset(VAL_LAYER_RAM); // Use cfgValset to disable / enable individual RTCM messages. Save setting in RAM layer only (not BBR) |
| 142 | + myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1005_I2C, 1); // Enable RTCM 1005 (Stationary Antenna Reference Point, No Height Information) at current navigation rate |
| 143 | + myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1074_I2C, 1); // Enable RTCM 1074 (GPS MSM4). RTCM 1077 (GPS MSM7) is higher resolution but is almost twice as many bytes |
| 144 | + myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1084_I2C, 1); // Enable RTCM 1084 (GLONASS MSM4). RTCM 1087 (GLONASS MSM7) is higher resolution |
| 145 | + myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1094_I2C, 1); // Enable RTCM 1094 (Galileo MSM4). RTCM 1097 (Galileo MSM7) is higher resolution |
| 146 | + myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1124_I2C, 1); // Enable RTCM 1124 (BeiDou MSM4). RTCM 1127 (BeiDou MSM7) is higher resolution |
| 147 | + myGNSS.addCfgValset(UBLOX_CFG_MSGOUT_RTCM_3X_TYPE1230_I2C, 10); // Enable RTCM message 1230 (GLONASS L1 and L2 Code-Phase Biases) every 10 seconds |
| 148 | + if (myGNSS.sendCfgValset()) // Send the configuration VALSET |
| 149 | + Serial.println(F("RTCM messages were configured successfully")); |
| 150 | + else |
| 151 | + Serial.println(F("RTCM message configuration failed!")); |
| 152 | + |
| 153 | + //myGNSS.saveConfiguration(VAL_CFG_SUBSEC_IOPORT | VAL_CFG_SUBSEC_MSGCONF); //Optional: Save only the ioPort and message settings to NVM |
| 154 | + |
| 155 | + //myGNSS.setRTCMOutputPort(Serial); // Uncomment this line to echo all RTCM data to Serial for debugging |
| 156 | + |
| 157 | + if (sizeof(double) != 8) // Check double is 64-bit |
| 158 | + Serial.println(F("double is not 64-bit. ECEF resolution may be limited!")); |
| 159 | +} |
| 160 | + |
| 161 | +// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 162 | + |
| 163 | +void loop() |
| 164 | +{ |
| 165 | + // getLatestRTCM1005 calls checkUblox for us. We don't need to do it here |
| 166 | + |
| 167 | + RTCM_1005_data_t data; // Storage for the RTCM 1005 data |
| 168 | + uint8_t result = myGNSS.getLatestRTCM1005(&data); // Get the latest RTCM 1005 data (if any) |
| 169 | + |
| 170 | + if (result == 0) |
| 171 | + { |
| 172 | + Serial.println(F("No RTCM 1005 data available")); |
| 173 | + } |
| 174 | + else if (result == 1) |
| 175 | + { |
| 176 | + Serial.println(F("RTCM 1005 data is available but is stale")); |
| 177 | + } |
| 178 | + else // if (result == 2) |
| 179 | + { |
| 180 | + double x = data.AntennaReferencePointECEFX; |
| 181 | + x /= 10000.0; // Convert to m |
| 182 | + double y = data.AntennaReferencePointECEFY; |
| 183 | + y /= 10000.0; // Convert to m |
| 184 | + double z = data.AntennaReferencePointECEFZ; |
| 185 | + z /= 10000.0; // Convert to m |
| 186 | + |
| 187 | + Serial.print(F("Latest RTCM ")); |
| 188 | + Serial.print(data.MessageNumber); |
| 189 | + Serial.print(F(": ARP ECEF-X: ")); |
| 190 | + Serial.print(x, 4); // 4 decimal places |
| 191 | + Serial.print(F(" Y: ")); |
| 192 | + Serial.print(y, 4); // 4 decimal places |
| 193 | + Serial.print(F(" Z: ")); |
| 194 | + Serial.println(z, 4); // 4 decimal places |
| 195 | + } |
| 196 | + |
| 197 | + delay(250); |
| 198 | +} |
0 commit comments