Skip to content

Commit d0be891

Browse files
committed
Add support for setRtkDifferentialAge
1 parent 3e7e112 commit d0be891

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Configuring the max age of an RTK Fix before the device drops back to RTK Float
3+
By: Nathan Seidle + Mikal Hart
4+
SparkFun Electronics
5+
Date: 21 May 2025
6+
License: MIT. Please see LICENSE.md for more information.
7+
8+
This example shows how to configure the max differential age of RTK Fix used for the position engine.
9+
10+
If corrections are discontinue while the engine is in RTK Fix mode, it will continue with an RTK Fix for a certain amount
11+
of time. This is known as the differential age. By default, the LG290P will maintain an RTK Fix for 120 seconds.alignas
12+
Some applications require a lower (or higher) RTK Fix after corrections have been lost.
13+
14+
It is a known practice to raise the minimum elevation from the default of 5 degrees to 10 or even 15 degrees
15+
when in an urban environment to exclude satellites that are too low and may be blocked by structures causing
16+
multipath errors. Similarly, increasing the minimum CNR from 10 dBHz to 20 or 25 dBHz can exclude satellites
17+
with lower signal strength from being used in the position calculation.
18+
19+
The LG290P firmware must be v5 ("LG290P03AANR01A05S") or higher for these commands to work. We recommend using the QGNSS software
20+
to update the LG290P firmware.
21+
Latest Firmware: https://github.com/sparkfun/SparkFun_RTK_Postcard/tree/main/Firmware
22+
Docs: https://docs.sparkfun.com/SparkFun_LG290P_Quadband_GNSS_RTK_Breakout/software_overview/#qgnss-software
23+
24+
These examples are targeted for an ESP32 platform but any platform that has multiple
25+
serial UARTs should be compatible.
26+
27+
Feel like supporting open source hardware?
28+
Buy a board from SparkFun!
29+
SparkFun Quadband GNSS RTK Breakout - LG290P (GPS-26620) https://www.sparkfun.com/products/26620
30+
31+
Hardware Connections:
32+
Connect RX3 (green wire) of the LG290P to pin 14 on the ESP32
33+
Connect TX3 (orange wire) of the LG290P to pin 13 on the ESP32
34+
To make this easier, a 4-pin locking JST cable can be purchased here: https://www.sparkfun.com/products/17240
35+
Note: Almost any ESP32 pins can be used for serial.
36+
Connect a multi-band GNSS antenna: https://www.sparkfun.com/products/21801
37+
*/
38+
39+
#include <SparkFun_LG290P_GNSS.h> // Click here to get the library: http://librarymanager/All#SparkFun_LG290P
40+
41+
// Adjust these values according to your configuration
42+
int pin_UART1_TX = 14;
43+
int pin_UART1_RX = 13;
44+
int gnss_baud = 460800;
45+
46+
LG290P myGNSS;
47+
HardwareSerial SerialGNSS(1); // Use UART1 on the ESP32
48+
49+
void setup()
50+
{
51+
Serial.begin(115200);
52+
delay(250);
53+
Serial.println();
54+
Serial.println("SparkFun Max Differential Age example");
55+
Serial.println("Initializing device...");
56+
57+
// We must start the serial port before using it in the library
58+
// Increase buffer size to handle high baud rate streams
59+
SerialGNSS.setRxBufferSize(1024);
60+
SerialGNSS.begin(gnss_baud, SERIAL_8N1, pin_UART1_RX, pin_UART1_TX);
61+
62+
// myGNSS.enableDebugging(Serial); // Print all debug to Serial
63+
if (myGNSS.begin(SerialGNSS) == false) // Give the serial port over to the library
64+
{
65+
Serial.println("LG290P failed to respond. Check ports and baud rates. Freezing...");
66+
while (true);
67+
}
68+
Serial.println("LG290P detected!");
69+
70+
uint16_t differentialAge = 0;
71+
if (myGNSS.getRtkDifferentialAge(differentialAge) == false)
72+
{
73+
Serial.println("Failed to read differential age. Do you have version 5 or newer of the LG290P firmware installed?");
74+
}
75+
else
76+
{
77+
Serial.printf("Successfully checked differential age: %d seconds\r\n", differentialAge);
78+
79+
// 120 seconds is default meaning if the engine has RTK Fix, and no more corrections are provided, RTK Fix will be
80+
// maintained for 120 more seconds, befor falling back to RTK Float, then 3D fix.
81+
// 1 to 600 is allowed
82+
if (myGNSS.setRtkDifferentialAge(10) == false)
83+
Serial.println("Failed to set differential age");
84+
else
85+
{
86+
if (myGNSS.getRtkDifferentialAge(differentialAge) == false)
87+
Serial.println("Failed to read differential age.");
88+
else
89+
{
90+
Serial.printf("Differential age set to %d seconds.\r\n", differentialAge);
91+
}
92+
}
93+
}
94+
}
95+
96+
void loop()
97+
{
98+
99+
}

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ setElevationAngle KEYWORD2
150150
getElevationAngle KEYWORD2
151151
setCNR KEYWORD2
152152
getCNR KEYWORD2
153+
setRtkDifferentialAge KEYWORD2
154+
getRtkDifferentialAge KEYWORD2
153155

154156
#######################################
155157
# Constants (LITERAL1)

src/SparkFun_LG290P_GNSS.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,27 @@ bool LG290P::getCNR(float &cnr)
705705
return ret;
706706
}
707707

708+
// Configures the max differential age of RTK fix before the device will drop back to RTK float.
709+
// Note: We assume Auto mode and Absolute mode when setting the timeout.
710+
bool LG290P::setRtkDifferentialAge(uint16_t timeout)
711+
{
712+
char parms[50];
713+
snprintf(parms, sizeof parms, ",W,1,1,%d", timeout);
714+
return sendOkCommand("PQTMCFGRTK", parms) && hotStart();
715+
}
716+
717+
bool LG290P::getRtkDifferentialAge(uint16_t &timeout)
718+
{
719+
bool ret = sendCommand("PQTMCFGRTK", ",R");
720+
if (ret)
721+
{
722+
auto packet = getCommandResponse();
723+
ret = packet[1] == "OK";
724+
timeout = atoi(packet[4].c_str());
725+
}
726+
return ret;
727+
}
728+
708729
bool LG290P::scanForMsgsEnabled()
709730
{
710731
bool ok = getMessageRate("GGA", devState.ggaRate);

src/SparkFun_LG290P_GNSS.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,22 @@ class LG290P
438438
*/
439439
bool getCNR(float &cnr);
440440

441+
/**
442+
* @brief Sets the max differential age of RTK fix.
443+
* @details Uses the PQTMCFGRTK command. Use a value between 1 and 600. Default is 120 seconds.
444+
* @param timeout The new RTK differential timeout for the position engine.
445+
* @return true if successful, false otherwise.
446+
*/
447+
bool setRtkDifferentialAge(uint16_t timeout);
448+
449+
/**
450+
* @brief Gets the max differential age of RTK fix.
451+
* @details Uses the PQTMCFGRTK command.
452+
* @param timeout Reference to a uint16_t where the timeout value will be stored.
453+
* @return true if successful, false otherwise.
454+
*/
455+
bool getRtkDifferentialAge(uint16_t &timeout);
456+
441457
/**
442458
* @brief Sets a new elevation threshold for position engine.
443459
* @details Uses the PQTMCFGELETHD command. Use a value between -90 and 90

0 commit comments

Comments
 (0)