Skip to content

Commit de5e739

Browse files
committed
Starting to add support for multiple message rates
1 parent 47f95a1 commit de5e739

File tree

3 files changed

+112
-6
lines changed

3 files changed

+112
-6
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Configuring the GNSS to produce multiple messages at different rates
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: April 1st, 2021
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to configure the U-Blox GNSS to output multiple messages at different rates:
10+
PVT is output once per measurement;
11+
POS_ECEF is output every second measurement;
12+
VEL_NED is output every third measurement.
13+
14+
Feel like supporting open source hardware?
15+
Buy a board from SparkFun!
16+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
17+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
18+
SAM-M8Q: https://www.sparkfun.com/products/15106
19+
20+
Hardware Connections:
21+
Plug a Qwiic cable into the GNSS and a BlackBoard
22+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
23+
Open the serial monitor at 115200 baud to see the output
24+
*/
25+
26+
#include <Wire.h> //Needed for I2C to GNSS
27+
28+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
29+
SFE_UBLOX_GNSS myGNSS;
30+
31+
void setup()
32+
{
33+
Serial.begin(115200);
34+
while (!Serial); //Wait for user to open terminal
35+
Serial.println("SparkFun u-blox Example");
36+
37+
Wire.begin();
38+
39+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
40+
{
41+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
42+
while (1);
43+
}
44+
45+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
46+
myGNSS.setMeasurementRate(1000); //Produce a measurement every 1000ms
47+
myGNSS.setNavigationRate(1); //Produce a navigation solution every measurement
48+
49+
myGNSS.setAutoPVTrate(1); //Tell the GNSS to "send" each PVT solution every measurement
50+
//myGNSS.setAutoPOSECEFrate(2); //Tell the GNSS to "send" each POS_ECEF solution every second measurement
51+
myGNSS.setAutoNAVVELNEDrate(3); //Tell the GNSS to "send" each VEL_NED solution every third measurement
52+
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
53+
}
54+
55+
void loop()
56+
{
57+
// Calling getPVT returns true if there actually is a fresh navigation solution available.
58+
if (myGNSS.getPVT())
59+
{
60+
long latitude = myGNSS.getLatitude();
61+
Serial.print(F("Lat: "));
62+
Serial.print(latitude);
63+
64+
long longitude = myGNSS.getLongitude();
65+
Serial.print(F(" Long: "));
66+
Serial.print(longitude);
67+
Serial.print(F(" (degrees * 10^-7)"));
68+
69+
long altitude = myGNSS.getAltitude();
70+
Serial.print(F(" Alt: "));
71+
Serial.print(altitude);
72+
Serial.println(F(" (mm)"));
73+
}
74+
75+
// Calling getVELNED returns true if there actually is fresh velocity data available.
76+
if (myGNSS.getNAVVELNED())
77+
{
78+
Serial.print(F("velN: "));
79+
Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velN / 100.0, 2); // convert velN to m/s
80+
81+
Serial.print(F(" velE: "));
82+
Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velE / 100.0, 2); // convert velE to m/s
83+
84+
Serial.print(F(" velD: "));
85+
Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velD / 100.0, 2); // convert velD to m/s
86+
Serial.println(F(" (m/s)"));
87+
88+
myGNSS.flushNAVVELNED(); //Mark all the data as read/stale so we get fresh data next time
89+
}
90+
}

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5755,12 +5755,19 @@ boolean SFE_UBLOX_GNSS::getPVT(uint16_t maxWait)
57555755
//works.
57565756
boolean SFE_UBLOX_GNSS::setAutoPVT(boolean enable, uint16_t maxWait)
57575757
{
5758-
return setAutoPVT(enable, true, maxWait);
5758+
return setAutoPVTrate(enable ? 1 : 0, true, maxWait);
57595759
}
57605760

