Initial commit - based on v2_candidate

This commit is contained in:
PaulZC
2021-01-09 06:44:12 +00:00
commit 6627841e7d
89 changed files with 31927 additions and 0 deletions
@@ -0,0 +1,141 @@
/*
Configuring the GNSS to automatically send position reports over I2C
By: Nathan Seidle and Thorsten von Eicken
SparkFun Electronics
Date: January 3rd, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.
This example shows how to configure the U-Blox GNSS the send navigation reports automatically
and retrieving the latest one via getPVT. This eliminates the blocking in getPVT while the GNSS
produces a fresh navigation solution at the expense of returning a slighly old solution.
This can be used over serial or over I2C, this example shows the I2C use. With serial the GNSS
simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in
size?) where it can be retrieved in the next I2C poll.
Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106
Hardware Connections:
Plug a Qwiic cable into the GNSS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/
#include <Wire.h> //Needed for I2C to GNSS
#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GPS myGPS;
void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");
Wire.begin();
if (myGPS.begin() == false) //Connect to the u-blox module using Wire port
{
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
while (1);
}
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGPS.setNavigationFrequency(2); //Produce two solutions per second
myGPS.setAutoPVT(true); //Tell the GNSS to "send" each solution
//myGPS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
}
void loop()
{
// Calling getPVT returns true if there actually is a fresh navigation solution available.
// Start the reading only when valid LLH is available
if (myGPS.getPVT() && (myGPS.getInvalidLlh() == false))
{
Serial.println();
long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);
int PDOP = myGPS.getPDOP();
Serial.print(F(" PDOP: "));
Serial.print(PDOP);
Serial.print(F(" (10^-2)"));
int nedNorthVel = myGPS.getNedNorthVel();
Serial.print(F(" VelN: "));
Serial.print(nedNorthVel);
Serial.print(F(" (mm/s)"));
int nedEastVel = myGPS.getNedEastVel();
Serial.print(F(" VelE: "));
Serial.print(nedEastVel);
Serial.print(F(" (mm/s)"));
int nedDownVel = myGPS.getNedDownVel();
Serial.print(F(" VelD: "));
Serial.print(nedDownVel);
Serial.print(F(" (mm/s)"));
int verticalAccEst = myGPS.getVerticalAccEst();
Serial.print(F(" VAccEst: "));
Serial.print(verticalAccEst);
Serial.print(F(" (mm)"));
int horizontalAccEst = myGPS.getHorizontalAccEst();
Serial.print(F(" HAccEst: "));
Serial.print(horizontalAccEst);
Serial.print(F(" (mm)"));
int speedAccEst = myGPS.getSpeedAccEst();
Serial.print(F(" SpeedAccEst: "));
Serial.print(speedAccEst);
Serial.print(F(" (mm/s)"));
int headAccEst = myGPS.getHeadingAccEst();
Serial.print(F(" HeadAccEst: "));
Serial.print(headAccEst);
Serial.print(F(" (degrees * 10^-5)"));
if (myGPS.getHeadVehValid() == true) {
int headVeh = myGPS.getHeadVeh();
Serial.print(F(" HeadVeh: "));
Serial.print(headVeh);
Serial.print(F(" (degrees * 10^-5)"));
int magDec = myGPS.getMagDec();
Serial.print(F(" MagDec: "));
Serial.print(magDec);
Serial.print(F(" (degrees * 10^-2)"));
int magAcc = myGPS.getMagAcc();
Serial.print(F(" MagAcc: "));
Serial.print(magAcc);
Serial.print(F(" (degrees * 10^-2)"));
}
Serial.println();
} else {
Serial.print(".");
delay(50);
}
}
@@ -0,0 +1,103 @@
/*
Configuring the GNSS to automatically send position reports over I2C, with explicit data parsing calls
By: Nathan Seidle Thorsten von Eicken and Felix Jirka
SparkFun Electronics
Date: July 1st, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.
This example shows how to configure the U-Blox GNSS the send navigation reports automatically
and retrieving the latest one via checkUblox when available.
This eliminates the implicit update in getPVT when accessing data fields twice.
Also this reduces the memory overhead of a separate buffer while introducing a slight error by inconsistencies because of the unsynchronized updates (on a multi core system).
This can be used over serial or over I2C, this example shows the I2C use. With serial the GNSS
simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in
size?) where it can be retrieved in the next I2C poll.
Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106
Hardware Connections:
Plug a Qwiic cable into the GNSS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/
#include <Wire.h> //Needed for I2C to GNSS
#include <SparkFun_Ublox_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GPS myGPS;
void setup()
{
Serial.begin(115200);
while (!Serial)
; //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");
Wire.begin();
if (myGPS.begin() == false) //Connect to the u-blox module using Wire port
{
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
while (1)
;
}
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGPS.setNavigationFrequency(2); //Produce two solutions per second
myGPS.setAutoPVT(true, false); //Tell the GNSS to "send" each solution and the lib not to update stale data implicitly
//myGPS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
}
/*
Calling getPVT would return false now (compare to previous example where it would return true), so we just use the data provided
If you are using a threaded OS eg. FreeRTOS on an ESP32, the explicit mode of autoPVT allows you to use the data provided on both cores and inside multiple threads
The data update in background creates an inconsistent state, but that should not cause issues for most applications as they usually won't change the GNSS location significantly within a 2Hz - 5Hz update rate.
Also you could oversample (10Hz - 20Hz) the data to smooth out such issues...
*/
void loop()
{
static uint16_t counter = 0;
if (counter % 10 == 0)
{
// update your AHRS filter here for a ~100Hz update rate
// GNSS data will be quasi static but data from your IMU will be changing
}
// debug output each half second
if (counter % 500 == 0)
{
Serial.println();
long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);
Serial.println();
}
// call checkUblox all 50ms to capture the GNSS data
if (counter % 50 == 0)
{
myGPS.checkUblox();
}
delay(1);
counter++;
}
@@ -0,0 +1,107 @@
/*
Configuring the GNSS to automatically send position reports over Serial
By: Nathan Seidle, Adapted from Example11 by Felix Jirka
SparkFun Electronics
Date: July 2nd, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.
This example shows how to configure the U-Blox GNSS the send navigation reports automatically
and retrieving the latest one via getPVT. This eliminates the blocking in getPVT while the GNSS
produces a fresh navigation solution at the expense of returning a slighly old solution.
This can be used over serial or over I2C, this example shows the Serial use. With serial the GNSS
simply outputs the UBX_NAV_PVT packet. With I2C it queues it into its internal I2C buffer (4KB in
size?) where it can be retrieved in the next I2C poll.
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106
Hardware Connections:
Plug a Qwiic cable into the GNSS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GPS myGPS;
#include <SoftwareSerial.h>
//#define mySerial Serial2 // Uncomment this line to connect via Serial2
// - or -
SoftwareSerial mySerial(10, 11); // Uncomment this line to connect via SoftwareSerial(RX, TX). Connect pin 10 to GNSS TX pin.
//#define baudRate 9600 // Uncomment this line to select 9600 Baud for the M8
// - or -
#define baudRate 38400 // Uncomment this line to select 38400 Baud for the F9
void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");
mySerial.begin(baudRate); // Start the Serial port
if (myGPS.begin(mySerial) == false) //Connect to the u-blox module using Serial
{
Serial.println(F("u-blox GNSS not detected. Please check wiring. Freezing."));
while (1);
}
myGPS.setUART1Output(COM_TYPE_UBX); //Set the UART1 port to output UBX only (turn off NMEA noise)
myGPS.setNavigationFrequency(2); //Produce two solutions per second
myGPS.setAutoPVT(true); //Tell the GNSS to "send" each solution
//myGPS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
}
void loop()
{
// getPVT will return true if there actually is a fresh navigation solution available.
// Important note: the PVT message is 100 bytes long. We need to call getPVT often enough
// to prevent serial buffer overflows on boards like the original RedBoard / UNO.
// At 38400 Baud, the 100 PVT bytes will arrive in 26ms.
// On the RedBoard, we need to call getPVT every 5ms to keep up.
if (myGPS.getPVT())
{
Serial.println();
long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);
Serial.println();
}
else
{
delay(5); // Delay for 5ms only
static int counter = 0; // Print a dot every 50ms
counter++;
if (counter > 10)
{
Serial.print(".");
counter = 0;
}
}
}
@@ -0,0 +1,110 @@
/*
Reading lat and long via UBX binary commands using an RX-only UART
By: Nathan Seidle, Adapted from Example11 by Felix Jirka
SparkFun Electronics
Date: July 2nd, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.
This example shows how to configure the library for serial port use with a single wire connection using the assumeAutoPVT method.
Saving your pins for other stuff :-)
This example only works correctly if the module has already been configured is sending PVT messages via its UART1 TX pin.
Run the previous example to enable the auto PVT messages if you need to.
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106
Preconditions:
U-Blox module is configured to send cyclical PVT message
Hardware Connections:
Connect the U-Blox serial TX pin to Rx of Serial2 (default: GPIO16) on your ESP32
Or, switch to SoftwareSerial
Open the serial monitor at 115200 baud to see the output
*/
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GPS myGPS;
#include <SoftwareSerial.h>
//#define mySerial Serial2 // Uncomment this line to connect via Serial2
// - or -
SoftwareSerial mySerial(10, 11); // Uncomment this line to connect via SoftwareSerial(RX, TX). Connect pin 10 to GNSS TX pin.
//#define baudRate 9600 // Uncomment this line to select 9600 Baud for the M8
// - or -
#define baudRate 38400 // Uncomment this line to select 38400 Baud for the F9
void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");
//Use any Serial port with at least a RX Pin connected or a receive only version of SoftwareSerial here
//Assume that the U-Blox GNSS is running at baudRate baud
mySerial.begin(baudRate);
// No need to check return value as internal call to isConnected() will not succeed
myGPS.begin(mySerial);
// Tell the library we are expecting the module to send PVT messages by itself to our Rx pin.
// You can set second parameter to "false" if you want to control the parsing and eviction of the data (need to call checkUblox cyclically)
myGPS.assumeAutoPVT(true, true);
}
void loop()
{
// If implicit updates are enabled, calling getPVT will trigger parsing of the incoming messages
// and return true once a PVT message has been parsed.
// In case you want to use explicit updates, wrap this in a timer and call checkUblox()
// as often as needed, not to overflow your UART buffers.
//
// Important note: the PVT message is 100 bytes long. We need to call getPVT often enough
// to prevent serial buffer overflows on boards like the original RedBoard / UNO.
// At 38400 Baud, the 100 PVT bytes will arrive in 26ms.
// On the RedBoard, we need to call getPVT every 5ms to keep up.
if (myGPS.getPVT())
{
Serial.println();
long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);
Serial.println();
}
else
{
delay(5); // Delay for 5ms only
static int counter = 0; // Print a dot every 50ms
counter++;
if (counter > 10)
{
Serial.print(".");
counter = 0;
}
}
}