|
| 1 | +/* |
| 2 | + Setting "Survey Fixed" Mode |
| 3 | + By: Nathan Seidle + Mikal Hart |
| 4 | + SparkFun Electronics |
| 5 | + Date: 29 September 2024 |
| 6 | + License: MIT. Please see LICENSE.md for more information. |
| 7 | +
|
| 8 | + This example shows how enable the fixed survey mode, where you define the BASE station's |
| 9 | + location by supplying setSurveyFixedMode with Latitude/Longitude/Altitude coordinates. |
| 10 | +
|
| 11 | + These examples are targeted for an ESP32 platform but any platform that has multiple |
| 12 | + serial UARTs should be compatible. |
| 13 | +
|
| 14 | + Feel like supporting open source hardware? |
| 15 | + Buy a board from SparkFun! |
| 16 | + SparkFun Quadband GNSS RTK Breakout - LG290P (GPS-26620) https://www.sparkfun.com/products/26620 |
| 17 | +
|
| 18 | + Hardware Connections: |
| 19 | + Connect RX3 (green wire) of the LG290P to pin 14 on the ESP32 |
| 20 | + Connect TX3 (orange wire) of the LG290P to pin 13 on the ESP32 |
| 21 | + To make this easier, a 4-pin locking JST cable can be purchased here: https://www.sparkfun.com/products/17240 |
| 22 | + Note: Almost any ESP32 pins can be used for serial. |
| 23 | + Connect a multi-band GNSS antenna: https://www.sparkfun.com/products/21801 |
| 24 | +*/ |
| 25 | + |
| 26 | +#include <SparkFun_LG290P_GNSS.h> // Click here to get the library: http://librarymanager/All#SparkFun_LG290P |
| 27 | + |
| 28 | +// Adjust these values according to your configuration |
| 29 | +int pin_UART1_TX = 14; |
| 30 | +int pin_UART1_RX = 13; |
| 31 | +int gnss_baud = 460800; |
| 32 | + |
| 33 | +LG290P myGNSS; |
| 34 | +HardwareSerial SerialGNSS(1); // Use UART1 on the ESP32 |
| 35 | +int mode; |
| 36 | + |
| 37 | +void setup() |
| 38 | +{ |
| 39 | + Serial.begin(115200); |
| 40 | + delay(250); |
| 41 | + Serial.println(); |
| 42 | + Serial.println("SparkFun Survey In Mode example"); |
| 43 | + Serial.println("Initializing device..."); |
| 44 | + |
| 45 | + // We must start the serial port before using it in the library |
| 46 | + // Increase buffer size to handle high baud rate streams |
| 47 | + SerialGNSS.setRxBufferSize(1024); |
| 48 | + SerialGNSS.begin(gnss_baud, SERIAL_8N1, pin_UART1_RX, pin_UART1_TX); |
| 49 | + |
| 50 | + // myGNSS.enableDebugging(Serial); // Print all debug to Serial |
| 51 | + if (myGNSS.begin(SerialGNSS) == false) // Give the serial port over to the library |
| 52 | + { |
| 53 | + Serial.println("LG290P failed to respond. Check ports and baud rates. Freezing..."); |
| 54 | + while (true); |
| 55 | + } |
| 56 | + Serial.println("LG290P detected!"); |
| 57 | + |
| 58 | + // You MUST be in BASE mode to set Survey In Mode |
| 59 | + Serial.println("Setting base station mode"); |
| 60 | + verify(myGNSS.setModeBase(false)); // don't reset, because setSurveyInMode() is going to do it |
| 61 | + |
| 62 | + double eiffelLat = 48.8584, eiffelLong = 2.2945, eiffelAlt = 365; |
| 63 | + double ecefX, ecefY, ecefZ; |
| 64 | + |
| 65 | + // Convert Eiffel Tower lat/long/alt to ECEF coordinates |
| 66 | + LG290P::geodeticToEcef(eiffelLat, eiffelLong, eiffelAlt, ecefX, ecefY, ecefZ); |
| 67 | + |
| 68 | + Serial.println("Setting 'Survey' Mode fixed to top of Eiffel Tower"); |
| 69 | + Serial.printf("(%.3f,%.3f,%.3f)\r\n", ecefX, ecefY, ecefZ); |
| 70 | + verify(myGNSS.setSurveyFixedMode(ecefX, ecefY, ecefZ)); |
| 71 | + if (!myGNSS.isConnected()) |
| 72 | + { |
| 73 | + Serial.println("reconnection failed; halting"); |
| 74 | + while (true); |
| 75 | + } |
| 76 | + Serial.println("Online!"); |
| 77 | + |
| 78 | + verify(myGNSS.getMode(mode)); |
| 79 | +} |
| 80 | + |
| 81 | +unsigned long lastUpdate = 0; |
| 82 | + |
| 83 | +void loop() |
| 84 | +{ |
| 85 | + myGNSS.update(); // Regularly call to parse any new data |
| 86 | + if (millis() - lastUpdate >= 1000) |
| 87 | + { |
| 88 | + lastUpdate = millis(); |
| 89 | + int svinStatus = myGNSS.getSurveyInStatus(); |
| 90 | + const char *status = svinStatus == 1 ? "In Progress" : svinStatus == 2 ? "Valid" : "Unknown/Invalid"; |
| 91 | + Serial.printf("%02d:%02d:%02d: Mode = '%s' Status = '%s' (%d/%d) (%.4f,%.4f,%.4f) Mean Accuracy = %.4f\r\n", |
| 92 | + myGNSS.getHour(), myGNSS.getMinute(), myGNSS.getSecond(), mode == 2 ? "BASE" : "ROVER", status, |
| 93 | + myGNSS.getSurveyInObservations(), myGNSS.getSurveyInCfgDuration(), |
| 94 | + myGNSS.getSurveyInMeanX(), myGNSS.getSurveyInMeanY(), myGNSS.getSurveyInMeanZ(), |
| 95 | + myGNSS.getSurveyInMeanAccuracy()); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +void verify(bool event) |
| 100 | +{ |
| 101 | + if (!event) |
| 102 | + { |
| 103 | + Serial.println("Operation failed: freezing!"); |
| 104 | + while (true); |
| 105 | + } |
| 106 | +} |
0 commit comments