57615761
//Enable or disable automatic navigation message generation by the GNSS. This changes the way getPVT
57625762
//works.
57635763
boolean SFE_UBLOX_GNSS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16_t maxWait)
5764+
{
5765+
return setAutoPVTrate(enable ? 1 : 0, implicitUpdate, maxWait);
5766+
}
5767+
5768+
//Enable or disable automatic navigation message generation by the GNSS. This changes the way getPVT
5769+
//works.
5770+
boolean SFE_UBLOX_GNSS::setAutoPVTrate(uint8_t rate, boolean implicitUpdate, uint16_t maxWait)
57645771
{
57655772
if (packetUBXNAVPVT == NULL) initPacketUBXNAVPVT(); //Check that RAM has been allocated for the PVT data
57665773
if (packetUBXNAVPVT == NULL) //Only attempt this if RAM allocation was successful
@@ -5772,12 +5779,12 @@ boolean SFE_UBLOX_GNSS::setAutoPVT(boolean enable, boolean implicitUpdate, uint1
57725779
packetCfg.startingSpot = 0;
57735780
payloadCfg[0] = UBX_CLASS_NAV;
57745781
payloadCfg[1] = UBX_NAV_PVT;
5775-
payloadCfg[2] = enable ? 1 : 0; // rate relative to navigation freq.
5782+
payloadCfg[2] = rate; // rate relative to navigation freq.
57765783

57775784
boolean ok = ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
57785785
if (ok)
57795786
{
5780-
packetUBXNAVPVT->automaticFlags.flags.bits.automatic = enable;
5787+
packetUBXNAVPVT->automaticFlags.flags.bits.automatic = (rate > 0);
57815788
packetUBXNAVPVT->automaticFlags.flags.bits.implicitUpdate = implicitUpdate;
57825789
}
57835790
packetUBXNAVPVT->moduleQueried.moduleQueried1.bits.all = false;
@@ -6199,12 +6206,19 @@ boolean SFE_UBLOX_GNSS::getNAVVELNED(uint16_t maxWait)
61996206
//works.
62006207
boolean SFE_UBLOX_GNSS::setAutoNAVVELNED(boolean enable, uint16_t maxWait)
62016208
{
6202-
return setAutoNAVVELNED(enable, true, maxWait);
6209+
return setAutoNAVVELNEDrate(enable ? 1 : 0, true, maxWait);
62036210
}
62046211

62056212
//Enable or disable automatic navigation message generation by the GNSS. This changes the way getVELNED
62066213
//works.
62076214
boolean SFE_UBLOX_GNSS::setAutoNAVVELNED(boolean enable, boolean implicitUpdate, uint16_t maxWait)
6215+
{
6216+
return setAutoNAVVELNEDrate(enable ? 1 : 0, implicitUpdate, maxWait);
6217+
}
6218+
6219+
//Enable or disable automatic navigation message generation by the GNSS. This changes the way getVELNED
6220+
//works.
6221+
boolean SFE_UBLOX_GNSS::setAutoNAVVELNEDrate(uint8_t rate, boolean implicitUpdate, uint16_t maxWait)
62086222
{
62096223
if (packetUBXNAVVELNED == NULL) initPacketUBXNAVVELNED(); //Check that RAM has been allocated for the data
62106224
if (packetUBXNAVVELNED == NULL) //Only attempt this if RAM allocation was successful
@@ -6216,12 +6230,12 @@ boolean SFE_UBLOX_GNSS::setAutoNAVVELNED(boolean enable, boolean implicitUpdate,
62166230
packetCfg.startingSpot = 0;
62176231
payloadCfg[0] = UBX_CLASS_NAV;
62186232
payloadCfg[1] = UBX_NAV_VELNED;
6219-
payloadCfg[2] = enable ? 1 : 0; // rate relative to navigation freq.
6233+
payloadCfg[2] = rate; // rate relative to navigation freq.
62206234

62216235
boolean ok = ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
62226236
if (ok)
62236237
{
6224-
packetUBXNAVVELNED->automaticFlags.flags.bits.automatic = enable;
6238+
packetUBXNAVVELNED->automaticFlags.flags.bits.automatic = (rate > 0);
62256239
packetUBXNAVVELNED->automaticFlags.flags.bits.implicitUpdate = implicitUpdate;
62266240
}
62276241
packetUBXNAVVELNED->moduleQueried.moduleQueried.bits.all = false;

src/SparkFun_u-blox_GNSS_Arduino_Library.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ class SFE_UBLOX_GNSS
733733
boolean getPVT(uint16_t maxWait = defaultMaxWait); //Query module for latest group of datums and load global vars: lat, long, alt, speed, SIV, accuracies, etc. If autoPVT is disabled, performs an explicit poll and waits, if enabled does not block. Returns true if new PVT is available.
734734
boolean setAutoPVT(boolean enabled, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic PVT reports at the navigation frequency
735735
boolean setAutoPVT(boolean enabled, boolean implicitUpdate, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic PVT reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
736+
boolean setAutoPVTrate(uint8_t rate, boolean implicitUpdate = true, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic PVT reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
736737
boolean setAutoPVTcallback(void (*callbackPointer)(UBX_NAV_PVT_data_t), uint16_t maxWait = defaultMaxWait); //Enable automatic PVT reports at the navigation frequency. Data is accessed from the callback.
737738
boolean assumeAutoPVT(boolean enabled, boolean implicitUpdate = true); //In case no config access to the GPS is possible and PVT is send cyclically already
738739
void flushPVT(); //Mark all the PVT data as read/stale
@@ -757,6 +758,7 @@ class SFE_UBLOX_GNSS
757758
boolean getNAVVELNED(uint16_t maxWait = defaultMaxWait); // NAV VELNED
758759
boolean setAutoNAVVELNED(boolean enabled, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic VELNED reports at the navigation frequency
759760
boolean setAutoNAVVELNED(boolean enabled, boolean implicitUpdate, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic VELNED reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
761+
boolean setAutoNAVVELNEDrate(uint8_t rate, boolean implicitUpdate = true, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic VELNED reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
760762
boolean setAutoNAVVELNEDcallback(void (*callbackPointer)(UBX_NAV_VELNED_data_t), uint16_t maxWait = defaultMaxWait); //Enable automatic VELNED reports at the navigation frequency. Data is accessed from the callback.
761763
boolean assumeAutoNAVVELNED(boolean enabled, boolean implicitUpdate = true); //In case no config access to the GPS is possible and VELNED is send cyclically already
762764
void flushNAVVELNED(); //Mark all the data as read/stale

0 commit comments

Comments
 (0)