Skip to content

Commit 16043c6

Browse files
committed
Add enable / configure odometer methods and example - resolves #185
1 parent 6f5f8c8 commit 16043c6

File tree

5 files changed

+126
-8
lines changed

5 files changed

+126
-8
lines changed

Diff for: examples/Callbacks/CallbackExample2_NAV_ODO/CallbackExample2_NAV_ODO.ino

+27-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
Configuring the GNSS to automatically send odometer reports over I2C and display the data using a callback
33
By: Paul Clark
44
SparkFun Electronics
5-
Date: December 30th, 2020
6-
License: MIT. See license file for more information but you can
7-
basically do whatever you want with this code.
5+
Date: March 20th, 2023
6+
License: MIT. See license file for more information.
87
98
This example shows how to configure the u-blox GNSS to send odometer reports automatically
109
and display the data via a callback. No more polling!
@@ -55,6 +54,8 @@ void printODOdata(UBX_NAV_ODO_data_t *ubxDataStruct)
5554

5655
void setup()
5756
{
57+
delay(1000);
58+
5859
Serial.begin(115200);
5960
while (!Serial); //Wait for user to open terminal
6061
Serial.println("SparkFun u-blox Example");
@@ -63,17 +64,37 @@ void setup()
6364

6465
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
6566

66-
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
67+
while (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
6768
{
68-
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
69-
while (1);
69+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring."));
7070
}
7171

7272
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
7373
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
7474

7575
myGNSS.setNavigationFrequency(1); //Produce one solution per second
7676

77+
//By default, the odometer is disabled. We need to enable it.
78+
//We can enable it using the default settings:
79+
myGNSS.enableOdometer();
80+
81+
//Or we can configure it using our own settings, by performing a read-modify-write:
82+
uint8_t flags; // Odometer/Low-speed COG filter flags
83+
uint8_t odoCfg; // Odometer filter settings
84+
uint8_t cogMaxSpeed; // Speed below which course-over-ground (COG) is computed with the low-speed COG filter : m/s * 0.1
85+
uint8_t cogMaxPosAcc; // Maximum acceptable position accuracy for computing COG with the low-speed COG filter
86+
uint8_t velLpGain; // Velocity low-pass filter level
87+
uint8_t cogLpGain; // COG low-pass filter level
88+
89+
if (myGNSS.getOdometerConfig(&flags, &odoCfg, &cogMaxSpeed, &cogMaxPosAcc, &velLpGain, &cogLpGain))
90+
{
91+
flags = UBX_CFG_ODO_USE_ODO; // Enable the odometer
92+
odoCfg = UBX_CFG_ODO_CAR; // Use the car profile (others are RUN, CYCLE, SWIM, CUSTOM)
93+
myGNSS.setOdometerConfig(flags, odoCfg, cogMaxSpeed, cogMaxPosAcc, velLpGain, cogLpGain); // Set the configuration
94+
}
95+
else
96+
Serial.println("Could not read odometer config!");
97+
7798
//myGNSS.resetOdometer(); //Uncomment this line to reset the odometer
7899

79100
myGNSS.setAutoNAVODOcallbackPtr(&printODOdata); // Enable automatic NAV ODO messages with callback to printODOdata

Diff for: keywords.txt

+14
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ setDynamicModel KEYWORD2
193193
getDynamicModel KEYWORD2
194194

195195
resetOdometer KEYWORD2
196+
enableOdometer KEYWORD2
197+
getOdometerConfig KEYWORD2
198+
setOdometerConfig KEYWORD2
196199

197200
enableGNSS KEYWORD2
198201
isGNSSenabled KEYWORD2
@@ -831,6 +834,17 @@ VAL_CFG_SUBSEC_ANTCONF LITERAL1
831834
VAL_CFG_SUBSEC_LOGCONF LITERAL1
832835
VAL_CFG_SUBSEC_FTSCONF LITERAL1
833836

837+
UBX_CFG_ODO_USE_ODO LITERAL1
838+
UBX_CFG_ODO_USE_COG LITERAL1
839+
UBX_CFG_ODO_OUT_LP_VEL LITERAL1
840+
UBX_CFG_ODO_OUT_LP_COG LITERAL1
841+
842+
UBX_CFG_ODO_RUN LITERAL1
843+
UBX_CFG_ODO_CYCLE LITERAL1
844+
UBX_CFG_ODO_SWIM LITERAL1
845+
UBX_CFG_ODO_CAR LITERAL1
846+
UBX_CFG_ODO_CUSTOM LITERAL1
847+
834848
DYN_MODEL_PORTABLE LITERAL1
835849
DYN_MODEL_STATIONARY LITERAL1
836850
DYN_MODEL_PEDESTRIAN LITERAL1

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun u-blox GNSS Arduino Library
2-
version=2.2.21
2+
version=2.2.22
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules<br/><br/>

Diff for: src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -8207,6 +8207,70 @@ bool SFE_UBLOX_GNSS::resetOdometer(uint16_t maxWait)
82078207
return (sendCommand(&packetCfg, maxWait, true) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
82088208
}
82098209

8210+
// Enable / disable the odometer
8211+
bool SFE_UBLOX_GNSS::enableOdometer(bool enable, uint16_t maxWait)
8212+
{
8213+
packetCfg.cls = UBX_CLASS_CFG;
8214+
packetCfg.id = UBX_CFG_ODO;
8215+
packetCfg.len = 0;
8216+
packetCfg.startingSpot = 0;
8217+
8218+
// Ask module for the current odometer configuration. Loads into payloadCfg.
8219+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
8220+
return (false);
8221+
8222+
if (enable)
8223+
payloadCfg[4] = payloadCfg[4] | UBX_CFG_ODO_USE_ODO;
8224+
else
8225+
payloadCfg[4] = payloadCfg[4] & ~UBX_CFG_ODO_USE_ODO;
8226+
8227+
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
8228+
}
8229+
8230+
// Read the odometer configuration
8231+
bool SFE_UBLOX_GNSS::getOdometerConfig(uint8_t *flags, uint8_t *odoCfg, uint8_t *cogMaxSpeed, uint8_t *cogMaxPosAcc, uint8_t *velLpGain, uint8_t *cogLpGain, uint16_t maxWait)
8232+
{
8233+
packetCfg.cls = UBX_CLASS_CFG;
8234+
packetCfg.id = UBX_CFG_ODO;
8235+
packetCfg.len = 0;
8236+
packetCfg.startingSpot = 0;
8237+
8238+
// Ask module for the current odometer configuration. Loads into payloadCfg.
8239+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
8240+
return (false);
8241+
8242+
*flags = payloadCfg[4];
8243+
*odoCfg = payloadCfg[5];
8244+
*cogMaxSpeed = payloadCfg[12];
8245+
*cogMaxPosAcc = payloadCfg[13];
8246+
*velLpGain = payloadCfg[16];
8247+
*cogLpGain = payloadCfg[17];
8248+
8249+
return true;
8250+
}
8251+
8252+
// Configure the odometer
8253+
bool SFE_UBLOX_GNSS::setOdometerConfig(uint8_t flags, uint8_t odoCfg, uint8_t cogMaxSpeed, uint8_t cogMaxPosAcc, uint8_t velLpGain, uint8_t cogLpGain, uint16_t maxWait)
8254+
{
8255+
packetCfg.cls = UBX_CLASS_CFG;
8256+
packetCfg.id = UBX_CFG_ODO;
8257+
packetCfg.len = 0;
8258+
packetCfg.startingSpot = 0;
8259+
8260+
// Ask module for the current odometer configuration. Loads into payloadCfg.
8261+
if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK
8262+
return (false);
8263+
8264+
payloadCfg[4] = flags;
8265+
payloadCfg[5] = odoCfg;
8266+
payloadCfg[12] = cogMaxSpeed;
8267+
payloadCfg[13] = cogMaxPosAcc;
8268+
payloadCfg[16] = velLpGain;
8269+
payloadCfg[17] = cogLpGain;
8270+
8271+
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
8272+
}
8273+
82108274
// Enable/Disable individual GNSS systems using UBX-CFG-GNSS
82118275
bool SFE_UBLOX_GNSS::enableGNSS(bool enable, sfe_ublox_gnss_ids_e id, uint16_t maxWait)
82128276
{

Diff for: src/SparkFun_u-blox_GNSS_Arduino_Library.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,22 @@ const uint8_t COM_TYPE_NMEA = (1 << 1);
465465
const uint8_t COM_TYPE_RTCM3 = (1 << 5);
466466
const uint8_t COM_TYPE_SPARTN = (1 << 6);
467467

468+
// Odometer configuration - flags
469+
const uint8_t UBX_CFG_ODO_USE_ODO = (1 << 0);
470+
const uint8_t UBX_CFG_ODO_USE_COG = (1 << 1);
471+
const uint8_t UBX_CFG_ODO_OUT_LP_VEL = (1 << 2);
472+
const uint8_t UBX_CFG_ODO_OUT_LP_COG = (1 << 3);
473+
474+
// Odometer configuration - odoCfg
475+
enum odoCfg_e
476+
{
477+
UBX_CFG_ODO_RUN = 0,
478+
UBX_CFG_ODO_CYCLE,
479+
UBX_CFG_ODO_SWIM,
480+
UBX_CFG_ODO_CAR,
481+
UBX_CFG_ODO_CUSTOM,
482+
};
483+
468484
// Configuration Sub-Section mask definitions for saveConfigSelective (UBX-CFG-CFG)
469485
const uint32_t VAL_CFG_SUBSEC_IOPORT = 0x00000001; // ioPort - communications port settings (causes IO system reset!)
470486
const uint32_t VAL_CFG_SUBSEC_MSGCONF = 0x00000002; // msgConf - message configuration
@@ -909,8 +925,11 @@ class SFE_UBLOX_GNSS
909925
bool setDynamicModel(dynModel newDynamicModel = DYN_MODEL_PORTABLE, uint16_t maxWait = defaultMaxWait);
910926
uint8_t getDynamicModel(uint16_t maxWait = defaultMaxWait); // Get the dynamic model - returns 255 if the sendCommand fails
911927

912-
// Reset the odometer
928+
// Reset / enable / configure the odometer
913929
bool resetOdometer(uint16_t maxWait = defaultMaxWait); // Reset the odometer
930+
bool enableOdometer(bool enable = true, uint16_t maxWait = defaultMaxWait); // Enable / disable the odometer
931+
bool getOdometerConfig(uint8_t *flags, uint8_t *odoCfg, uint8_t *cogMaxSpeed, uint8_t *cogMaxPosAcc, uint8_t *velLpGain, uint8_t *cogLpGain, uint16_t maxWait = defaultMaxWait); // Read the odometer configuration
932+
bool setOdometerConfig(uint8_t flags, uint8_t odoCfg, uint8_t cogMaxSpeed, uint8_t cogMaxPosAcc, uint8_t velLpGain, uint8_t cogLpGain, uint16_t maxWait = defaultMaxWait); // Configure the odometer
914933

915934
// Enable/Disable individual GNSS systems using UBX-CFG-GNSS
916935
// Note: you must leave at least one major GNSS enabled! If in doubt, enable GPS before disabling the others

0 commit comments

Comments
 (0)