Skip to content

Commit ef5abac

Browse files
committed
Add auto support for NAV SAT. Add NAV SAT callback example. Add final AssistNow Autonomous examples.
1 parent 235df31 commit ef5abac

File tree

11 files changed

+1112
-46
lines changed

11 files changed

+1112
-46
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
Monitor AssistNow Autonomous data collection
3+
By: SparkFun Electronics / Paul Clark
4+
Date: November 29th, 2021
5+
License: MIT. See license file for more information but you can
6+
basically do whatever you want with this code.
7+
8+
This example shows how to enable and monitor AssistNow Autonomous data collection by the module.
9+
A callback is used to monitor AssistNow Autonomous data availability for each satellite.
10+
A second callback is used to print the AOPSTATUS status.
11+
12+
If your GNSS board has battery-backup for the RAM - and all SparkFun boards do! - then you can:
13+
wait until the module has AssistNow Autonomous data for a few satellites;
14+
power-cycle the board;
15+
watch how fast it gets its first fix!
16+
17+
Note: this example will only work on boards which have plenty of RAM available.
18+
The UBX-NAV-SAT information occupies several kBytes.
19+
20+
Feel like supporting open source hardware?
21+
Buy a board from SparkFun!
22+
SparkFun Thing Plus - ESP32 WROOM: https://www.sparkfun.com/products/15663
23+
ZED-F9P RTK2: https://www.sparkfun.com/products/16481
24+
SparkFun GPS Breakout - ZOE-M8Q (Qwiic): https://www.sparkfun.com/products/15193
25+
26+
Hardware Connections:
27+
Plug a Qwiic cable into the GNSS and a ESP32 Thing Plus
28+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
29+
Open the serial monitor at 115200 baud to see the output
30+
*/
31+
32+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
33+
SFE_UBLOX_GNSS myGNSS;
34+
35+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
36+
37+
// Callback: printSATdata will be called when new NAV SAT data arrives
38+
// See u-blox_structs.h for the full definition of UBX_NAV_SAT_data_t
39+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVSATcallback
40+
// / _____ This _must_ be UBX_NAV_SAT_data_t
41+
// | / _____ You can use any name you like for the struct
42+
// | | /
43+
// | | |
44+
void printSATdata(UBX_NAV_SAT_data_t ubxDataStruct)
45+
{
46+
//Serial.println();
47+
48+
Serial.print(F("UBX-NAV-SAT contains data for "));
49+
Serial.print(ubxDataStruct.header.numSvs);
50+
if (ubxDataStruct.header.numSvs == 1)
51+
Serial.println(F(" SV"));
52+
else
53+
Serial.println(F(" SVs"));
54+
55+
uint16_t numAopAvail = 0; // Count how many SVs have AssistNow Autonomous data available
56+
57+
for (uint16_t block = 0; block < ubxDataStruct.header.numSvs; block++) // For each SV
58+
{
59+
if (ubxDataStruct.blocks[block].flags.bits.aopAvail == 1) // If the aopAvail bit is set
60+
numAopAvail++; // Increment the number of SVs
61+
}
62+
63+
Serial.print(F("AssistNow Autonomous data is available for "));
64+
Serial.print(numAopAvail);
65+
if (numAopAvail == 1)
66+
Serial.println(F(" SV"));
67+
else
68+
Serial.println(F(" SVs"));
69+
}
70+
71+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
72+
73+
// Callback: printAOPstatus will be called when new NAV AOPSTATUS data arrives
74+
// See u-blox_structs.h for the full definition of UBX_NAV_AOPSTATUS_data_t
75+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVAOPSTATUScallback
76+
// / _____ This _must_ be UBX_NAV_AOPSTATUS_data_t
77+
// | / _____ You can use any name you like for the struct
78+
// | | /
79+
// | | |
80+
void printAOPstatus(UBX_NAV_AOPSTATUS_data_t ubxDataStruct)
81+
{
82+
//Serial.println();
83+
84+
Serial.print(F("AOPSTATUS status is "));
85+
Serial.println(ubxDataStruct.status);
86+
}
87+
88+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
89+
90+
// Callback: printPVTdata will be called when new NAV PVT data arrives
91+
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t
92+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoPVTcallback
93+
// / _____ This _must_ be UBX_NAV_PVT_data_t
94+
// | / _____ You can use any name you like for the struct
95+
// | | /
96+
// | | |
97+
void printPVTdata(UBX_NAV_PVT_data_t ubxDataStruct)
98+
{
99+
// Print the UBX-NAV-PVT data so we can see how quickly the fixType goes to 3D
100+
101+
Serial.println();
102+
103+
long latitude = ubxDataStruct.lat; // Print the latitude
104+
Serial.print(F("Lat: "));
105+
Serial.print(latitude);
106+
107+
long longitude = ubxDataStruct.lon; // Print the longitude
108+
Serial.print(F(" Long: "));
109+
Serial.print(longitude);
110+
Serial.print(F(" (degrees * 10^-7)"));
111+
112+
long altitude = ubxDataStruct.hMSL; // Print the height above mean sea level
113+
Serial.print(F(" Alt: "));
114+
Serial.print(altitude);
115+
Serial.print(F(" (mm)"));
116+
117+
byte fixType = ubxDataStruct.fixType; // Print the fix type
118+
Serial.print(F(" Fix: "));
119+
if(fixType == 0) Serial.print(F("No fix"));
120+
else if(fixType == 1) Serial.print(F("Dead reckoning"));
121+
else if(fixType == 2) Serial.print(F("2D"));
122+
else if(fixType == 3) Serial.print(F("3D"));
123+
else if(fixType == 4) Serial.print(F("GNSS + Dead reckoning"));
124+
else if(fixType == 5) Serial.print(F("Time only"));
125+
126+
Serial.println();
127+
}
128+
129+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
130+
131+
void setup()
132+
{
133+
delay(1000);
134+
135+
Serial.begin(115200);
136+
Serial.println(F("AssistNow Example"));
137+
138+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
139+
// Start I2C. Connect to the GNSS.
140+
141+
Wire.begin(); //Start I2C
142+
143+
//myGNSS.enableDebugging(Serial, true); // Uncomment this line to see the 'major' debug messages on Serial
144+
145+
if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port
146+
{
147+
Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing."));
148+
while (1);
149+
}
150+
Serial.println(F("u-blox module connected"));
151+
152+
myGNSS.setI2COutput(COM_TYPE_UBX); //Turn off NMEA noise
153+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
154+
155+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
156+
// Enable AssistNow Autonomous data collection.
157+
158+
if (myGNSS.setAopCfg(1) == true)
159+
{
160+
Serial.println(F("aopCfg enabled"));
161+
}
162+
else
163+
{
164+
Serial.println(F("Could not enable aopCfg. Please check wiring. Freezing."));
165+
while (1);
166+
}
167+
168+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
169+
// Enable automatic UBX-NAV-SAT and UBX-NAV-AOPSTATUS messages and set up the callbacks
170+
171+
myGNSS.setNavigationFrequency(1); //Produce one solution per second
172+
173+
myGNSS.setAutoNAVSATcallback(&printSATdata); // Enable automatic NAV SAT messages with callback to printSATdata
174+
myGNSS.setAutoAOPSTATUScallback(&printAOPstatus); // Enable automatic NAV AOPSTATUS messages with callback to printAOPstatus
175+
myGNSS.setAutoPVTcallback(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
176+
}
177+
178+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
179+
180+
void loop()
181+
{
182+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
183+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
184+
185+
Serial.print(".");
186+
delay(50);
187+
}

Diff for: examples/AssistNow/AssistNow_Autonomous/Example1_AssistNowAutonomous_Read/Example1_AssistNowAutonomous_Read.ino renamed to examples/AssistNow/AssistNow_Autonomous/Example2_AssistNowAutonomous_DatabaseRead/Example2_AssistNowAutonomous_DatabaseRead.ino

+83-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Read the AssistNow Autonomous data from the module
2+
Read the AssistNow Autonomous database from the module
33
By: SparkFun Electronics / Paul Clark
44
Date: November 29th, 2021
55
License: MIT. See license file for more information but you can
@@ -8,8 +8,7 @@
88
This example shows how to enable, check the status of, and read the AssistNow Autonomous data from the module.
99
1010
Note: this example will only work on boards which have plenty of RAM available.
11-
The database can be several kBytes in length and needs to be stored twice:
12-
once inside the library (by readNavigationDatabase); and again in this example code.
11+
The database can be several kBytes in length.
1312
1413
Feel like supporting open source hardware?
1514
Buy a board from SparkFun!
@@ -28,6 +27,59 @@ SFE_UBLOX_GNSS myGNSS;
2827

2928
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3029

30+
// Callback: printSATdata will be called when new NAV SAT data arrives
31+
// See u-blox_structs.h for the full definition of UBX_NAV_SAT_data_t
32+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVSATcallback
33+
// / _____ This _must_ be UBX_NAV_SAT_data_t
34+
// | / _____ You can use any name you like for the struct
35+
// | | /
36+
// | | |
37+
void printSATdata(UBX_NAV_SAT_data_t ubxDataStruct)
38+
{
39+
Serial.println();
40+
41+
Serial.print(F("UBX-NAV-SAT contains data for "));
42+
Serial.print(ubxDataStruct.header.numSvs);
43+
if (ubxDataStruct.header.numSvs == 1)
44+
Serial.println(F(" SV"));
45+
else
46+
Serial.println(F(" SVs"));
47+
48+
uint16_t numAopAvail = 0; // Count how many SVs have AssistNow Autonomous data available
49+
50+
for (uint16_t block = 0; block < ubxDataStruct.header.numSvs; block++) // For each SV
51+
{
52+
if (ubxDataStruct.blocks[block].flags.bits.aopAvail == 1) // If the aopAvail bit is set
53+
numAopAvail++; // Increment the number of SVs
54+
}
55+
56+
Serial.print(F("AssistNow Autonomous data is available for "));
57+
Serial.print(numAopAvail);
58+
if (numAopAvail == 1)
59+
Serial.println(F(" SV"));
60+
else
61+
Serial.println(F(" SVs"));
62+
}
63+
64+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
65+
66+
// Callback: printAOPstatus will be called when new NAV AOPSTATUS data arrives
67+
// See u-blox_structs.h for the full definition of UBX_NAV_AOPSTATUS_data_t
68+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVAOPSTATUScallback
69+
// / _____ This _must_ be UBX_NAV_AOPSTATUS_data_t
70+
// | / _____ You can use any name you like for the struct
71+
// | | /
72+
// | | |
73+
void printAOPstatus(UBX_NAV_AOPSTATUS_data_t ubxDataStruct)
74+
{
75+
//Serial.println();
76+
77+
Serial.print(F("AOPSTATUS status is "));
78+
Serial.println(ubxDataStruct.status);
79+
}
80+
81+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
82+
3183
void setup()
3284
{
3385
delay(1000);
@@ -69,39 +121,40 @@ void setup()
69121
}
70122

71123
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
72-
// Keep calling getAOPSTATUSstatus until it returns zero (indicating AssistNow Autonomous data collection is complete)
73-
// or the user presses a key
124+
// Enable automatic UBX-NAV-SAT and UBX-NAV-AOPSTATUS messages and set up the callbacks
125+
126+
myGNSS.setNavigationFrequency(1); //Produce one solution per second
127+
128+
myGNSS.setAutoNAVSATcallback(&printSATdata); // Enable automatic NAV SAT messages with callback to printSATdata
129+
myGNSS.setAutoAOPSTATUScallback(&printAOPstatus); // Enable automatic NAV AOPSTATUS messages with callback to printAOPstatus
130+
131+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
132+
// Keep displaying NAV SAT and AOPSTATUS until the user presses a key
74133

75-
Serial.println(F("AssistNow Autonomous data collection is in progress. Press any key to quit."));
76-
Serial.println(F("NAV AOPSTATUS status indicates when the AssistNow Autonomous subsystem is idle (0) or running (not 0)."));
134+
Serial.println(F("AssistNow Autonomous data collection is in progress. Press any key to quit and read the database."));
77135

78-
bool keepGoing = true;
79-
int zerosSeen = 0; // Keep track of how many times aopStatus has been zero
80136
while (Serial.available()) Serial.read(); // Empty the serial buffer
81137

82-
while (keepGoing && !Serial.available()) // Wait for keepGoing to go false, or for the arrival of a keypress
138+
while (!Serial.available()) // Wait for the arrival of a keypress
83139
{
84-
delay(1000);
85-
uint8_t aopStatus = myGNSS.getAOPSTATUSstatus();
86-
Serial.print(F("NAV AOPSTATUS status is: "));
87-
Serial.println(aopStatus);
88-
if (aopStatus == 0) // aopStatus will be zero when the AssistNow Autonomous subsystem is idle - i.e. data collection is complete
89-
{
90-
zerosSeen++; // Keep track of how long aopStatus has been zero
91-
if (zerosSeen >= 30)
92-
keepGoing = false; // Stop after seeing 30 consecutive zeros
93-
}
94-
else
95-
{
96-
zerosSeen = 0; // Reset the number of zeros seen
97-
}
140+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
141+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
142+
143+
Serial.print(".");
144+
delay(50);
98145
}
99146

100-
if (!keepGoing)
101-
Serial.println(F("AssistNow Autonomous data collection is complete!"));
147+
Serial.println();
148+
149+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
150+
// Disable the automatic UBX-NAV-SAT and UBX-NAV-AOPSTATUS messages
151+
152+
myGNSS.setAutoNAVSAT(false);
153+
myGNSS.setAutoAOPSTATUS(false);
154+
delay(1100);
102155

103156
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
104-
// Read the AssistNow Autonomous data from the module and pretty-print it (so it can be copied and pasted into Example2)
157+
// Read the AssistNow Autonomous database from the module and pretty-print it (so it can be copied and pasted into the next example)
105158

106159
#define MAX_DATABASE_LENGTH 32768 // Allocate 32kBytes to store the navigation database
107160
size_t maxDatabaseLen = MAX_DATABASE_LENGTH;
@@ -117,8 +170,8 @@ void setup()
117170
if (actualDatabaseLen == maxDatabaseLen)
118171
Serial.println(F("There was not enough memory to store the entire database. Some data will have been lost!"));
119172

120-
// Pretty-print the database so it can be copied into Example2
121-
Serial.println(F("Copy and paste the following into Example2, so you can write it back to the module:"));
173+
// Pretty-print the database so it can be copied into the next example
174+
Serial.println(F("Copy and paste the following into the next example, so you can write it back to the module:"));
122175
Serial.println();
123176
Serial.print(F("size_t databaseLen = "));
124177
Serial.print(actualDatabaseLen);
@@ -150,4 +203,4 @@ void setup()
150203
void loop()
151204
{
152205
// Nothing to do here
153-
}
206+
}

0 commit comments

Comments
 (0)